File size: 2,111 Bytes
2bf52ad
d620f19
dd82908
3d9aeea
3ef36dd
3012d35
d620f19
2bf52ad
 
4440844
 
c685413
9c7ea38
 
f50567e
c685413
 
 
 
 
 
 
0269124
987fbf6
0269124
 
 
 
3d9aeea
0269124
3d9aeea
 
 
c685413
3d9aeea
 
 
 
 
 
ef9c007
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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