question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The request body must contain the following parameter: 'refresh_token' or 'NoneType' object has no attribute 'refresh_token'

See original GitHub issue

Hi,

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:closed
  • Created 5 years ago
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
janscascommented, Jan 23, 2019

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:

  1. Make sure you have this permissions included in the app registration portal:

    • User.Read
    • offline_access
  2. Perform the authentication flow with this library. Just do this:

    credentials = ('my_client_id', 'my_secret')
    my_desired_scopes =['basic', 'calendar', 'address_book_all', 'message_all']
    account = Account(credentials)
    account.authenticate(scopes=my_desired_scopes)
    # follow authentication flow. You should retrieve the token. 
    

    I’ve just added the scopes you have pasted on your token definition above. Check scope helpers for more options.

  3. Then (without calling account.authenticate again), just use the library… you don’t have to call refresh_token. The token is refreshed automatically.

1reaction
ajwillocommented, Jan 24, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found