# OAuth component for Streamlit

**URL:** <https://discuss.streamlit.io/t/oauth-component-for-streamlit/40883>\
**Category:** Custom Components\
**Tags:** authentication\
**Created:** [April 6, 2023, 7:45pm UTC](https://discuss.streamlit.io/t/oauth-component-for-streamlit/40883 "2023-04-06T19:45:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianmhess](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/brianmhess/32/18049_2.png) [@brianmhess](https://discuss.streamlit.io/u/brianmhess)\
**Post date:** [April 6, 2023, 7:45pm UTC](https://discuss.streamlit.io/t/oauth-component-for-streamlit/40883/1 "2023-04-06T19:45:11Z")

</div>

Hello all 👋  
I created a Python-only component that handles OAuth authentication to Streamlit apps. The component will “gate” your app until the user successfully authenticates with the OAuth provider. It’s as simple as:

```auto
import streamlit as st
from st_oauth import st_oauth

st.markdown("## This (and above) is always seen")
id = st_oauth('myoauth', 'Click to login via OAuth')
st.markdown("## This (and below) is only seen after authentication")

```

It supports multi-page apps and query parameters, as well!  
I also wrote a brief blog post on how to use it: [OAuth Component for Streamlit. One of the common requests I get when… | by Brian Hess | Streamlit | Apr, 2023 | Medium](https://medium.com/streamlit/oauth-component-for-streamlit-e05f00874fbc)

Check out the GitHub repo here: [GitHub - sfc-gh-bhess/st\_oauth: OAuth component for Streamlit](https://github.com/sfc-gh-bhess/st_oauth)

---

<div class="post-metadata">

**Author:** ![Sandipayan\_Nandi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/sandipayan_nandi/32/29521_2.png) [@Sandipayan\_Nandi](https://discuss.streamlit.io/u/Sandipayan_Nandi)\
**Post date:** [July 20, 2023, 6:52pm UTC](https://discuss.streamlit.io/t/oauth-component-for-streamlit/40883/2 "2023-07-20T18:52:29Z")

</div>

Hi @brianmhess , thanks for making this - very helpful ! For me somehow after I first time login to Okta from the app, it lands to the Okta admin dashboard instead of redirecting to the application as mentioned in redirect\_uri as mentioned in secrets.toml or sign-in redirect APIs as configured in Okta (which is: [http://localhos:8080/sample\_app](http://localhos:8080/sample_app) in both cases).

Next time in the same browser I open [http://localhos:8080/sample\_app](http://localhos:8080/sample_app), it correctly logs me in via okta as the token is there in browser. I am not sure why after first time login it does not redirect me to the redirect\_uri … any idea?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [January 16, 2024, 6:53pm UTC](https://discuss.streamlit.io/t/oauth-component-for-streamlit/40883/3 "2024-01-16T18:53:29Z")

</div>

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