question

ZouchaMichael-8172 avatar image
0 Votes"
ZouchaMichael-8172 asked azure-cxp-api edited

Outlook Connection - Token received without permissions

I am trying to write a script in Python to grab new emails from a specific folder and save the attachments to upload to a database. I am able to authenticate the token, but am getting the following error when trying to grab the emails:

Unauthorized for url.
The token contains no permissions, or permissions can not be understood.

I have included the code I am using to connect to Microsoft Graph. Any insights would be greatly appreciated!

(credentials and tenant_id are correct in my code, took them out for obvious reasons)

from O365 import Account, MSOffice365Protocol, MSGraphProtocol

credentials = ('xxxxxx', 'xxxxxx')
protocol = MSGraphProtocol(default_resource='reporting.triometric@xxxx.com')
scopes_graph = protocol.get_scopes_for('message_all_shared')
scopes = ['https://graph.microsoft.com/.default']
account = Account(credentials, auth_flow_type='credentials', tenant_id="**", scopes=scopes,)


if account.authenticate():
print('Authenticated')
mailbox = account.mailbox(resource='reporting.triometric@xxxx.com')
inbox = mailbox.inbox_folder()
for message in inbox.get_messages():
print(message)

microsoft-graph-mail
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.

1 Answer

Deva-MSFT avatar image
0 Votes"
Deva-MSFT answered
  • Validate the above token in https://jwt.ms and make sure it contains the necessary permissions/scopes to access the above Graph resource or not.

  • Just to isolate the issue out of your code, you can make the same API call in Graph Explorer for the same user and it will work for you. So it will tell you that issue is due to the permissions.

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.