Download auth.py from dashgaming/slyte: direct link, hf CLI and curl.
- Browser
- Download file 967 Bytes
-
https://huggingface.co/dashgaming/slyte/resolve/main/auth.py
- Command line
-
hf download hf://dashgaming/slyte/auth.py
-
curl -L -o auth.py https://huggingface.co/dashgaming/slyte/resolve/main/auth.py
967 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 | |