Skip to content

Instantly share code, notes, and snippets.

@karmanyaahm
Created October 3, 2020 23:34
Show Gist options
  • Save karmanyaahm/aa2a035e5a9e38d60b5fbf1507db2d0f to your computer and use it in GitHub Desktop.
Save karmanyaahm/aa2a035e5a9e38d60b5fbf1507db2d0f to your computer and use it in GitHub Desktop.
Google OpenID API Python get User Info
##it took me hours to find what I wanted in between deprecated APIs and lacking documentation as of Oct 2020, hopefully this'll help someone
import requests
creds = google.oauth2.credentials.Credentials ###not real thing, replace with the credentials you got from the flow
url = 'https://openidconnect.googleapis.com/v1/userinfo'
head = { 'Authorization': 'Bearer '+creds.token}
response = requests.get(url, headers=head)
print(response.json()['sub'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment