question

AdminTeam-3346 avatar image
0 Votes"
AdminTeam-3346 asked saldana-msft edited

Simple question: How do I authenticate with Graph API with Python app?

I just want to be able to use the Planner API. See code below:

from O365 import Account

credentials = (CLIENT_ID, CLIENT_SECRET)

base_url = "https://graph.microsoft.com"

scopes = [
'User.Read.All',
'offline_access',
'openid',
'profile'
]

account = Account(credentials)

if not account.is_authenticated:
account.authenticate(scopes=scopes)

else:
print("Authenticated")


response = requests.get(f"{base_url}/{version}/{query_parameters}")
print(response)

The output I get is Response 401, even though earlier I did manage to print "Authenticated". I've already registered my app in Azure Portal, and have enabled multi-tenant. My client ID and client secret is also obtained from there. Why am I still getting 401 response error?

microsoft-authenticatormicrosoft-graph-sdk
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @AdminTeam-3346 would you kindly share the request ID and the full error that is returned? Are you able to reproduce this using graph explorer or postman? The 401 error indicates that the request is unauthorized, would you kindly use jwt.ms to decode the authentication token to check the claims to confirm that the User.Read.All permission has been granted to your application as in the screenshot.86894-permissionsscreenado.png.


0 Votes 0 ·

0 Answers