Google Sign in

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[“*****”]

CLIENT_SECRET = os.environ[“*****”]

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 = ***

CLIENT_SECRET = ***

REDIRECT_URI = “http://localhost:8501

======
Output is like

Hi there,

Thanks for sharing your question with the community! Check out our guidelines on how to post an effective question here – in particular, please format your code properly so the community can read it and make suggestions

Caroline :balloon:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.