O365 / python-o365

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

Token Authentication link does not load #652

Closed seve-martinez closed 3 years ago

seve-martinez commented 3 years ago

I have registered my app in the App Registration and have given it the basic auth Mail.ReadWrite Mail.Send User.Read

I've also used delegated access. Basically I've recreated the example app in the README to a T.

I then took the generated client ID and client secret and used the following code:

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

Which then opens up a link. The link will ask me to select a login (I have several for Azure) and I select the one where I registered the app. However, the link does not load. It just ends up at a white screen and never progresses or provides a token. If I paste the link I get the following response:

Something go wrong. Please try again.
Unable to fetch auth token. Error: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /common/oauth2/v2.0/token (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),))

Is this something with the link generation? Perhaps user error? I have tried several browsers (Chrome, Edge, MS Explorer) with no change in behavior.

Thanks.

alejcas commented 3 years ago

The basic and default flow asks you to visit a link and authenticate and the console will wait for a response. Just copy the link after authenticating ( the link on the blank page) and paste it on the console. then hit enter.

seve-martinez commented 3 years ago

@janscas Thanks for the reply. Upon trying that I get the following error in Python: Something go wrong. Please try again. Unable to fetch auth token. Error: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /common/oauth2/v2.0/token (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),))

are there any SSL considerations that I must pass?

alejcas commented 3 years ago

Are you sure you pasted the complete url? Its something like:

https://login.microsoftonline.com/common/oauth2/nativeclient?code=Xxxxxxxxx

if you have the “code” part the url is correct.

Are you on mac?

seve-martinez commented 3 years ago

Yes, it's like that plus a super long code and a state and session state values.

No, I'm not on a Mac. Just plain Win 10

I'm running this in PyCharm if it makes a difference

alejcas commented 3 years ago

I’m also using pycharm and when you paste the url before hitting enter go first to the begining of the line. Otherwise you will submit just a partial url.

nwold commented 3 years ago

I've had this issue in Pycharm. When I paste the URL back into pycharm i get an error or nothing happens...may be because i was submitting a partial URL. When I use the IDLE (Python 3.9 64-bit) it works fine.

seve-martinez commented 3 years ago

Thanks for the replies. Unfortunately using IDLE did not change the behavior. I continue to receive SSL errors. I did confirm that I was pasting the entire URL. Is there anything else that I can try?

seve-martinez commented 3 years ago

Upon running this again with an updated Python library, I got this error:

Unable to fetch auth token. Error: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /common/oauth2/v2.0/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)'))) Something go wrong. Please try again.

I passed verify_ssl=False to the Account object after looking at the code and seeing the **kwargs from there is passed to the Connection constructor, but no change.

`if account.authenticate(scopes=['basic', 'message_all'], verify_ssl=False):

Do stuff here`

alejcas commented 3 years ago

We use requests behind the scenes so maybe you find something about this searching for the same issue about requests

seve-martinez commented 3 years ago

@janscas Thanks for the reply. Closing this ticket because the SSL issue is on my side and nothing to do with the O365 library.