Reputation: 1
import requests
from datetime import datetime
refresh_token = "1//0gGNYTet38TyKCgYIARAAGBASNwF-L9Ir8JMGjR82iiCdPY0bTfdu2gutU50qPGFcASU4EmDWSouvnhvbuGtrEAiijoElpRoUKqg"
client_id = (
"760863696391-ub3lqtqj4ou3qf4l35vjd3sa5bft14u1.apps.googleusercontent.com"
)
client_secret = "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"
token_endpoint = "https://oauth2.googleapis.com/token"
payload = {
"refresh_token": refresh_token,
"client_id": client_id,
"client_secret": client_secret,
"grant_type": "refresh_token",
}
# Make the POST request to obtain new access tokens
response = requests.post(token_endpoint, data=payload)
token_data = response.json()
print(response.json())
access_token = token_data.get("access_token")
print(access_token)
refresh_token = token_data.get("refresh_token")
expires_in = token_data.get("expires_in")
print(access_token, "|", refresh_token, "||", expires_in)
in above code while getting access token from refresh token it work for sometime but after certain time while trying to get access_token from refresh token it throws
{
'error': 'invalid_grant',
'error_description': 'reauth related error (invalid_rapt)',
'error_uri': 'https://support.google.com/a/answer/9368756',
'error_subtype': 'invalid_rapt'
}
I read the docs. I am expecting that once the user gets refresh token it should not expire so that the user should not have to re-login.`
Upvotes: 0
Views: 202
Reputation: 98
Per the google docs, the time you can set on the refresh token for authtication is 24 hours.
The minimum frequency allowed is 1 hour, and the maximum is 24 hours. The frequency doesn't include how long a user has been inactive in the session. It is the fixed time that elapses before the user needs to sign in again.
You can also check the Exempt trusted apps box to exempt trusted apps from reauthentication. (Trusted apps are marked as Trusted on the App access control page.
Upvotes: 0