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.
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
ofrefresh_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.
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.