mirror of
https://github.com/vale981/outlook-oauth-hack
synced 2025-03-04 16:41:38 -05:00
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from msal import ConfidentialClientApplication, SerializableTokenCache
|
|
import config
|
|
import sys
|
|
|
|
redirect_uri = "http://localhost"
|
|
|
|
# We use the cache to extract the refresh token
|
|
cache = SerializableTokenCache()
|
|
app = ConfidentialClientApplication(config.ClientId, client_credential=config.ClientSecret, token_cache=cache)
|
|
|
|
url = app.get_authorization_request_url(config.Scopes, redirect_uri=redirect_uri)
|
|
|
|
print('Navigate to the following url in a web browser:')
|
|
print(url)
|
|
|
|
print()
|
|
|
|
print('After login, you will be redirected to a blank (or error) page with a url containing an access code. Paste the url below.')
|
|
resp = input('Response url: ')
|
|
|
|
i = resp.find('code') + 5
|
|
code = resp[i : resp.find('&', i)] if i > 4 else resp
|
|
|
|
token = app.acquire_token_by_authorization_code(code, config.Scopes, redirect_uri=redirect_uri)
|
|
|
|
print()
|
|
|
|
if 'error' in token:
|
|
print(token)
|
|
sys.exit("Failed to get access token")
|
|
|
|
print(f'Access token acquired, writing to file {config.OutputFileName}')
|
|
with open(config.OutputFileName, 'w') as f:
|
|
f.write(cache.find('RefreshToken')[0]['secret'])
|