Dependency to extract and verify JWT token from Authorization header Usage: - Include this as a dependency in route functions - The JWT payload will be passed to the route function
(authorization: str = Header(None))
| 94 | |
| 95 | |
| 96 | async def get_jwt_token(authorization: str = Header(None)) -> JWTPayload: |
| 97 | """ |
| 98 | Dependency to extract and verify JWT token from Authorization header |
| 99 | |
| 100 | Usage: |
| 101 | - Include this as a dependency in route functions |
| 102 | - The JWT payload will be passed to the route function |
| 103 | """ |
| 104 | if not authorization: |
| 105 | raise HTTPException(status_code=401, detail="Authorization header missing") |
| 106 | |
| 107 | try: |
| 108 | # Extract token from "Bearer <token>" format |
| 109 | scheme, token = authorization.split() |
| 110 | if scheme.lower() != "bearer": |
| 111 | raise HTTPException(status_code=401, detail="Invalid authentication scheme") |
| 112 | |
| 113 | return verify_jwt(token) |
| 114 | except ValueError: |
| 115 | raise HTTPException(status_code=401, detail="Invalid token format") |
| 116 | except jwt.ExpiredSignatureError: |
| 117 | raise HTTPException(status_code=401, detail="Token has expired") |
| 118 | except jwt.InvalidAudienceError: |
| 119 | raise HTTPException(status_code=401, detail="Invalid audience") |
| 120 | except jwt.InvalidTokenError: |
| 121 | raise HTTPException(status_code=401, detail="Invalid token") |
| 122 | |
| 123 | |
| 124 | def generate_dev_token(project_id: str) -> str: |
searching dependent graphs…