O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.65k stars 418 forks source link

Application not configured as a multi-tenant #1103

Closed pkoevesdi closed 3 hours ago

pkoevesdi commented 3 hours ago

I try to authenticate with this simple script:

from O365 import Account
credentials = ('#############', '###############')

account = Account(credentials)
if account.authenticate(scopes=['basic', 'message_all']):
   print('Authenticated!')

I get printed:

Visit the following url to give consent:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id=#####....
Paste the authenticated url here:

When I visit this URL, I get the following error code: AADSTS50194: Application '#############' is not configured as a multi-tenant application. Usage of the /common endpoint is not supported for such applications created after '10/15/2018'. Use a tenant-specific endpoint or configure the application to be multi-tenant.

What do I have to set inside MS 365 to make this work?

pkoevesdi commented 3 hours ago

Ok, if I change the line to

account = Account(credentials, tenant_id='organizations')

or my tenant ID instead of organizations, I get a URL of type https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize, and a different error message: AADSTS500113: No reply address is registered for the application. This is probably a different issue, I'll close this here.

Background: I thought I used the auth_flow_type=='authorization', but probably I was on auth_flow_type=='credentials', which doesn't allow the default tenant common.

pkoevesdi commented 2 hours ago

Btw.: the resulting account.connection object indeed shows _auth_flow_type = 'authorization'.