import os from requests_oauthlib import OAuth2Session client_id = os.environ["CLIENT_ID"] client_secret = os.environ["CLIENT_SECRET"] tenant_id = os.environ["TENANT_ID"] redirect_uri = "http://localhost:8080/callback" # Check readme to make this work locally scope = ["openid", "profile", "email"] authorization_base_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize" token_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token" oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope) authorization_url, state = oauth.authorization_url(authorization_base_url) print("Go to the following URL and approve the app:") print(authorization_url) redirect_response = input("Paste the full redirect URL after approval: ") token = oauth.fetch_token(token_url, authorization_response=redirect_response, client_secret=client_secret) print("Access token:", token["access_token"])