Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add auth0 #85

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ streamlit==1.17.0
testcontainers==3.2.0
uvicorn==0.17.6
geopandas==0.11.1
garrett-streamlit-auth0==0.9

45 changes: 23 additions & 22 deletions src/auth.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import os
import streamlit as st
import ssl
from auth0_component import login_button

clientId = os.getenv("AUTH0_CLIENT_ID")
domain = os.getenv("AUTH0_DOMAIN")

# need this for the login to work
ssl._create_default_https_context = ssl._create_unverified_context


def check_password():
"""Returns `True` if the user had the correct password."""

def password_entered():
"""Checks whether a password entered by the user is correct."""
if st.session_state["password"] == st.secrets["password"]:
st.session_state["password_correct"] = True
del st.session_state["password"] # don't store password
else:
st.session_state["password_correct"] = False

if "password_correct" not in st.session_state:
# First run, show input for password.
st.text_input(
"Password", type="password", on_change=password_entered, key="password", autocomplete="current-password"
)
with st.sidebar:
user_info = login_button(clientId=clientId, domain=domain,debug_logs=True)

if user_info is None:
st.text('No user info')
return False
elif not st.session_state["password_correct"]:
# Password not correct, show input + error.
st.text_input(
"Password", type="password", on_change=password_entered, key="password", autocomplete="current-password"
)
st.error("😕 Password incorrect")

if not user_info:
st.text('Please log in')
return False
else:
# Password correct.
return True

if '@openclimatefix.' not in user_info['email']:
st.text('This is only available to OCF members')
return False

return user_info