Simple OAuth2 authorization code flow for Streamlit
Project description
🔐 Streamlit OAuth
A simple wrap for oauth2 authorization code grant flow using httpx_oauth
Installation
pip install streamlit-oauth
Getting started
Set your callback url to https://<YOUR ADDRESS>/component/streamlit_oauth.authorize_button/index.html
import streamlit as st
from dotenv import load_dotenv
load_dotenv()
AUTHORIZATION_URL = os.environ.get("AUTHORIZATION_URL")
TOKEN_URL = os.environ.get("TOKEN_URL")
REVOKE_URL = os.environ.get("REVOKE_URL")
CLIENT_ID = os.environ.get("CLIENT_ID")
CLIENT_SECRET = os.environ.get("CLIENT_SECRET")
REDIRECT_URI = os.environ.get("REDIRECT_URI")
SCOPE = os.environ.get("SCOPE")
oauth2 = OAuth2Component(CLIENT_ID, CLIENT_SECRET, AUTHORIZATION_URL, TOKEN_URL, TOKEN_URL, REVOKE_URL)
if 'token' not in st.session_state:
result = oauth2.authorize_button("🔗 Authorize", REDIRECT_URI, SCOPE)
if result:
st.session_state.token = result.get('token')
st.experimental_rerun()
else:
token = st.session_state['token']
st.json(token)
if st.button("♻️ Refresh Token"):
token = oauth2.refresh_token(token)
st.session_state.token = token
st.experimental_rerun()
Demo
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
streamlit-oauth-0.0.1.tar.gz
(62.6 kB
view hashes)
Built Distribution
Close
Hashes for streamlit_oauth-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e573866da39d2cb9f3420700bbf9a974c7ef5e402f60005406270bb79a8019e |
|
MD5 | dac18de07a63f083c1a80cdefb1b9dcb |
|
BLAKE2b-256 | dec1ddddecbe9fe54fceeb3bb2bf931f9ea7675c14164b9a780ad7d4cec95e5e |