Download dependencies.py from testser2/mzlessons: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/testser2/mzlessons/resolve/main/dependencies.py
- Command line
-
hf download hf://spaces/testser2/mzlessons/dependencies.py
-
curl -L -o dependencies.py https://huggingface.co/spaces/testser2/mzlessons/resolve/main/dependencies.py
1.05 kB
| from fastapi import Header, HTTPException, Depends | |
| from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials | |
| from jose import jwt | |
| from typing import Optional | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| JWT_SECRET = os.getenv("SUPABASE_JWT_SECRET") | |
| security = HTTPBearer() | |
| async def verify_jwt_token(credentials: HTTPAuthorizationCredentials = Depends(security)): | |
| try: | |
| token = credentials.credentials | |
| # Verify the JWT token using your Supabase public key | |
| # You can get the JWT secret from your Supabase dashboard | |
| payload = jwt.decode( | |
| token, | |
| JWT_SECRET, | |
| algorithms=["HS256"], | |
| audience="authenticated" | |
| ) | |
| return payload | |
| except jwt.ExpiredSignatureError: | |
| raise HTTPException( | |
| status_code=401, | |
| detail="Token has expired" | |
| ) | |
| except jwt.JWTError: | |
| raise HTTPException( | |
| status_code=401, | |
| detail="Invalid token" | |
| ) | |