galerts / app.py
blazingbunny's picture
Update app.py
f51c203 verified
import streamlit as st
from google.auth_oauthlib.flow import Flow
import json
# Function to create Google OAuth Flow object
def create_flow():
client_secret = st.secrets["client_secret"]
return Flow.from_client_config(
json.loads(client_secret),
scopes=['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'],
redirect_uri='https://huggingface.co/spaces/blazingbunny:8501'
)
# Function to generate Google Sign-In URL
def generate_auth_url(flow):
return flow.authorization_url(
access_type='offline',
include_granted_scopes='true'
)[0]
# Function to authenticate user with Google
def authenticate_user():
flow = create_flow()
auth_url = generate_auth_url(flow)
st.write(f"[Click here to sign in with Google]({auth_url})")
# Main function to run the Streamlit app
def main():
st.title("Google Sign-In with Streamlit")
authenticate_user()
if __name__ == "__main__":
main()