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

Add config to pass on token scope-change warnings #329

Merged
merged 3 commits into from
Oct 13, 2022

Conversation

jstevans
Copy link
Contributor

This provides a more-explicit fix for #287

Since we get exactly the same token in the warning, and the original commit's message suggests the warning is optional, it seems as though we can just do session.token = e.token (whose setter calls the necessary follow-on logic) and continue as usual.

we call `requests_oauthlib.OAuth2Session#fetch_token` which
* [calls `oauthlib.oauth2.WebApplicationClient#parse_request_body_response`](https://github.com/requests/requests-oauthlib/blob/3a2a852e33c691c7e793300ce366a01b6e4b3848/requests_oauthlib/oauth2_session.py#L388) which
  * is actually `oauthlib.oauth2.rfc6749.clients.Client#parse_request_body_response` which
    * [calls `oauthlib.oauth2.rfc6749.parameters.parse_token_response`](https://github.com/oauthlib/oauthlib/blob/6569ec3c062be7268f4a17f5a371aa29f1bcfa4a/oauthlib/oauth2/rfc6749/clients/base.py#L427) which
      * [emits a `Warning` on changed scopes](oauthlib/oauthlib@ca4811b#diff-27d6ecb53c0926bcd8cc87f98cf661d5e2936cd48b04f57cdfdb63cd3b23ab38R400-R406), complete with the parsed token
    * sets `self.token`
    * [calls `self.populate_token_attributes`](https://github.com/oauthlib/oauthlib/blob/6569ec3c062be7268f4a17f5a371aa29f1bcfa4a/oauthlib/oauth2/rfc6749/clients/base.py#L428)
* sets `self.token` which
    * [sets the WebApplicationClient's token again, and calls its `populate_token_attributes` again](https://github.com/requests/requests-oauthlib/blob/3a2a852e33c691c7e793300ce366a01b6e4b3848/requests_oauthlib/oauth2_session.py#L142-L145)
* returns `self.token`


Since we get exactly the same token in the warning, and the [original commit's message](oauthlib/oauthlib@ca4811b) suggests the warning is optional, it seems as though we can just do `session.token = e.token` (whose setter calls the necessary follow-on logic) and continue as usual.
Copy link
Owner

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable approach - thanks for the fix!

@freakboy3742 freakboy3742 merged commit a97737b into freakboy3742:main Oct 13, 2022
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

Successfully merging this pull request may close these issues.

2 participants