From abcd7cf54fa1cf321bf2d7aec9ef14e71119679b Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 23 Dec 2023 15:30:05 +0530 Subject: [PATCH] build(auth.py): adding email / magic link based login for proxy ui --- ui/README.md | 6 ++++++ ui/app.py | 35 +++++++++++++++++++++++++++++++++++ ui/auth.py | 39 +++++++++++++++++++++++++++++++++++++++ ui/requirements.txt | 2 ++ 4 files changed, 82 insertions(+) create mode 100644 ui/README.md create mode 100644 ui/app.py create mode 100644 ui/auth.py create mode 100644 ui/requirements.txt diff --git a/ui/README.md b/ui/README.md new file mode 100644 index 000000000..6857a304a --- /dev/null +++ b/ui/README.md @@ -0,0 +1,6 @@ +# proxy ui + +A simple UI to manage the litellm proxy. + +This just lets users create new keys for the proxy, through a ui. + diff --git a/ui/app.py b/ui/app.py new file mode 100644 index 000000000..3cdd5dad8 --- /dev/null +++ b/ui/app.py @@ -0,0 +1,35 @@ +import streamlit as st +import urllib.parse + +def generate_key(name, description): + # Code to generate and return a key goes here + return "Generated Key" + + +def main(api_base, url_hash): + st.title("Key Request") + + # Create input fields for key name and description + name = st.text_input("Key Name") + description = st.text_area("Key Description") + + # Create a button to request the key + if st.button("Request Key"): + if name and description: + key = generate_key(name, description) + st.success(f"Your key: {key}") + else: + st.error("Please enter a valid key name and description.") + + +if __name__ == "__main__": + # Get the proxy URL and hash from the admin + proxy_url = st.text_input("Admin Proxy URL") + hash_input = st.text_input("URL Hash") + + # Generate the public URL with hash + encoded_hash = urllib.parse.quote(hash_input.strip()) if hash_input else "" + public_url = f"{proxy_url}/{encoded_hash}" + + # Run the Streamlit app + main(proxy_url, hash_input) \ No newline at end of file diff --git a/ui/auth.py b/ui/auth.py new file mode 100644 index 000000000..dff665963 --- /dev/null +++ b/ui/auth.py @@ -0,0 +1,39 @@ +""" +Auth in user, to proxy ui. + +Uses supabase passwordless auth: https://supabase.com/docs/reference/python/auth-signinwithotp + +Remember to set your redirect url to 8501 (streamlit default). +""" +import streamlit as st +from dotenv import load_dotenv +load_dotenv() +import os +from supabase import create_client, Client + +# Set up Supabase client +url: str = os.environ.get("SUPABASE_URL") +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}) + # Redirect to Supabase UI with the return data + st.write(f"Please check your email for a login link!") + + +# Create the Streamlit app +def main(): + st.title("User Authentication") + + # User email input + email = st.text_input("Enter your email") + + # Sign in button + if st.button("Sign In"): + sign_in_with_otp(email) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/ui/requirements.txt b/ui/requirements.txt new file mode 100644 index 000000000..18b689b0a --- /dev/null +++ b/ui/requirements.txt @@ -0,0 +1,2 @@ +python-dotenv +supabase \ No newline at end of file