I need to verify google token in my backend drf. I use React library reactjs-social-login, and it works perfect and send data:
{
"access_token": "...",
"token_type": "Bearer",
"expires_in": 3599,
"scope": "...",
"authuser": "0",
"prompt": "none",
"sub": "...",
"name": "...",
"given_name": "...",
"family_name": "...",
"picture": "...",
"email": "...",
"email_verified": true,
"locale": "en"
}
Then I send this data to APIView. I install google-auth library for django. The question is, how can I check validation of this google access token. Library expect another token:
def verify_token(
id_token,
request,
audience=None,
certs_url=_GOOGLE_OAUTH2_CERTS_URL,
clock_skew_in_seconds=0,
):
And in this case I've got the exception. My view:
try:
id_token.verify_oauth2_token(google_user['token'], requests.Request())
except ValueError:
raise AuthenticationFailed(code=403, detail="Bad token Google")
Thanks for any advices
GoogleAuthProviderand pass theid_tokenin init.Then call
get_decoded_data()to get info from thatid_token.