Protect APIs on Choreo API Management with ThunderID
This guide explains how to secure your APIs at the Choreo API Management gateway layer using tokens issued by ThunderID. You register ThunderID as a key manager on the gateway. The gateway then retrieves public signing keys from the ThunderID JWKS endpoint and 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 Choreo API Management:
- Token Validation: Add ThunderID as a key manager on the gateway and attach the JWT Auth policy to your API, ensuring only requests with a valid ThunderID token reach your backend.
- Scope-Based Authorization: Leverage ThunderID's RBAC capabilities to enforce strict, gateway-driven access control policies on your APIs.
Prerequisites
- ThunderID is installed and configured. See Get ThunderID.
- A Choreo organization with access to API Management.
- A backend API that the Choreo gateway can reach over HTTPS.
curlis available in your terminal.- ngrok installed to expose ThunderID on a public URL.
Expose ThunderID on a Public URL
Choreo API Management is a cloud-hosted service and cannot reach a ThunderID instance running on localhost. The gateway fetches the ThunderID discovery document and JWKS over the internet, so expose ThunderID on a publicly accessible HTTPS URL before configuring Choreo.
Set the public URL in ThunderID's deployment.yaml:
server:
hostname: "localhost"
port: 8090
public_url: "https://<THUNDERID_PUBLIC_URL>"
Restart ThunderID after saving the change. Also update the Console callback URL to https://<THUNDERID_PUBLIC_URL>/console.
Unless jwt.issuer is set in deployment.yaml, ThunderID uses the public URL as the iss claim of every token it issues. If jwt.issuer is set, that value is the iss claim, and you use it as the key manager's Issuer below. Choreo matches the issuer exactly when it validates a token.
Configure JWT Token Validation in Choreo API Management
The JWT Auth policy validates each token against the key manager that you register for ThunderID. In this section, you register an application in ThunderID to obtain credentials, add ThunderID as a key manager on the Choreo gateway, attach the JWT Auth policy to your API, and verify that unauthenticated requests are rejected.
Configure ThunderID
Create an Application
- Sign in to the ThunderID Console at
https://<THUNDERID_PUBLIC_URL>/console. - Navigate to Applications → Add application.
- Select Backend service as the application type.
- Enter an Application name (for example,
choreo-api-client). - Click Create application.
- Note the Client ID and Client secret.
Obtain an Access Token
Use the client credentials grant to request an access token. A Backend service application authenticates with HTTP Basic authentication (client_secret_basic):
curl --location 'https://<THUNDERID_PUBLIC_URL>/oauth2/token' \
--user '<CLIENT_ID>:<CLIENT_SECRET>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials'
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://<THUNDERID_PUBLIC_URL>. Copy the access_token value. You use it in the next Try It Out section.
Configure Choreo API Management
Add ThunderID as a Key Manager
A key manager is an identity provider that the gateway trusts. The gateway accepts a token only when its iss claim matches the issuer of one of its key managers.
- Sign in to the Choreo console and open API Management.
- Navigate to API Gateways.
- On the gateway you deploy your APIs to (for example, Default), click Configure.
- Under JWT AUTHENTICATION → Key managers, click Add key manager.
- Fill in the following fields:
- Name:
thunderid. API policies refer to the key manager by this name. - Issuer:
https://<THUNDERID_PUBLIC_URL>. It must exactly match theissclaim in tokens issued by ThunderID.
- Name:
- Click Continue. Choreo fetches the ThunderID discovery document and fills in the Well-known URL and the JWKS URL (
https://<THUNDERID_PUBLIC_URL>/oauth2/jwks). - Click Add.
- Click Save and apply, and wait until the gateway shows Running.
Create an API
- In API Management, open your project and click Create API.
- Under What kind of API are you exposing?, select REST API and click Continue.
- Select Start from scratch, enter the URL of your upstream bookings API in Endpoint URL (for example,
https://<BOOKINGS_API>), and click Continue. - Enter a Name (for example,
bookings), set Context to/bookings, and click Create.
An API created from scratch has GET, POST, PATCH, and DELETE resources on /*. Keep only GET /* and POST /*:
- In the API's side menu, select Develop → Definition.
- Click View Resources if the definition opens as code, then click the delete icon on
PATCH /*andDELETE /*. - Click Save, then click Save in the Update API dialog.
Add JWT Validation
Attach the JWT Auth policy to the API so that the gateway validates every incoming token.
- In the API's side menu, select Develop → Policies.
- Under Available policies, search for
JWT. - Drag JWT Auth onto Global policies to apply it to every resource in the API.
- In the Configure JWT Auth panel, expand Advanced settings.
- In Issuers, type
thunderidand press Enter. - Click Attach policy, then click Save changes.
With Issuers set to thunderid, the gateway accepts only tokens issued by ThunderID. It verifies each token's signature against the ThunderID JWKS, and checks the issuer and expiry.
Deploy the API
- In the API's side menu, select Deploy.
- Click Build and deploy.
- In the Deploy to development dialog, confirm the endpoint URL and click Deploy.
- Wait until the gateway shows Active.
Get the Invoke URL
- In the API's side menu, select Overview.
- In the Invoke URL panel, select the gateway and copy the URL. It is the gateway endpoint followed by the API context, for example
https://<CHOREO_GATEWAY_HOST>/bookings. Use it as<INVOKE_URL>in the commands below.
Try It Out
Request without a token, expect 401 Unauthorized:
curl -i "<INVOKE_URL>"
Request with a valid ThunderID token, expect 200 OK:
export ACCESS_TOKEN="<ACCESS_TOKEN>"
curl -i "<INVOKE_URL>" \
-H "Authorization: Bearer $ACCESS_TOKEN"
A successful request returns the response from your backend. If the token is missing, invalid, expired, or issued by an identity provider other than ThunderID, the gateway returns 401 Unauthorized with a WWW-Authenticate: Bearer header.
The gateway forwards the validated token to the backend in the x-forwarded-authorization header and removes the Authorization header.
Configure Scope-Based Authorization in Choreo API Management
JWT validation confirms that a token is valid and was issued by ThunderID. It does not control what the token holder is allowed to do. With the configuration from the previous section, the gateway accepts any valid ThunderID token regardless of the application or its assigned permissions.
ThunderID issues the scopes an application requests when its roles grant them, and sets the token's audience to the resource server the token was requested for. The JWT Auth policy then checks both on every request and rejects tokens that do not carry the required permissions. GET requires bookings:read, and POST requires bookings:write.
The steps below build on the JWT validation configuration from the previous section. You will define a Resource Server, a Resource, and actions in ThunderID to model your API permissions. Then bundle them into a role, assign the role to your application, and attach a JWT Auth policy to each resource with its scope.
Configure ThunderID
Create a Resource Server
A Resource Server represents your API in ThunderID. It groups the resources and actions that model your API, and exposes a permission (scope) for each action. For a full reference, see Resource Servers.
- In the Console, navigate to Resource servers → Add resource server.
- For the type, select API.
- Enter a Resource server name (for example,
Bookings API) and an Identifier (for example,https://bookings.example.com). - For the Permission delimiter, select
:. - Click Create resource server.
Add Resources and Actions
A Resource represents an entity within the API (such as the /bookings route), 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,
Bookings) and a Handle (bookings). - Under that resource, click Add action and enter a Name (for example,
Read Bookings) and a Handle (read). - Add a second action with a Name (for example,
Write Bookings) and a Handle (write).
This produces the permissions bookings:read and bookings:write. An application gets them in its token when it requests them and holds a role that grants them.
Create a Role and Assign Permissions
Roles bundle one or more permissions together. Assigning a role to an application controls which scopes its tokens can carry.
- Navigate to Roles → Add role.
- Enter a Role name (for example,
Bookings editor). - Click Continue.
- Under Assign permissions, choose
bookings:readandbookings:write. - Click Continue.
Assign the Role to the Application
Assign the role to the application you created in the previous section. When the application requests a scope that the role grants, ThunderID includes it in the token.
- Open the role and go to the Assignments tab.
- Under Apps, assign the application you created earlier (
choreo-api-client).
Configure Choreo API Management
Replace the global JWT Auth policy with one policy per resource:
-
Open the API and select Develop → Policies.
-
Under Global policies, click Remove policy (the trash icon) on the JWT Auth policy.
-
Under Resource policies, drag JWT Auth onto the
GET /*resource. -
In the Configure JWT Auth panel, expand Advanced settings and set:
- Issuers:
thunderid - Audiences:
https://bookings.example.com - Scopes → All of:
bookings:read
Type each value and press Enter.
- Issuers:
-
Click Attach policy.
-
Drag JWT Auth onto the
POST /*resource and configure it the same way, withbookings:writein Scopes → All of. -
Click Save changes.
-
Select Deploy, open the deploy action menu next to Deploy, and select Build and Deploy so that the gateway runs the updated policies.
Each policy reads scopes from the token's scope claim. It rejects tokens whose aud claim does not include https://bookings.example.com with 401 Unauthorized, and tokens without the operation's scope with 403 Forbidden, before the request reaches your backend.
Try It Out
Obtain an Access Token with the Required Scope
Request a read-only token for the application that has the role assigned. Pass the resource server identifier in the resource parameter, which sets the token's audience and selects the resource server whose scopes are issued:
curl --location 'https://<THUNDERID_PUBLIC_URL>/oauth2/token' \
--user '<CLIENT_ID>:<CLIENT_SECRET>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=bookings:read' \
--data-urlencode 'resource=https://bookings.example.com'
The response confirms the scope is present:
{
"access_token": "<ACCESS_TOKEN>",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "bookings:read"
}
To get a token that can also create bookings, run the same request with scope=bookings:read bookings:write. Use it as <READ_WRITE_TOKEN> below.
Call the Protected API
Read bookings with the read-only token, expect 200 OK:
export ACCESS_TOKEN="<ACCESS_TOKEN>"
curl -i "<INVOKE_URL>" \
-H "Authorization: Bearer $ACCESS_TOKEN"
The gateway verifies the token's audience and the bookings:read scope, and forwards the request to your backend.
Create a booking with the read-only token, expect 403 Forbidden:
curl -i -X POST "<INVOKE_URL>" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{}'
The gateway returns 403 Forbidden with WWW-Authenticate: Bearer error="insufficient_scope", because POST requires bookings:write.
Create a booking with the read-write token, expect your backend's response:
curl -i -X POST "<INVOKE_URL>" \
-H "Authorization: Bearer <READ_WRITE_TOKEN>" \
-H "Content-Type: application/json" \
-d '{}'
The token carries bookings:write, so the gateway forwards the request to your backend.
With a token missing the required scope, expect 403 Forbidden:
curl -i "<INVOKE_URL>" \
-H "Authorization: Bearer <TOKEN_WITHOUT_REQUIRED_SCOPE>"
The gateway returns 403 Forbidden with WWW-Authenticate: Bearer error="insufficient_scope". To get such a token, request one with resource=https://bookings.example.com and no scope parameter.
With a token for a different audience, expect 401 Unauthorized:
Use the token from Obtain an Access Token, which was requested without scope or resource. It carries the application's client ID as its audience:
curl -i "<INVOKE_URL>" \
-H "Authorization: Bearer <TOKEN_WITHOUT_RESOURCE>"
The gateway returns 401 Unauthorized with WWW-Authenticate: Bearer error="invalid_token".
Configuration Reference
Key Manager
| Field | Value | Description |
|---|---|---|
| Name | thunderid | Identifier that API policies use to refer to this key manager. |
| Issuer | https://<THUNDERID_PUBLIC_URL> | Must exactly match the iss claim in tokens issued by ThunderID. |
| Well-known URL | https://<THUNDERID_PUBLIC_URL>/.well-known/openid-configuration | ThunderID's OpenID Connect discovery document. Filled in by Continue. |
| JWKS URL | https://<THUNDERID_PUBLIC_URL>/oauth2/jwks | Endpoint the gateway fetches ThunderID's signing keys from. Filled in from the discovery document. |
JWT Auth Policy
The Configure JWT Auth panel lists these settings under Advanced settings.
| Setting | Value | Description |
|---|---|---|
| Issuers | thunderid | Key managers whose tokens the API accepts. When empty, the gateway accepts tokens from any of its key managers whose issuer matches the token's iss claim. |
| Audiences | https://bookings.example.com | Accepted audience values. The token's aud claim must contain at least one of them. Set it to the identifier of the resource server that protects this API. When empty, any audience is accepted. |
| Scopes → All of | bookings:read on GET /*, bookings:write on POST /* | Every listed scope must be present in the token's scope claim. |
| Scopes → Any of | Not set | At least one listed scope must be present. When both lists are set, both conditions apply. |
| On authorization failure status code | 403 (default) | Status code returned when a valid token fails the scope or claim checks. |
| Header name | Authorization | Request header the gateway reads the token from. |
| Auth header prefix | Bearer | Prefix expected before the token in that header. |
| Forwarded token header | x-forwarded-authorization | Header that carries the validated token to the backend. |