import msal import os import streamlit as st import webbrowser as wb import requests from msal import PublicClientApplication APPLICATION_ID_KEY = os.getenv('APPLICATION_ID_KEY') CLIENT_SECRET_KEY = os.getenv('CLIENT_SECRET_KEY') #st.write(APPLICATION_ID_KEY) #st.write(CLIENT_SECRET_KEY) authority_url = 'https://login.microsoftonline.com/consumers' base_url = 'https://graph.microsoft.com/v1.0/' endpoint = base_url + 'me' SCOPES = ['User.Read','User.Export.All'] # Authenticate with Auth Code client_instance = msal.ConfidentialClientApplication( client_id=APPLICATION_ID_KEY, client_credential=CLIENT_SECRET_KEY, authority=authority_url ) authorization_request_url = client_instance.get_authorization_request_url(SCOPES) st.write('Connecting to MSGraph with url:' + authorization_request_url) wb.open(authorization_request_url, new=True) access_token = client.instance.acquire_token_by_authorization_code( code=AUTHORIZATION_KEY, scopes=SCOPES) access_token_id = access_token['access_token'] headers = {'Authorization': 'Bearer ' + access_token_id} endpoint = base_url + 'me' response = requests.get(endpoint, headers=headers) st.write(response) st.write(rresponse.json) # URLs used in this sample app to demonstrate MS Graph in Python # https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/~/Authentication/appId/d36c689d-3c61-4be6-a230-c09fc54cf80d/objectId/ece93996-1d7c-4b39-abc5-de51487073ed/isMSAApp~/false/defaultBlade/Overview/appSignInAudience/AzureADandPersonalMicrosoftAccount/servicePrincipalCreated~/true # https://developer.microsoft.com/en-us/graph/graph-explorer # https://chatgpt.com/c/67065b64-e2a8-800d-8b64-69cfe7aaed7f # https://www.google.com/search?q=msal+pypi&oq=msal+pypi&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIICAEQABgWGB4yCAgCEAAYFhgeMg0IAxAAGIYDGIAEGIoFMg0IBBAAGIYDGIAEGIoFMg0IBRAAGIYDGIAEGIoFMgoIBhAAGIAEGKIEMgoIBxAAGIAEGKIEMgoICBAAGIAEGKIE0gEIMTk2NGowajeoAgCwAgA&sourceid=chrome&ie=UTF-8 # https://www.youtube.com/watch?v=1Jyd7SA-0kI&list=PLHgX2IExbFot3M2dudQEbTVEk9ikRJ2h5&t=972s # https://huggingface.co/spaces/awacke1/MSGraphAPI