File size: 1,050 Bytes
e1d0e4b
 
 
01af3f9
e1d0e4b
 
 
01af3f9
e1d0e4b
01af3f9
 
 
e1d0e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01af3f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
from google.oauth2 import service_account
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_secrets_file(
        client_secret,
        scopes=['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'],
        redirect_uri='https://huggingface.co/spaces/blazingbunny/galerts: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()