Using this wonderful code Implementing Google OAuth in Streamlit | by Duc Anh Bui | Towards Data Science , I refactor it to simply use as pip.
Just do:
pip install git+https://github.com/hunkim/streamlit-google-oauth
Then add login code:
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")
That’s it.
Any comments, and contributions are welcome at GitHub - hunkim/streamlit-google-oauth: An example Streamlit application that incorporates Google OAuth 2.0 .
Actually, these buttons are ugly. Please feel free to send us PR.
14 Likes
Looks great
For some reason it lets every user in, not only the ones under “Test Users” (and the app is set to testing mode)
chan
June 30, 2023, 9:51pm
3
How can I save the user session state here?
Because as I reload the page I have to authenticate again.
Thanks!
Goyo
July 1, 2023, 6:31pm
4
This is how you maintain session state.
The Code is working fine in localhost. I really appreciate the work. But when I hosted it on streamlit cloud, I am getting the above. I have added the keys in secrets as well. Seems like it’s the issue with GOOGLE_REDIRECT_URI key. Any suugestions please.
GitHub - Harisathwik/streamlitoauth is the link to code. Just few lines of code.
https://examonoaut.streamlit.app/ is the link. The App reads the email id and prints Welcome EMAIL_ID!
Did you change the GOOGLE_REDIRECT_URI in both your code as well as your google cloud API console?
I have the same issue.
It seems that REDIRECT open a new streamlit session and hence clears the previous session’s variables.
Did u arrive at workaround?
Yahia
chan
August 21, 2023, 11:44am
10
I used cookies to maintain user session even if he reloads the website or visit it after a day
Use this library to integrate google auth in your application
import streamlit as st
from google_auth import Google_auth
client_id = “hasjh5jk498ufiu3h89g8-aghdszjhk3k.apps.googleusercontent.com ”
client_secret = “afsghfbkhfdjdsgfdjhfjkfhjkfhkjhkjdhks”
login = Google_auth(clientId=client_id, clientSecret=client_secret)
if login == “authenticated”:
# your streamlit applciation
pass
else:
st.warning(“login failed”)
1 Like
use this imports
from google_auth.google_auth import GoogleAuth
john12
October 4, 2024, 8:02am
14
found any workaround/fix for this?
system
Closed
October 4, 2025, 8:03am
15
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.