| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/cloudflare-one/access-controls/policies/external-evaluation/ | [Back] [Original] |
With Cloudflare Access, you can create Allow or Block policies which evaluate the user based on custom criteria. This is done by adding an External Evaluation rule to your policy. The External Evaluation selector requires two values:
After the user authenticates with your identity provider, Access sends the user's identity to the external API at Evaluate URL. The external API returns a True or False response to Access, which will then allow or deny access to the user. To protect against man-in-the-middle attacks, Access signs all requests with your Access account key and checks that responses are signed by the key at Keys URL.
You can set up External Evaluation rules using any API service, but to get started quickly we recommend using Cloudflare Workers.
Open a terminal and clone our example project.
npm create cloudflare@latest my-worker -- --template https://github.com/cloudflare/workers-access-external-auth-example
Go to the project directory.
cd my-worker
Create a Workers KV namespace to store the key. The binding name should be KV if you want to run the example as written.
npx wrangler kv namespace create "KV"
The command will output the binding name and KV namespace ID, for example
[[kv_namespaces]]
binding = "KV"
id = "YOUR_KV_NAMESPACE_ID"
Open the Wrangler configuration file in an editor and insert the following:
[[kv_namespaces]]: Add the output generated in the previous step.<TEAM_NAME>: your Cloudflare One team name.{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "my-worker",
"workers_dev": true,
// Set this to today's date
"compatibility_date": "2026-08-19",
"main": "index.js",
"kv_namespaces": [
{
"binding": "KV",
"id": "YOUR_KV_NAMESPACE_ID"
}
],
"vars": {
"TEAM_DOMAIN": "<TEAM_NAME>.cloudflareaccess.com",
"DEBUG": false
}
}"$schema" = "./node_modules/wrangler/config-schema.json"
name = "my-worker"
workers_dev = true
# Set this to today's date
compatibility_date = "2026-08-19"
main = "index.js"
[[kv_namespaces]]
binding = "KV"
id = "YOUR_KV_NAMESPACE_ID"
[vars]
TEAM_DOMAIN = "<TEAM_NAME>.cloudflareaccess.com"
DEBUG = falseindex.js and modify the externalEvaluation function to perform logic on any identity-based data sent by Access.Note
/cdn-cgi/access/get-identity to the URL. For example, if www.example.com is behind Access, visit https://www.example.com/cdn-cgi/access/get-identity.Deploy the Worker to Cloudflare's global network.
npx wrangler deploy
The Worker will be deployed to your *.workers.dev subdomain at my-worker.<YOUR_SUBDOMAIN>.workers.dev.
To generate an RSA private/public key pair:
Open a browser and go to https://my-worker.<YOUR_SUBDOMAIN>.workers.dev/keys.
(Optional) Verify that the key has been stored in the KV namespace:
my-worker-KV.Other key formats (such as DSA) are not supported at this time.
In the Cloudflare dashboard , go to Zero Trust > Access controls > Policies.
Edit an existing policy or select Add a policy.
Add the following rule to your policy:
| Rule Type | Selector | Evaluate URL | Keys URL |
|---|---|---|---|
| Include | External Evaluation | https://my-worker.<YOUR_SUBDOMAIN>.workers.dev/ |
https://my-worker.<YOUR_SUBDOMAIN>.workers.dev/keys/ |
Save the policy.
Go to Access controls > Applications and edit the application for which you want to apply the External Evaluation rule.
In the Policies tab, add the policy that contains the External Evaluation rule.
Select Save.
When a user logs in to your application, Access will now check their email, device, location, and other identity-based data against your business logic.
To debug your External Evaluation rule:
Go to your Worker directory.
cd my-worker
Open the Wrangler configuration file in an editor and set the debug variable to TRUE.
Deploy your changes.
npx wrangler deploy
Next, start a session to output realtime logs from your Worker.
wrangler tail -f pretty
Log in to your Access application.
The session logs should show an incoming and outgoing JWT. The incoming JWT was sent by Access to the Worker API, while the outgoing JWT was sent by the Worker back to Access.
To decode the contents of a JWT, you can copy the token into jwt.io .
The incoming JWT should contain the user's identity data. The outgoing JWT should look similar to:
{
"success": true,
"iat": 1655409315,
"exp": 1655409375,
"nonce": "9J2E9Xg6wYj8tlnA5MV4Zgp6t8rzmS0Q"
}
Access checks the outgoing JWT for all of the following criteria:
"success": true.nonce is unchanged from the incoming JWT. The nonce value is unique per request.If any condition fails, the External Evaluation rule evaluates to false.
| Web Proxy Viewer | New URL | Original Page |