Well, I am trying to implement google oauth authentication with my django project.
I follow the guide here:
https://developers.google.com/accounts/docs/OAuth2Login?hl=de-DE
I have got the response from exchanging code. I got a string type json which contains multiple info like access_token, id_token, etc.
Id_token is a cryptographically-signed JSON object encoded in base 64. I try to decode id_token with python module base64, but failed.
I also tried PyJWT, failed.
Is there any way to decode and verify it?
Know this is an old post but I found it via Google so I thought somebody else might drop in...
I ended up doing:
segments = response['id_token'].split('.')
if (len(segments) != 3):
raise Exception('Wrong number of segments in token: %s' % id_token)
b64string = segments[1]
b64string = b64string.encode('ascii')
padded = b64string + '=' * (4 - len(b64string) % 4)
padded = base64.urlsafe_b64decode(padded)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With