Cloudflare Enablement
Cloudflare Zero Trust
Testing
Edit this page on GitHub
Set theme to dark (⇧+D)

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

​​ 1. Create a validation function

  1. In your FastAPI project, create a new file called cloudflare.py that 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: