Created
February 13, 2022 14:16
-
-
Save CognitiveDave/2a14f4cf7e16f0deac171b8f4f74a239 to your computer and use it in GitHub Desktop.
A secure FastApi endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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