namsoojang / streamlit-google-oauth

An example Streamlit application that incorporates Google OAuth 2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

streamlit-google-oauth

An example Streamlit application that incorporates Google OAuth 2.0

PIP

pip install git+https://github.com/hunkim/streamlit-google-oauth

Setup Google OAuth client ID

image

Make sure people api is enabled

image

Put client id, etc. in env

Put in the .env file

~/streamlit-google-oauth$ cat .env 
GOOGLE_CLIENT_ID=767025784452-fscnojvddiek...
GOOGLE_CLIENT_SECRET=GOCSPX-KE4_...
GOOGLE_REDIRECT_URI=http://localhost:8080

or

export GOOGLE_CLIENT_ID="xxx"
export GOOGLE_CLIENT_SECRET="yyy"
export GOOGLE_REDIRECT_URI="http://localhost:8080"

Add login in your streamlit app

import streamlit as st
import os
from dotenv import load_dotenv
import streamlit_google_oauth as oauth

load_dotenv()
client_id = os.environ["GOOGLE_CLIENT_ID"]
client_secret = os.environ["GOOGLE_CLIENT_SECRET"]
redirect_uri = os.environ["GOOGLE_REDIRECT_URI"]


if __name__ == "__main__":
    login_info = oauth.login(
        client_id=client_id,
        client_secret=client_secret,
        redirect_uri=redirect_uri,
        login_button_text="Continue with Google",
        logout_button_text="Logout",
    )
    if login_info:
        user_id, user_email = login_info
        st.write(f"Welcome {user_email}")
    else:
        st.write("Please login")

Run streamlit with google oauth

streamlit run app.py --server.port 8080

Quick demo screenshots

Quick demo

About

An example Streamlit application that incorporates Google OAuth 2.0


Languages

Language:Python 93.4%Language:Makefile 6.6%