New Component: streamlit-oauth

Hi

For now, you can share the authentication state across pages using session_state.

The functionality to use cookies or local storage is planned to be added in the future.

Hi @dnplus,
Thanks for this great library.
Is there any way to retrieve the email address and/or username of the authenticated user?

Have a look on this example.

Can anyone help with GitHub auth please?

Thank you so much, this was exactly what I was looking for. Couldn’t figure out the button + url and you provide that!

Thank you @dnplus for such a helpful component.
I am able to easily integrate it … I am however looking for some guidance here.
After authentication, I would like to use the user to create google slides programmatically using his account… not sure how to use the response from oauth2.authorize_button() to a credential in service = build(‘slides’, ‘v1’, credentials=). the credential is of type oauth2client.Credentials or google.auth.credentials.Credentials, credentials to be used for authentication.

Any suggestion would really help… Truly appreciate…

refer to google.auth.credentials module — google-auth 1.30.0 documentation

Seems like it is a class to represent the token response.

I think you can fill the necessary parameters from oauth2.authorize_button() into that class to create an object to use it

Thank you @dnplus for that reply… One more question… how can we provide more scopes? seems you are loading dotenv which has scope variable defined: SCOPE = os.environ.get(“SCOPE”) and then use it like:
scope=“openid email profile”
If I want to add more scopes, how I can do so? is it possible to share the env file without the sensitive information.

It just an example, you can define scope directly and pass when calling authorize_button

oauth2.authorize_button("authorize", redirect_uri, "email openid") # split each scope with space

hi, Do you have an example of using cookies to store the state? can you please point to the example? The issue I have is that page refresh triggers fresh login and session_state is lost

You can use streamlit-cookies-controller · PyPI to save the session state.

Hi @dnplus,

I have code that looks like this for Oauth with pingID:


oauth2 = #initalized_correctly
# from your github
if 'token' not in st.session_state:
    result = oauth2.authorize_button(name="SSO", redirect_uri=os.environ['REDIRECT_URL'], scope=os.environ['SCOPE'], use_container_width=True, auto_click=True,  extras_params={'response_type': 'code'})
    if result and 'token' in result:
        st.session_state.token = result.get('token')
        st.rerun()
else:
        render_webpage() 

but I get the following error signature starting with:
site-packages/streamlit_oauth/init.py", line xyz, in authorize_button
result[‘token’] = asyncio.run(self.client.get_access_token(**args))

Also the auto_click does not work

what’s the full error message?

And how you make sure the oauth2 object initialized correctly?

Enable CORS in your oauth provider. For example in Okta: Enable CORS in API → SECURITY → Trusted Origins

Hey all! Just wanted to mention here that with 1.42, we recently launched a native authentication feature in Streamlit! :partying_face: This let’s you add auth via OIDC/OAuth2 (e.g. “Login with Google”) to your app. Check out the docs here: User authentication and information - Streamlit Docs

@dnplus This is a great module—thank you for putting it together! It’s working as expected for me. I do have a quick question though: is it possible to capture the user’s email address during the identification process?

Thanks

Thanks! Glad to hear it’s working well for you.

Regarding your question:
In theory, accessing the popup’s content from a parent window would violate browser security policies if they are on different origins, so it wouldn’t be feasible in that case.

Hi,

Can we remove the “Authorize” button during Okta authentication and directly call the application?

I tried using the following approach:
result = oauth2.authorize (config.REDIRECT_URI,
config.SCOPE,
pkce=‘S256’
)
However, I encountered the following error: AttributeError: ‘OAuth2Component’ object has no attribute ‘authorize’
We are currently using streamlit-oauth==0.1.14.
Could you please help resolve this issue?