Skip to content

Instantly share code, notes, and snippets.

@davidbernick
Created May 13, 2017 03:58
Show Gist options
  • Save davidbernick/ea91fb28e537bf747afc5fddf063a429 to your computer and use it in GitHub Desktop.
Save davidbernick/ea91fb28e537bf747afc5fddf063a429 to your computer and use it in GitHub Desktop.
Getting JWT via google oauth
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run_flow,argparser
from oauth2client.file import Storage
import argparse,os
CLIENT_ID = '806222273987-v6882atb04c4pfl8n3279iacv33e9tt7.apps.googleusercontent.com'
CLIENT_SECRET = 'xxxxx'
REDIRECT_URL='https://yourwebapp/oauth2c/OAuthProxy.jsp'
CREDS_FILE = os.path.join(os.path.dirname(__file__), 'credentials.json')
parser = argparse.ArgumentParser(parents=[argparser])
flags = parser.parse_args()
storage = Storage(CREDS_FILE)
credentials = storage.get()
flow = OAuth2WebServerFlow(client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
scope=['profile','openid','email'],
redirect_uri=REDIRECT_URL)
auth_uri = flow.step1_get_authorize_url()
print("Browser here %s" % auth_uri)
code = raw_input('Look at URL and paste code parameter here. Enter verification code: ').strip()
credentials = flow.step2_exchange(code)
storage.put(credentials)
print(storage.get().to_json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment