Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: The request body must contain the following parameter: 'refresh_token' #8

Closed
stepic opened this issue Jun 15, 2023 · 2 comments

Comments

@stepic
Copy link

stepic commented Jun 15, 2023

OAuth2 fails because of this error

Traceback (most recent call last):
File "/volume1/homes/stepic/notion-bot/notion-bot.py", line 32, in
lists = todo_client.get_lists()
File "/volume1/homes/stepic/notion-bot/lib/python3.9/site-packages/pymstodo/client.py", line 307, in get_lists
self._refresh_token()
File "/volume1/homes/stepic/notion-bot/lib/python3.9/site-packages/pymstodo/client.py", line 292, in _refresh_token
new_token = oa_sess.refresh_token(token_url, client_id=self.client_id, client_secret=self.client_secret)
File "/volume1/homes/stepic/notion-bot/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 452, in refresh_token
self.token = self._client.parse_request_body_response(r.text, scope=self.scope)
File "/volume1/homes/stepic/notion-bot/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 427, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "/volume1/homes/stepic/notion-bot/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in parse_token_response
validate_token_parameters(params)
File "/volume1/homes/stepic/notion-bot/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 448, in validate_token_parameters
raise_from_error(params.get('error'), params)
File "/volume1/homes/stepic/notion-bot/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 399, in raise_from_error
raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) AADSTS900144: The request body must contain the following parameter: 'refresh_token'.

@stepic stepic closed this as completed Jun 16, 2023
@stepic stepic reopened this Jun 22, 2023
@TheStutterNerd
Copy link

TheStutterNerd commented Aug 30, 2023

This was happening to me too when the tokens expired after an hour. I realised that it wasn't getting a refresh_token within the token itself. After googling and going through the source code, I found out that you have to pass offline_access inside the scope otherwise a refresh_token won't be returned.

  • pymstodo/client.py
class ToDoConnection:
...
_scope: str = 'openid Tasks.ReadWrite offline_access'
...

After the change above, I got a refresh_token. I still need to wait an hour to check if it refreshes correctly but I'd imagine so. So yeah... Thought I'd post this here whilst I wait. I'll edit this comment otherwise.

@inbalboa
Copy link
Owner

inbalboa commented Apr 28, 2024

Sorry for ignoring, just reverted the scope to openid Tasks.ReadWrite offline_access.

inbalboa added a commit that referenced this issue Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants