Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Updating device flow sample
  • Loading branch information
abhidnya13 committed Oct 29, 2019
commit 74007776d22d06e660c31fe4e006d4ad656e684c
18 changes: 12 additions & 6 deletions sample/device_flow_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
{
"authority": "https://login.microsoftonline.com/common",
"client_id": "your_client_id",
"scope": ["User.Read"]
"scope": ["User.ReadBasic.All"],
// You can find the other permission names from this document
// https://docs.microsoft.com/en-us/graph/permissions-reference
"endpoint": "https://graph.microsoft.com/v1.0/users"
// You can find more Microsoft Graph API endpoints from Graph Explorer
// https://developer.microsoft.com/en-us/graph/graph-explorer
}

You can then run this sample with a JSON configuration file:
Expand All @@ -16,6 +21,7 @@
import json
import logging

import requests
import msal


Expand Down Expand Up @@ -70,12 +76,12 @@
# and then keep calling acquire_token_by_device_flow(flow) in your own customized loop.

if "access_token" in result:
print(result["access_token"])
print(result["token_type"])
print(result["expires_in"]) # You don't normally need to care about this.
# It will be good for at least 5 minutes.
# Calling graph using the access token
graph_data = requests.get( # Use token to call downstream service
config["endpoint"],
headers={'Authorization': 'Bearer ' + result['access_token']},).json()
print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
else:
print(result.get("error"))
print(result.get("error_description"))
print(result.get("correlation_id")) # You may need this when reporting a bug