Skip to content

Instantly share code, notes, and snippets.

@Khahory
Created November 21, 2023 00:42
Show Gist options
  • Save Khahory/5c4f0981c8e7481e8d15dd245ddfc2c7 to your computer and use it in GitHub Desktop.
Save Khahory/5c4f0981c8e7481e8d15dd245ddfc2c7 to your computer and use it in GitHub Desktop.
from fastapi.routing import APIRoute
from fastapi import Request
from functions_jwt import validate_token
class VerifyTokenRoute(APIRoute):
def get_route_handler(self):
original_route_handler = super().get_route_handler()
async def verify_token_middleware(request: Request):
token = request.headers.get("Authorization", None)
if token:
token = token.split(" ")[1]
token = validate_token(token)
if token:
return token
return await original_route_handler(request)
return verify_token_middleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment