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

Fix documentation or fix the way client is handled in requests-oauthlib for refreshing tokens #489

Closed
ghost opened this issue Mar 25, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 25, 2022

Hello!

I don't mind working through and trying to fix this in oauth2_sessions.py but it would require reworking how the client deceleration is handled. Unfortunately, the documentation for client refreshing isn't really accurate, as most endpoints expect a grant_type of refresh_token.

Assuming there isn't a massive interest in changing the way references are made to clients, at least the documentation can be updated. The fitbit example pointed me in the right direction after a couple of hours.

from requests.auth import HTTPBasicAuth
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import Client

client_id = "abc"
client_secret = "def"
refresh_token = "hij"
refresh_url = "https://api.twitter.com/2/oauth2/token"
auth = HTTPBasicAuth(client_id, client_secret)
additional_headers = {
    'client_id': client_id,
}
# setting the client type
client = Client(client_id)
twitter_refresh = OAuth2Session(client=client)
twitter_refresh.refresh_token(auth_url, refresh_token=refresh_token, auth=auth, **additional_headers)

Sorry if it's a bit messy, but this will actually pass the proper grant type and fix any issues with refresh tokens not being returned. While I haven't tested it on Google's API -- from their documentation it seems they also need the same grant_type, so it might be worth it to actually try to fix the code to not require an undocumented workaround.

Just wanted to put this somewhere in-case anyone spent forever working on it.

@ghost
Copy link
Author

ghost commented Mar 25, 2022

Ignore this; I sadly realized my mistake was in the fact that refresh_token wasn't defined on the first run through... oops.

@ghost ghost closed this as completed Mar 25, 2022
This issue was closed.
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

0 participants