Skip to content

Instantly share code, notes, and snippets.

@petergs
Last active October 18, 2024 23:55
Show Gist options
  • Select an option

  • Save petergs/52c4318925d4064586b8c68a598872da to your computer and use it in GitHub Desktop.

Select an option

Save petergs/52c4318925d4064586b8c68a598872da to your computer and use it in GitHub Desktop.
graph-api-token-from-stdin-template.py
import requests
import sys
import json
MS_GRAPH_API_BASE_URL = "https://graph.microsoft.com"
if __name__ == "__main__":
if sys.stdin is not None:
access_token = sys.stdin.readline().rstrip()
else:
print("Error: Expecting an access_token supplied from stdin")
sys.exit(1)
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}
r = requests.get(
url=f"{MS_GRAPH_API_BASE_URL}/v1.0/me",
headers=headers,
).json()
print(json.dumps(r, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment