|
5 | 5 | "authority": "https://login.microsoftonline.com/organizations", |
6 | 6 | "client_id": "your_client_id", |
7 | 7 | "username": "your_username@your_tenant.com", |
8 | | - "scope": ["User.Read"], |
9 | | - "password": "This is a sample only. You better NOT persist your password." |
| 8 | + "password": "This is a sample only. You better NOT persist your password.", |
| 9 | + "scope": ["User.ReadBasic.All"], |
| 10 | + // You can find the other permission names from this document |
| 11 | + // https://docs.microsoft.com/en-us/graph/permissions-reference |
| 12 | + "endpoint": "https://graph.microsoft.com/v1.0/users" |
| 13 | + // You can find more Microsoft Graph API endpoints from Graph Explorer |
| 14 | + // https://developer.microsoft.com/en-us/graph/graph-explorer |
10 | 15 | } |
11 | 16 |
|
12 | 17 | You can then run this sample with a JSON configuration file: |
|
18 | 23 | import json |
19 | 24 | import logging |
20 | 25 |
|
| 26 | +import requests |
21 | 27 | import msal |
22 | 28 |
|
23 | 29 |
|
|
51 | 57 | config["username"], config["password"], scopes=config["scope"]) |
52 | 58 |
|
53 | 59 | if "access_token" in result: |
54 | | - print(result["access_token"]) |
55 | | - print(result["token_type"]) |
56 | | - print(result["expires_in"]) # You don't normally need to care about this. |
57 | | - # It will be good for at least 5 minutes. |
| 60 | + # Calling graph using the access token |
| 61 | + graph_data = requests.get( # Use token to call downstream service |
| 62 | + config["endpoint"], |
| 63 | + headers={'Authorization': 'Bearer ' + result['access_token']},).json() |
| 64 | + print("Graph API call result: %s" % json.dumps(graph_data, indent=2)) |
58 | 65 | else: |
59 | 66 | print(result.get("error")) |
60 | 67 | print(result.get("error_description")) |
|
0 commit comments