Validate the Access token with FastAPI
This tutorial covers how to validate that the Access JWT is on requests made to FastAPI apps.
Time to complete: 15 minutes
Prerequisites
- A self-hosted Access application for your FastAPI app
- The AUD tag for your Access application
1. Create a validation function
- In your FastAPI project, create a new file called
cloudflare.pythat contains the following code:
2. Use the validation function in your app
You can now add the validation function as a dependency in your FastAPI app. One way to do this is by creating an
APIRouter instance
. The following example executes the validation function on each request made to paths that start with /admin: