Skip to main content
Version: 1.14.0

Call the gateway with your identity provider's tokens

From 1.14.0, a workspace can let callers reach /v1 with an access token from the company's own identity provider, instead of a DVARA API key. The gateway checks the token, maps it to the workspace, and records the person it names on the audit record and the cost record of every call.

Enterprise only

Not included in DVARA Open Source. It runs with or without a licence.

It is off by default. A workspace accepts tokens only after its admin turns it on. API keys keep working beside it, so you can move callers over one at a time.

Use it when:

  • your people already sign in to an identity provider, and you want each call costed and audited to the person, not only to a shared key;
  • your services already get tokens from the identity provider, and you do not want to hand out and rotate one more secret.

How a token is checked​

A workspace trusts one issuer. For each call that carries a token, the gateway:

  1. finds the workspaces that trust the issuer named in the token's iss claim;
  2. checks the signature against the keys that issuer publishes at its JWKS URL, with one of the algorithms the workspace allows;
  3. checks that iss matches exactly, and that exp and nbf are within the clock skew. A token with no exp is refused;
  4. checks that the token's aud names one of the workspace's audiences;
  5. checks every required claim, and reads the user claim.

Exactly one workspace must accept the token. If none does, the call is refused with 401. If two would, the call is also refused, so a token meant for one workspace never acts in another (see Keep two workspaces apart).

The gateway then treats the call as it treats a call with an API key. Scopes, IP access rules, rate limits, budgets, policies, PII handling, guardrails and audit all apply. The token is never written to a log, an audit record or a cost record.

Send the token where you would send an API key. The gateway reads it from the same headers, in the same order:

Authorization: Bearer <access-token>

x-api-key (the Anthropic Messages API) and x-goog-api-key (the Gemini API) carry a token too. A credential that is not shaped like a signed token, such as a gw_ API key, is checked as an API key, as before.

Keys are cached. The gateway keeps an issuer's key set for 5 minutes. A token signed with a key it does not know makes it fetch the key set again, at most once every 30 seconds, so a rotated key works within seconds. A token signed with a retired key is refused.

Turn it on for a workspace​

There are two pages with the same form:

  • A workspace admin opens Identity → Identity Provider. It covers their own workspace only. A developer or viewer cannot open it.
  • A platform owner opens Access → Workspaces, edits the workspace, and follows Identity provider in the Access section. A policy-admin or billing-admin can read this page but cannot save it.

Fill in the form and click Save identity provider:

FieldDefaultWhat it does
Accept tokens from this identity providerOffTurns token sign-in on for this workspace
IssuerNone; requiredExactly the iss value in your tokens. One value, no spaces, at most 512 characters
JWKS URLNone; requiredWhere the identity provider publishes its signing keys. HTTPS only
AudiencesNone; at least oneThe aud values a token may carry, separated by commas. At most 10. Every token must name one
Signing algorithmsRS256Any of RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512 and EdDSA. None chosen means RS256
User claimsubThe claim that names the person on the audit record and the cost record. Its value must be text or a number, at most 256 characters
Clock skew (seconds)60How far exp and nbf may be off. 0 to 300
Required claimsNoneOne name=value per line, at most 10. A token must carry each one. For a claim that holds a list, such as groups, the list must contain the value
Endpoints a token may callNone: every endpointThe same scopes as an API key, such as completions:write or models:read

The form refuses a save that has a problem, lists every problem, and writes nothing. It refuses:

  • a missing issuer, JWKS URL or audience while the switch is on;
  • an algorithm that is not on the list. none and shared-secret algorithms such as HS256 are never accepted;
  • iss, aud, exp, nbf or iat as a required claim, because they are checked already;
  • an unknown scope;
  • a JWKS URL that is not HTTPS, or that points at a loopback, link-local or cloud metadata address;
  • a JWKS URL on a private network, unless the page allows it (see below);
  • an issuer and audience that another workspace already trusts with the same required claims.

The setting reaches the gateways with the workspace's other settings on the configuration bundle. A gateway applies a change within about 5 seconds of taking the bundle. No restart is needed.

Private networks. An identity provider inside your network, such as a Keycloak server on a private address, is allowed from the platform page by default (dvara.admin.egress.allow-private-networks, default true). From the workspace admin's page it is refused unless the operator sets dvara.portal.egress.allow-private-networks=true (default false). The gateway applies the same rule when it fetches the keys. It never follows a redirect, and it reads at most 512 KiB of keys.

Set up your identity provider​

Each provider needs an API, or a client, for the gateway, so that its tokens carry an audience the gateway can check.

Microsoft Entra ID​

  1. In App registrations, register an application for the gateway, for example dvara-gateway.
  2. Under Expose an API, set the Application ID URI and add a scope, for example access.
  3. In the application's Manifest, set "accessTokenAcceptedVersion": 2, so its access tokens use the v2.0 issuer below.
  4. Let your callers ask for the scope: a user signs in to a client application that requests api://<app-id>/access; a service uses the client credentials flow with api://<app-id>/.default.

Then fill in the form:

FieldValue
Issuerhttps://login.microsoftonline.com/<tenant-id>/v2.0
JWKS URLhttps://login.microsoftonline.com/<tenant-id>/discovery/v2.0/keys
AudiencesThe gateway application's client ID, which v2.0 tokens carry in aud
User claimoid (the user's object ID), or preferred_username for a name you can read. A service's token has no user, so use azp for services
Required claimstid=<tenant-id>

Entra ID signs with RS256, the default.

Okta​

Use a custom authorization server, such as default. Tokens from the org authorization server are for Okta's own APIs and should not be trusted here.

  1. In Security → API → Authorization Servers, open the server (or add one) and note its issuer and audience.
  2. Add a scope for the gateway, and an access policy that lets your client applications ask for it.
FieldValue
Issuerhttps://<your-org>.okta.com/oauth2/default
JWKS URLhttps://<your-org>.okta.com/oauth2/default/v1/keys
AudiencesThe server's audience, api://default unless you changed it
User claimsub (the user's sign-in name, or the client ID for a service token), or uid

Okta signs with RS256, the default.

Keycloak​

  1. In your realm, add a client for the gateway, for example dvara-gateway.
  2. Keycloak access tokens do not name your API by default. On the client that your callers use, add an Audience mapper that puts dvara-gateway in the access token's aud.
FieldValue
Issuerhttps://<keycloak-host>/realms/<realm>
JWKS URLhttps://<keycloak-host>/realms/<realm>/protocol/openid-connect/certs
Audiencesdvara-gateway
User claimpreferred_username, or sub

Keycloak signs with RS256 by default. A Keycloak server on a private address needs the private-network setting above.

Make a call​

Get an access token from your identity provider, then call the gateway with it:

curl -s https://<gateway-host>/v1/chat/completions \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}'

The answer is the same as with an API key. In Flightdeck, the call's audit record names the issuer and the user.

Keep two workspaces apart​

Two workspaces can trust the same issuer, as long as each token can match only one of them. Give each workspace its own audience, or a required claim that only its tokens carry, such as a group:

WorkspaceAudienceRequired claim
paymentsdvara-gatewaygroups=payments-ai
claimsdvara-gatewaygroups=claims-ai

Flightdeck refuses a save when another turned-on workspace trusts the same issuer, shares an audience and has the same required claims. If a token still matches two workspaces, for example a person in both groups, the gateway refuses it with 401 idp_token_ambiguous and serves neither.

What each call records​

The audit record. A call made with a token writes the usual GATEWAY_RESPONSE record, with these fields added:

FieldValue
auth_methodidp_token
idp_issuerThe token's issuer
end_userThe value of the workspace's user claim
idp_subjectThe token's sub, only when it differs from the user claim
api_keydvara-idp-<workspace-id>

The cost record. The call's user tag is the user the token names. It wins over the request's user field and over a user tag the caller sent, because the identity provider checked who that is. So spend by user, and budgets on a user value, follow the person. See Cost attribution.

One key id per workspace. Every token call in a workspace is counted under the key id dvara-idp-<workspace-id>. Usage, cost, rate limits and budgets that work per API key treat all of a workspace's token callers as one key. Use the user tag to tell people apart.

Settings changes. Every save writes WORKSPACE_IDP_TOKENS_UPDATED to the audit trail, with the workspace, the page it was saved from (workspace or platform), and the settings before and after. The settings hold no secret.

Resolve a refused token​

A refused token gets 401, with error type authentication_error, in the error shape of the API the caller used. The message says which check failed and never repeats the token:

CodeMeaningWhat to check
idp_issuer_not_trustedNo workspace accepts tokens from this issuerThe switch is on, and Issuer matches iss exactly, including any trailing /
idp_signature_invalidThe signature did not check against the issuer's keysThe JWKS URL belongs to this issuer
idp_algorithm_not_allowedThe token is signed with an algorithm the workspace does not allowSigning algorithms; none and HS256 are never accepted
idp_token_expiredexp is in the past, beyond the clock skewGet a new token
idp_audience_not_trustedaud names none of the workspace's audiencesAudiences; on Keycloak, the audience mapper
idp_claim_mismatchA required claim is missing or has another value, or the user claim is not short textRequired claims and User claim
idp_keys_unavailableThe gateway could not fetch the issuer's keysThe JWKS URL is reachable from the gateways. Try again later
idp_token_ambiguousMore than one workspace accepts the tokenKeep two workspaces apart
idp_token_invalidThe token is not a well-formed signed token, or its claims are not acceptable, such as no exp or no user claimThe token your client sends

A token that passes these checks but lacks a scope the endpoint needs gets 403 api_key_scope, as an API key does.

The refusal is written to the audit trail as a GATEWAY_RESPONSE record with status: 401 and the code. When only one workspace trusts the token's issuer, the record goes to that workspace's audit log.

Turn it off for a gateway​

To stop a gateway accepting tokens for every workspace, set dvara.llm-gateway.idp-tokens.enabled=false (DVARA_LLM_GATEWAY_IDP_TOKENS_ENABLED=false) and restart it. The workspace settings are then ignored, and /v1 takes API keys only. See the configuration reference for the gateway's other key-fetch settings.