Skip to content

Instantly share code, notes, and snippets.

@CognitiveDave
Created February 13, 2022 14:16
Show Gist options
  • Save CognitiveDave/2a14f4cf7e16f0deac171b8f4f74a239 to your computer and use it in GitHub Desktop.
Save CognitiveDave/2a14f4cf7e16f0deac171b8f4f74a239 to your computer and use it in GitHub Desktop.
A secure FastApi endpoint
@app.get("/api/private")
async def private(response: Response, token: str = Depends(token_auth_scheme)): # 👈 updated code
"""A valid access token is required to access this route"""
result = VerifyToken(token.credentials).verify()
if result.get("status"):
response.status_code = status.HTTP_400_BAD_REQUEST
return result
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment