This is a prototype for authentication in Streamlit. It supports all OIDC providers (e.g., Google, Microsoft etc.).
git clone https://github.com/kajarenc/stauthlib
pip install -r requirements.txt
. Note that this will install a custom Streamlit wheel from this PR.streamlit run app.py
ngrok http 8501 --domain <your-static-ngrok-url>
. Insert the static ngrok URL you created while signing up for ngrok. You can now go to this URL in your browser and check that you can access your local app through it.<your-static-ngrok-url>/oauth2callback
.<your-static-ngrok-url>/oauth2callback
), client ID, and client secret to .streamlit/secrets.toml
. You can remove the code for providers you don't use.With the wheel file in this repo, you can use the following commands in your Python code:
st.experimental_user
shows you information about the user when logged in (e.g., their email, name, and avatar image). This information comes from the OAuth provider.st.experimental_user.login(provider="google")
will send the user to the OAuth provider and let them log in. After login, they will be redirected to the app. Note that a user can only be signed in with one provider at a time, i.e. logging in with a different provider will log them out of the previous one.st.experimental_user.logout()
will log out a signed-in user.See app.py for a full example of how to use this code.