forked from phoenix/litellm-mirror
build(auth.py): send redirect url via magic link
This commit is contained in:
parent
1bfab87323
commit
189fcc0934
3 changed files with 18 additions and 8 deletions
|
@ -1,11 +1,13 @@
|
|||
"""
|
||||
Admin sets proxy url + allowed email subdomain
|
||||
"""
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
import streamlit as st
|
||||
import base64
|
||||
import base64, os
|
||||
|
||||
# Replace your_base_url with the actual URL where the proxy auth app is hosted
|
||||
your_base_url = 'http://localhost:8501' # Example base URL
|
||||
your_base_url = os.getenv("BASE_URL") # Example base URL
|
||||
|
||||
# Function to encode the configuration
|
||||
def encode_config(proxy_url, allowed_email_subdomain):
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"""
|
||||
Routes between admin, auth, keys pages
|
||||
"""
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
import streamlit as st
|
||||
import base64, binascii
|
||||
import base64, binascii, os
|
||||
from admin import admin_page
|
||||
from auth import auth_page
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
|
@ -44,7 +46,7 @@ if page_param:
|
|||
try:
|
||||
# Try to decode the page_param from base64
|
||||
if is_base64(page_param):
|
||||
auth_page()
|
||||
auth_page(redirect_url=f"{os.getenv('BASE_URL')}/{page_param}")
|
||||
else:
|
||||
st.error("Unknown page")
|
||||
except Exception as e:
|
||||
|
|
14
ui/auth.py
14
ui/auth.py
|
@ -5,6 +5,8 @@ Uses supabase passwordless auth: https://supabase.com/docs/reference/python/auth
|
|||
|
||||
Remember to set your redirect url to 8501 (streamlit default).
|
||||
"""
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
import streamlit as st
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
@ -17,14 +19,18 @@ key: str = os.environ.get("SUPABASE_KEY")
|
|||
supabase: Client = create_client(url, key)
|
||||
|
||||
|
||||
def sign_in_with_otp(email: str):
|
||||
data = supabase.auth.sign_in_with_otp({"email": email})
|
||||
def sign_in_with_otp(email: str, redirect_url: str):
|
||||
data = supabase.auth.sign_in_with_otp({"email": email,
|
||||
"options": {
|
||||
"email_redirect_to": redirect_url
|
||||
}})
|
||||
print(f"data: {data}")
|
||||
# Redirect to Supabase UI with the return data
|
||||
st.write(f"Please check your email for a login link!")
|
||||
|
||||
|
||||
# Create the Streamlit app
|
||||
def auth_page():
|
||||
def auth_page(redirect_url: str):
|
||||
st.title("User Authentication")
|
||||
|
||||
# User email input
|
||||
|
@ -32,4 +38,4 @@ def auth_page():
|
|||
|
||||
# Sign in button
|
||||
if st.button("Sign In"):
|
||||
sign_in_with_otp(email)
|
||||
sign_in_with_otp(email, redirect_url=redirect_url)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue