mirror of
https://github.com/vale981/outlook-oauth-hack
synced 2025-03-04 16:41:38 -05:00
implement lifetime
This commit is contained in:
parent
057d343656
commit
c533eb92d7
4 changed files with 14 additions and 4 deletions
|
@ -20,4 +20,5 @@ def get_config(profile):
|
||||||
Scopes = config_data["Scopes"],
|
Scopes = config_data["Scopes"],
|
||||||
RefreshTokenFileName = cache_path / "imap_smtp_refresh_token",
|
RefreshTokenFileName = cache_path / "imap_smtp_refresh_token",
|
||||||
AccessTokenFileName = cache_path / "imap_smtp_access_token",
|
AccessTokenFileName = cache_path / "imap_smtp_access_token",
|
||||||
Authority = config_data["Authority"] or None)
|
Authority = config_data["Authority"] or None,
|
||||||
|
Timeout = config_data.get("Timeout", 60 * 60))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
ClientId = "08162f7c-0fd2-4200-a84a-f25a4db0b584"
|
ClientId = "08162f7c-0fd2-4200-a84a-f25a4db0b584"
|
||||||
ClientSecret = "TxRBilcHdC6WGBee]fs?QR:SJ8nI[g82"
|
ClientSecret = "TxRBilcHdC6WGBee]fs?QR:SJ8nI[g82"
|
||||||
Scopes = ['https://outlook.office.com/IMAP.AccessAsUser.All','https://outlook.office.com/SMTP.Send']
|
Scopes = ['https://outlook.office.com/IMAP.AccessAsUser.All','https://outlook.office.com/SMTP.Send']
|
||||||
|
|
||||||
Authority = false
|
Authority = false
|
||||||
|
Timeout = 3600
|
||||||
|
|
||||||
[mcgill]
|
[mcgill]
|
||||||
|
|
|
@ -25,6 +25,7 @@ in
|
||||||
ClientSecret = "TxRBilcHdC6WGBee]fs?QR:SJ8nI[g82"
|
ClientSecret = "TxRBilcHdC6WGBee]fs?QR:SJ8nI[g82"
|
||||||
Scopes = ['https://outlook.office.com/IMAP.AccessAsUser.All','https://outlook.office.com/SMTP.Send']
|
Scopes = ['https://outlook.office.com/IMAP.AccessAsUser.All','https://outlook.office.com/SMTP.Send']
|
||||||
Authority = false
|
Authority = false
|
||||||
|
Timeout = 3600
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
from msal import ConfidentialClientApplication, SerializableTokenCache
|
from msal import ConfidentialClientApplication, SerializableTokenCache
|
||||||
import config
|
import config
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
print_access_token = True
|
print_access_token = True
|
||||||
# get first command line argument
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
profile = sys.argv[1]
|
profile = sys.argv[1]
|
||||||
|
@ -18,10 +18,18 @@ profile_config = config.get_config(profile)
|
||||||
cache = SerializableTokenCache()
|
cache = SerializableTokenCache()
|
||||||
app = ConfidentialClientApplication(profile_config.ClientId, client_credential=profile_config.ClientSecret, token_cache=cache, authority=profile_config.Authority)
|
app = ConfidentialClientApplication(profile_config.ClientId, client_credential=profile_config.ClientSecret, token_cache=cache, authority=profile_config.Authority)
|
||||||
|
|
||||||
|
if profile_config.AccessTokenFileName.exists() and print_access_token:
|
||||||
|
st = os.stat(profile_config.AccessTokenFileName)
|
||||||
|
if (time.time()-st.st_mtime) < profile_config.Timeout:
|
||||||
|
with open(profile_config.AccessTokenFileName, 'r') as f:
|
||||||
|
print(f.read())
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# check if file exists and error out if it doesn't
|
# check if file exists and error out if it doesn't
|
||||||
try:
|
try:
|
||||||
old_refresh_token = open(profile_config.RefreshTokenFileName,'r').read()
|
old_refresh_token = open(profile_config.RefreshTokenFileName,'r').read()
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
sys.exit("Please get the initial token by running `o365-get-token` first.")
|
sys.exit("Please get the initial token by running `o365-get-token` first.")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue