The request body must contain the following parameter: 'refresh_token' or 'NoneType' object has no attribute 'refresh_token'
See original GitHub issueHi,
I have followed the instructions to setup the oflow authentication and have a successful token in my directory.
>>> mailbox = account.mailbox()
>>> query = mailbox.new_query().on_attribute('from').contains('@bob.com')
>>> query = query.chain('and').on_attribute('is_read').equals(False)
>>> messages = mailbox.get_messages(limit=25, query=query)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/O365/connection.py", line 539, in _internal_request
**kwargs)
File "/usr/local/lib/python3.6/site-packages/requests_oauthlib/oauth2_session.py", line 395, in request
http_method=method, body=data, headers=headers)
File "/usr/local/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 198, in add_token
raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)
...
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) AADSTS900144: The request body must contain the following parameter: 'refresh_token'.
Trace ID: 78ae8c45-f51e-4dfe-a46a-....
Correlation ID: 46063da9-0a05-495a-8d32-...
Timestamp: 2019-01-23 14:47:03Z
>>>
However when I run a script I get the missing authentication token error if I use just account, looking at other issues and documentation I assumed I must need to create a con each time also
so ive added the below:
scopes = ['calendar','message_all','offline_access']
con = Connection((credentials.username, credentials.password), scopes=scopes)
con.refresh_token()
account = Account((credentials.username, credentials.password))
mailbox = account.mailbox()
query = mailbox.new_query().on_attribute('from').contains('@kcom.com')
query = query.chain('and').on_attribute('is_read').equals(False)
messages = mailbox.get_messages(limit=25, query=query)
and now I get the error
>>> con.refresh_token()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/O365/connection.py", line 484, in refresh_token
self.token = token = (self.session
AttributeError: 'NoneType' object has no attribute 'refresh_token'
Thanks for any help
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (16 by maintainers)
Top Results From Across the Web
Unable to access the access code and refresh token of AAD ...
I'm trying to automate the file transfer between one drive and Linux. Hence I need to generate the access token and refresh token....
Read more >Solved: OAuth Refresh token has expired after 90 days
We try to authenticate using an OAuth Refresh Token (this authentication ... of this call not only contains the access token, but also...
Read more >POST refreshtoken | Authentication (OAuth)
Acquire a new access token by using the refresh token provided by the POST gettoken endpoint. See the Field Guide for more information...
Read more >JWT & Refresh Token APIs - FusionAuth
APIs that allow you to manage Refresh Tokens, verify Access Tokens and retrieve public keys used for verifying JWT signatures.
Read more >Get an OAuth2 Refresh Token and Configure Your Client
properties file should have all you need to make test API calls, and should contain values similar to the following: ... api.googleads.developerToken ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You do not have the refresh_token. That’s why you are getting the error.
If you don’t ask the offline_access scope basically you only receive a “1 time, 1 hour” access token. After this 1 hour you will have to re-authenticate again. To avoid this just include the offline_access scope.
Do the following in order:
Make sure you have this permissions included in the app registration portal:
Perform the authentication flow with this library. Just do this:
I’ve just added the scopes you have pasted on your token definition above. Check scope helpers for more options.
Then (without calling
account.authenticate
again), just use the library… you don’t have to callrefresh_token
. The token is refreshed automatically.finally got it working! I used what you had said above. what threw me off was the step 1, I assumed I needed to use the manual scopes as a step before I could use the helper, I then realised I add them manually to the app in the 365 portal, then use step 2.
thanks for your assistance and your patience