The Cloudflare Access Pages Plugin is a middleware to validate Cloudflare Access JWT assertions. It also includes an API to lookup additional information about a given user’s JWT.
Installation
Usage
The Plugin takes an object with two properties: the domain of your Cloudflare Access account, and the policy aud (audience) to validate against. Any requests which fail validation will be returned a 403 status code.
Access the JWT payload
If you need to use the JWT payload in your application (for example, you need the user’s email address), this Plugin will make this available for you at data.cloudflareAccess.JWT.payload.
For example:
The entire JWT payload will be made available on data.cloudflareAccess.JWT.payload. Be aware that the fields available differ between identity authorizations (for example, a user in a browser) and non-identity authorizations (for example, a service token).
Look up identity
In order to get more information about a given user’s identity, use the provided getIdentity API function:
The getIdentity function takes an object with two properties: a jwt string, and a domain string. It returns a Promise of the object returned by the /cdn-cgi/access/get-identity endpoint. This is particularly useful if you want to use a user’s group membership for something like application permissions.
For convenience, this same information can be fetched for the current request’s JWT with the data.cloudflareAccess.JWT.getIdentity function, (assuming you have already validated the request with the Plugin as above):
Login and logout URLs
If you want to force a login or logout, use these utility functions to generate URLs and redirect a user: