O365 Authorization Code Grant Flow URL not loading

1k views Asked by At

I'm trying to use the O365 pypl python library to receive a new auth token after changing my microsoft password. The authentication flow looks like this:

from O365 import Account
credentials = ('my_client_id', 'my_client_secret')

# the default protocol will be Microsoft Graph
# the default authentication method will be "on behalf of a user"

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

I receive a message saying to visit the following URL to give consent. However, when I paste the URL, I am asked to login to microsoft and then nothing happens i.e. no permissions or consent page appears. My organization recently switched to Single Sign On so I'm wondering if this could potentially be causing the issue or if anyone else has experienced this? I'm new to this and very lost so any help is greatly appreciated! Thanks so much!!

1

There are 1 answers

0
Imran On

To receive auth token, please check the following:

  • Register your application at Microsoft Application Registration Portal.
  • Login to the portal to get the access token.
  • To consent the application in order to access the resources first get the authorization URL like below:
url = account.connection.get_authorization_url()
  • Visit the above URL and grant consent for the application.
  • To perform authentication, create Account instance and authenticate using the authenticate method.
from pyo365 import Account
account = Account(credentials=('client_id', 'client_secret'))
result = account.authenticate(scopes=['basic', 'message_all'])
  • After requesting a token, app consent screen will appear where you have to give consent.
  • The user have to provide the result url after consent.
  • Token will be stored in the default location if all goes as expected.

For more information in detail, please refer below links:

https://github.com/janscas/pyo365#authentication

Question about get_authorization_url · Issue #13 · janscas/pyo365 · GitHub