forked from vgrem/office365-rest-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.py
More file actions
31 lines (24 loc) · 1.02 KB
/
interactive.py
File metadata and controls
31 lines (24 loc) · 1.02 KB
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
"""
Demonstrates how to login when the user may be prompted for input by the authorization server.
For example, to sign in, perform multi-factor authentication (MFA), or to grant consent
to more resource access permissions.
Note:
in AAD portal ensure Mobile and Desktop application is added for application
and http://localhost is set as redirect uri
https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#interactive-and-non-interactive-authentication
"""
import msal
from office365.graph_client import GraphClient
from tests import test_tenant, test_client_id
def acquire_token():
app = msal.PublicClientApplication(
test_client_id,
authority='https://login.microsoftonline.com/{0}'.format(test_tenant),
client_credential=None
)
scopes = ["https://graph.microsoft.com/.default"]
result = app.acquire_token_interactive(scopes=scopes)
return result
client = GraphClient(acquire_token)
me = client.me.get().execute_query()
print(me.user_principal_name)