slyte / auth.py
DASH Gaming
Deploy app_hf.py to Hugging Face Spaces as Streamlit app
bdf7308
Raw History Blame Contribute Delete
928 Bytes
import streamlit as st
from firebase_admin import auth
def verify_user_from_query():
"""
Retrieves Firebase ID token from URL parameter 'token',
verifies it with Firebase Admin SDK.
Returns:
uid (str): The verified User ID.
Raises:
ValueError: If token is missing.
auth.ExpiredIdTokenError: If token is expired.
auth.InvalidIdTokenError: If token is invalid.
Exception: For other errors.
"""
token = st.query_params.get("token")
if not token:
raise ValueError("No token found in query parameters.")
try:
# Verify the ID token
decoded_token = auth.verify_id_token(token)
uid = decoded_token['uid']
return uid
except auth.ExpiredIdTokenError:
raise
except auth.InvalidIdTokenError:
raise
except Exception as e:
raise e