Protect APIs on Apache APISIX with Choreo Identity & Access Management
This guide explains how to secure your APIs at the Apache APISIX gateway layer using tokens issued by Choreo Identity & Access Management. By retrieving public signing keys from the Choreo Identity & Access Management JWKS endpoint, APISIX cryptographically verifies every incoming token at the edge before forwarding authorized requests to your backend services.
The guide covers two core integration approaches available in Apache APISIX:
- Token Validation: Configure APISIX to validate incoming JWTs issued by Choreo Identity & Access Management using the OpenID Connect plugin, ensuring only authenticated requests access your APIs.
- Scope-Based Authorization: Leverage Choreo Identity & Access Management's RBAC capabilities to enforce strict, APISIX-driven access control policies on upstream APIs.
Prerequisites
- Access to a Choreo Identity & Access Management tenant.
- Docker is installed on your machine (required to run Apache APISIX).
curlis available in your terminal.
Configure JWT Token Validation in Apache APISIX
JWT authentication is the foundation of API security with Apache APISIX and Choreo Identity & Access Management. In this section, you register an application to obtain credentials, configure APISIX to validate tokens using the Choreo Identity & Access Management JWKS endpoint, and verify that unauthenticated requests are rejected.
Configure Choreo Identity & Access Management
Create an Application
- Sign in to the Choreo Identity & Access Management Console at https://console.cloud.choreolabs.com/iam/.
- Navigate to Applications → New Application.
- Enter an Application name (for example,
apisix-client). - Select Backend service as the application type.
- Click Create application.
- Note the Client ID and Client secret from the application details page.
Saving a change does not make it live. You author in the control plane, and your users sign in on a separate data plane, so a change takes effect in an environment only after you deploy it. Go to Deploy, deploy the latest version to your first environment, then promote it to the next environment when you are ready.
Auto-sync deploys saved changes to your first environment within seconds. Turning it on is your choice, per project. See Deploy a Version, or learn why you deploy and how auto-sync works.
Obtain an Access Token
Use the client credentials grant to request an access token:
curl -k -X POST 'https://<DATA_PLANE_URL>/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=<CLIENT_ID>' \
--data-urlencode 'client_secret=<CLIENT_SECRET>'
The response contains an access_token:
{
"access_token": "<ACCESS_TOKEN>",
"token_type": "Bearer",
"expires_in": 3600
}
The token is a JWT signed with RS256. Its iss claim is https://<DATA_PLANE_URL>, which matches the discovery URL you configure on the plugin. Copy the access_token value. You will use it to call the protected route.
Configure Apache APISIX
Start Apache APISIX
Run the APISIX quickstart script to start a local APISIX instance using Docker:
curl -sL https://run.api7.ai/apisix/quickstart | sh
Wait for the script to complete. APISIX starts with the Admin API on port 9180 and the proxy on port 9080.
Create a Route with JWT Validation
Create a route that requires a valid Choreo Identity & Access Management-issued JWT. The openid-connect plugin fetches the JWKS from Choreo Identity & Access Management's discovery document and validates every incoming bearer token against it.
curl -i 'http://127.0.0.1:9180/apisix/admin/routes' -X PUT -d '{
"id": "auth-with-thunderid",
"uri": "/anything/*",
"plugins": {
"openid-connect": {
"bearer_only": true,
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>",
"use_jwks": true,
"discovery": "https://<DATA_PLANE_URL>/.well-known/openid-configuration",
"ssl_verify": false
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'
With discovery set, the plugin fetches Choreo Identity & Access Management's JWKS and verifies each token's signature, issuer, and expiry. Setting bearer_only to true makes APISIX return 401 for requests without a valid token instead of redirecting to a sign-in page.
Try It Out
Request without a token, expect 401 Unauthorized:
curl -i 'http://127.0.0.1:9080/anything/test'
Request with a valid Choreo Identity & Access Management token, expect 200 OK:
export ACCESS_TOKEN="<ACCESS_TOKEN>"
curl -i 'http://127.0.0.1:9080/anything/test' \
-H "Authorization: Bearer $ACCESS_TOKEN"
A successful request returns an HTTP 200 response forwarded from the upstream. If the token is missing, invalid, or expired, APISIX returns 401 Unauthorized.
Configure Scope-Based Authorization in Apache APISIX
JWT validation confirms that a token is valid and was issued by Choreo Identity & Access Management. It does not control what the token holder is allowed to do. With the configuration from the previous section, APISIX accepts any valid Choreo Identity & Access Management token regardless of the application or its assigned permissions.
Scope-based authorization adds a second layer of control. Choreo Identity & Access Management embeds scopes in tokens based on the roles assigned to an application. APISIX then checks those scopes on every request and rejects tokens that do not carry the required permissions. To enforce that tokens carry specific permission scopes, configure the required_scopes parameter on the OpenID Connect plugin.
The steps below build on the JWT validation configuration from the previous section. You will define a Resource Server, a Resource, and actions in Choreo Identity & Access Management to model your API permissions. Then bundle them into a role, assign the role to your application, and update the APISIX route to enforce scope validation.
Configure Choreo Identity & Access Management
Create a Resource Server
A Resource Server represents your API in Choreo Identity & Access Management. It groups the resources and actions that model your API, and exposes a permission (scope) for each action.
- In the Console, navigate to Resource servers → Add resource server.
- For the type, select API.
- Enter a Resource server name (for example,
HTTPBin API) and an Identifier (for example,https://httpbin.example.com). - For the Permission delimiter, select
:. - Select the Organization the resource server belongs to, then create it.
Add Resources and Actions
A Resource represents an entity within the API, and Actions define the operations allowed on it. Each action produces a scope in the format <resource-handle>:<action-handle>.
- Open the resource server you just created and go to the Resources & actions tab.
- Click Add resource and enter a Name (for example,
Headers) and a Handle (headers). - Under that resource, click Add action and enter a Name (for example,
Read Headers) and a Handle (read).
This produces the permission headers:read, which Choreo Identity & Access Management includes in tokens issued to applications that hold a role granting it.
Create a Role and Assign Permission
Roles bundle one or more permissions together. Assigning a role to an application controls which scopes appear in its tokens.
- Navigate to Roles → Add role.
- Enter a Role name (for example,
Headers reader). - Click Continue.
- Under Assign permissions, choose
headers:read. - Click Continue.
Assign the Role to the Application
Assign the role to the application you created in the previous section. Choreo Identity & Access Management includes the role's scopes in every token issued for that application.
- Open the role and go to the Assignments tab.
- Under Apps, assign the application you created earlier (
apisix-client).
Configure Apache APISIX
Update the route to require the generated scope. APISIX rejects tokens that do not carry headers:read with 403 Forbidden.
curl -i 'http://127.0.0.1:9180/apisix/admin/routes' -X PUT -d '{
"id": "auth-with-thunderid",
"uri": "/anything/*",
"plugins": {
"openid-connect": {
"bearer_only": true,
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>",
"use_jwks": true,
"discovery": "https://<DATA_PLANE_URL>/.well-known/openid-configuration",
"ssl_verify": false,
"required_scopes": ["headers:read"]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'
Try It Out
Obtain an Access Token with the Required Scope
Request a token for the application that has the role assigned:
curl -k -X POST 'https://<DATA_PLANE_URL>/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=headers:read' \
--data-urlencode 'client_id=<CLIENT_ID>' \
--data-urlencode 'client_secret=<CLIENT_SECRET>'
The response confirms the scope is present:
{
"access_token": "<ACCESS_TOKEN>",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "headers:read"
}
Call the Protected API
With a token that has the required scope, the request is forwarded to the upstream:
export ACCESS_TOKEN="<ACCESS_TOKEN>"
curl -i 'http://127.0.0.1:9080/anything/test' \
-H "Authorization: Bearer $ACCESS_TOKEN"
APISIX verifies the token carries the headers:read scope and forwards the request to the upstream.
With a token missing the required scope, expect 403 Forbidden:
curl -i 'http://127.0.0.1:9080/anything/test' \
-H "Authorization: Bearer <TOKEN_WITHOUT_REQUIRED_SCOPE>"
APISIX inspects the token, finds the headers:read scope absent, and returns 403 Forbidden.
Plugin Parameter Reference
| Parameter | Value | Description |
|---|---|---|
discovery | https://<DATA_PLANE_URL>/.well-known/openid-configuration | Choreo Identity & Access Management's OIDC discovery endpoint. The plugin fetches the JWKS from here and verifies each token's signature, issuer, and expiry. |
client_id | <CLIENT_ID> | Client ID of the Choreo Identity & Access Management Backend Service application. |
client_secret | <CLIENT_SECRET> | Client secret of the Choreo Identity & Access Management Backend Service application. |
bearer_only | true | Requires a Bearer token in all requests. APISIX returns 401 for requests without a valid token instead of redirecting to a sign-in page. |
use_jwks | true | Validates JWT signatures using the JWKS endpoint fetched from the discovery document. |
ssl_verify | false | Disables TLS certificate verification. Use this during local development when Choreo Identity & Access Management uses a self-signed certificate. Enable certificate verification in production. |
required_scopes | ["headers:read"] | Scopes the token must carry. Missing scopes are rejected with 403. Omit to accept any valid token. |
Was this page helpful?