File size: 1,006 Bytes
e1d0e4b
f51c203
01af3f9
e1d0e4b
 
 
01af3f9
f51c203
 
01af3f9
f51c203
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
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()