Hello Everyone!!
Hope that all are doing well. I am extremely new at streamlit.
Now I am trying to google authenticate. That means I have a button, whenever I click this button, It will require google authentication, which means the user will give the proper email address and password.
This is my (main.py) file’s code:
import streamlit as st
from auth import *
st.title(“Google Login”)
st.button(“Sign in with Google”)
result=st.write(get_login_str(),unsafe_allow_html=True)
print(result)
This is my (auth.py) file:
================================
import os
from numpy import void
import streamlit as st
import asyncio
OAuth2 - HTTPX OAuth
from httpx_oauth.clients.google import GoogleOAuth2
from dotenv import load_dotenv
load_dotenv(‘.env’)
CLIENT_ID = os.environ[“927176841255-jo801rj4vug8mnib7n1dpts10vrgug1j.apps.googleusercontent.com”]
CLIENT_SECRET = os.environ[“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”]
REDIRECT_URI = os.environ[‘http://localhost:8501/’]
async def get_authorization_url(client: GoogleOAuth2, redirect_uri: str):
authorization_url = await client.get_authorization_url(redirect_uri, scope=[“profile”, “email”])
return authorization_url
def get_login_str():
client: GoogleOAuth2 = GoogleOAuth2(CLIENT_ID, CLIENT_SECRET)
authorization_url = asyncio.run(
get_authorization_url(client, REDIRECT_URI))
return f’‘’ < a target = “_self” href = “{authorization_url}” > Google login < /a > ‘’’
This is my (.env) File
CLIENT_ID = 927176841255-jo801rj4vug8mnib7n1dpts10vrgug1j.apps.googleusercontent.com
CLIENT_SECRET = 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
REDIRECT_URI = “http://localhost:8501”
======
Output is like