Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from google.oauth2 import service_account
|
3 |
+
from google.auth.transport.requests import Request
|
4 |
+
from google_auth_oauthlib.flow import Flow
|
5 |
+
import os
|
6 |
+
|
7 |
+
# Define your Google OAuth credentials
|
8 |
+
CLIENT_SECRET_FILE = 'client_secret.json'
|
9 |
+
SCOPES = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email']
|
10 |
+
REDIRECT_URI = 'https://huggingface.co/spaces/blazingbunny/galerts/'
|
11 |
+
PORT = 8081
|
12 |
+
|
13 |
+
# Function to create Google OAuth Flow object
|
14 |
+
def create_flow():
|
15 |
+
return Flow.from_client_secrets_file(
|
16 |
+
CLIENT_SECRET_FILE,
|
17 |
+
scopes=SCOPES,
|
18 |
+
redirect_uri=REDIRECT_URI
|
19 |
+
)
|
20 |
+
|
21 |
+
# Function to generate Google Sign-In URL
|
22 |
+
def generate_auth_url(flow):
|
23 |
+
return flow.authorization_url(
|
24 |
+
access_type='offline',
|
25 |
+
include_granted_scopes='true'
|
26 |
+
)[0]
|
27 |
+
|
28 |
+
# Function to authenticate user with Google
|
29 |
+
def authenticate_user():
|
30 |
+
flow = create_flow()
|
31 |
+
auth_url = generate_auth_url(flow)
|
32 |
+
st.write(f"[Click here to sign in with Google]({auth_url})")
|
33 |
+
|
34 |
+
# Main function to run the Streamlit app
|
35 |
+
def main():
|
36 |
+
st.title("Google Sign-In with Streamlit")
|
37 |
+
authenticate_user()
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
main()
|