| | """https://chatgpt.com/share/131b6bdf-373e-4b85-83ae-212ce368e42c""" |
| |
|
| | import streamlit as st |
| | from auth0.authentication import GetToken, Users |
| | import os |
| |
|
| | |
| | DOMAIN = os.getenv("AUTH0_DOMAIN") |
| | CLIENT_ID = os.getenv("AUTH0_CLIENT_ID") |
| | CLIENT_SECRET = os.getenv("AUTH0_CLIENT_SECRET") |
| | API_IDENTIFIER = os.getenv("API_IDENTIFIER") |
| | REDIRECT_URI = ( |
| | "https://huggingface.co/spaces/AccelerationConsortium/hardware-auth-example" |
| | ) |
| |
|
| |
|
| | |
| | def login(): |
| | login_url = ( |
| | f"https://{DOMAIN}/authorize?response_type=code&client_id={CLIENT_ID}" |
| | f"&redirect_uri={REDIRECT_URI}&scope=openid%20profile%20email&audience={API_IDENTIFIER}" |
| | ) |
| | st.markdown(f"[Login]({login_url})", unsafe_allow_html=True) |
| |
|
| |
|
| | |
| | def get_token(auth_code): |
| | get_token = GetToken(DOMAIN) |
| | return get_token.authorization_code( |
| | CLIENT_ID, CLIENT_SECRET, auth_code, REDIRECT_URI |
| | ) |
| |
|
| |
|
| | |
| | def get_user_info(access_token): |
| | users = Users(DOMAIN) |
| | return users.userinfo(access_token) |
| |
|
| |
|
| | |
| | st.title("Streamlit App with Auth0 for HiveMQ") |
| |
|
| | if "auth_code" not in st.session_state: |
| | st.session_state.auth_code = None |
| |
|
| | if st.session_state.auth_code: |
| | token_info = get_token(st.session_state.auth_code) |
| | access_token = token_info["access_token"] |
| |
|
| | user_info = get_user_info(access_token) |
| | if user_info["email_verified"]: |
| | st.write("Access Token for HiveMQ:", access_token) |
| | else: |
| | st.error("Please verify your email address to receive the token.") |
| | else: |
| | if st.button("Login"): |
| | login() |
| |
|
| | |
| | if "code" in st.query_params: |
| | st.session_state.auth_code = st.query_params["code"][0] |
| |
|