Dynamic claim templates allow you to define custom JWT claims, where the claim value is determined at the time the access token is generated.
The value is based on contextual data and specified functions.
For example, you can use a dynamic claim template so that Konnect populates a random UUID for the client.
You can use dynamic claim templates for both the auth server and client.
These JWT claim values can be rendered as any of the following types:
- Strings
- Integers
- Floats
- Booleans
- JSON object or arrays
The type is inferred from the value.
JWT claim values can be templated with contextual data and functions. Dynamic values must use ${} as templating boundaries. For example:
-
${ uuidv4 } creates a UUID every time a new token is created.
-
${ .Client.Name } includes the client’s name in the token.
-
${ now | date "2006-01-02T15:04:05Z07:00" } generates the current timestamp in ISO 8601 format.
-
${ .AuthServer.Audience }-${ .Client.ID } concatenates the auth server’s audience with the client ID.
-
${ .Client.Labels.environment | default "production" } uses the client’s environment label, defaulting to “production” if it isn’t set.
-
${ upper .Client.Name } converts the client name to uppercase.
-
${ randAlphaNum 16 } generates a random 16-character alphanumeric string for each token.
You can use uuidParse and uuidValidate in your dynamic claim templates to parse a string as a UUID and check for a valid UUID, respectively.
To test the templating, you can use the /v1/auth-servers/$authServerId/clients/$clientId/test-claim endpoint.
Dynamic claims can use the context passed to the client during authentication in the following format:
|
Variable Name
|
Description
|
Format
|
|
AuthServer.ID
|
A regionally unique UUID of the auth server
|
uuid.UUID
|
|
AuthServer.CreatedAt
|
The timestamp when the auth server was created
|
DateTime
|
|
AuthServer.UpdatedAt
|
The timestamp when the auth server was last updated
|
DateTime
|
|
AuthServer.Name
|
The name of the auth server
|
string
|
|
AuthServer.Description
|
A description of the auth server
|
string
|
|
AuthServer.Audience
|
The intended audience for tokens issued by this auth server
|
string
|
|
AuthServer.SigningAlgorithm
|
The algorithm used to sign the JWT (for example, RS256, HS256)
|
string
|
|
AuthServer.Labels.key
|
A key/value label for metadata tagging
|
string
|
|
Client.ID
|
The ID of the client
|
string
|
|
Client.CreatedAt
|
The timestamp when the client was created
|
DateTime
|
|
Client.UpdatedAt
|
The timestamp when the client was last updated
|
DateTime
|
|
Client.Name
|
The name of the client
|
string
|
|
Client.Labels.key
|
A key/value label for metadata tagging
|
string
|
|
Client.GrantTypes[]
|
The grant types supported by the client (for example, client_credentials)
|
string
|
|
Client.RedirectURIs[]
|
Allowed redirect URIs for the client
|
string
|
|
Client.LoginURI
|
Login URI for interactive flows
|
string
|
|
Client.ResponseTypes[]
|
Supported OAuth response types (for example, code, token)
|
string
|
|
Client.AllowAllScopes
|
Indicates if all scopes are allowed by default
|
boolean
|
Dynamic claim templates support all the following functions from sprig in the claim templating engine: