Forked from frankie567/interactive_google_oauth2.py
Created
February 24, 2020 09:53
-
-
Save laranea/ab5707e695f1d64624173ea43b67e979 to your computer and use it in GitHub Desktop.
Interactive Google OAuth2 flow with Streamlit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import streamlit as st | |
from httpx_oauth.clients.google import GoogleOAuth2 | |
st.title("Google OAuth2 flow") | |
"## Configuration" | |
client_id = st.text_input("Client ID") | |
client_secret = st.text_input("Client secret") | |
redirect_uri = st.text_input("Redirect URI", "http://localhost:8000/redirect") | |
if client_id and client_secret and redirect_uri: | |
client = GoogleOAuth2(client_id, client_secret) | |
else: | |
client = None | |
"## Authorization URL" | |
async def write_authorization_url(): | |
authorization_url = await client.get_authorization_url( | |
redirect_uri, | |
scope=["profile", "email"], | |
extras_params={"access_type": "offline"}, | |
) | |
st.write(authorization_url) | |
if client: | |
asyncio.run(write_authorization_url()) | |
else: | |
"Waiting client configuration..." | |
"## Callback" | |
if client: | |
code = st.text_input("Authorization code") | |
else: | |
code = None | |
"Waiting client configuration..." | |
"## Access token" | |
async def write_access_token(code): | |
token = await client.get_access_token(code, redirect_uri) | |
st.write(token) | |
if code: | |
asyncio.run(write_access_token(code)) | |
else: | |
"Waiting authorization code..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment