Custom Token Claims

Learn how to embed custom claims directly into your application tokens.

Overview

Custom claims let you include information about an authenticated user or OAuth2 client in access tokens, ID tokens, and responses from the UserInfo Endpoint. For example, you can include a user's email, a tenant's display name, or the roles assigned to the authenticated subject.

You define custom claims at the application level. Each definition has three parts: a name that identifies the claim, one or more destinations where Wristband returns it, and a path expression that tells Wristband where to read its value.

Wristband groups custom claims in a JSON object named custom_claims within each selected token payload or UserInfo response. Each entry pairs the claim's configured name with the value Wristband resolves from its path expression.

Custom Claim Name

The claim name becomes a key in the custom_claims object. For example, if you name a claim department, your application can read its value at custom_claims.department.

Claim names must meet the following requirements:

  • Uniqueness: Each name must be unique within the application (case insensitive). Wristband treats department and Department as the same name.
  • Length: Up to 20 characters.
  • Allowed characters: Letters, numbers, hyphens (-), and underscores (_).

Destinations

Choose one or more destinations for each custom claim based on where your application needs its value.

DestinationWhen to use it
Access TokenYour application needs additional claims regarding the authenticated subject when processing an API request that includes the access token.
ID TokenYour application needs additional claims about the authenticated user at sign-in and cannot retrieve it from the UserInfo Endpoint.
UserInfo ResponseYour application needs additional claims about the authenticated user after sign-in.

Prefer the UserInfo Response for Custom User Claims

If your application needs additional user claims after sign-in, prefer UserInfo Response under Include In instead of ID Token. Select ID Token only when your application has a specific requirement for the claims to be in the ID token.

This follows the OpenID Connect pattern for standard claims. When the sign-in flow issues an access token, UserInfo is the destination for claims requested through the profile, email, address, and phone scopes. See OpenID Connect Core §5.4.

Path Expressions

A path expression tells Wristband where to get a custom claim's value.

The table below lists the supported paths for role names and direct user and tenant fields. For custom metadata values, see Custom Metadata Path Expressions.

Path expressionValue
role.nameThe authenticated subject's assigned role names, returned as an array of strings.
user.idThe authenticated user's ID.
user.emailThe authenticated user's email address.
tenant.idThe associated tenant's ID.
tenant.nameThe associated tenant's name.
tenant.displayNameThe associated tenant's display name.

Custom Claims in Client Credentials Access Tokens

When an OAuth2 client authenticates using the client_credentials grant, the client is the authenticated subject. Wristband omits claims with user. paths from the access token because no user is involved.

For a tenant-level client, tenant. paths reference the tenant that owns the client. For an application-level client, Wristband also omits claims with tenant. paths because the client has no associated tenant.

Custom Metadata Path Expressions

Path expressions can also be used to read values from user and tenant custom metadata. A custom metadata path expression starts with a prefix that selects the metadata object.

PrefixMetadata source
user.publicMetadataThe authenticated user's public metadata.
user.restrictedMetadataThe authenticated user's restricted metadata.
tenant.publicMetadataThe associated tenant's public metadata.
tenant.restrictedMetadataThe associated tenant's restricted metadata.

Add a period after the prefix, followed by the field path. For a nested field, separate each field name with a period. The field path can contain up to four segments after publicMetadata or restrictedMetadata.

For example, in user.publicMetadata.subscription.plan, the prefix user.publicMetadata selects the authenticated user's public metadata. The field path subscription.plan reads the plan field inside the subscription object and uses it as the claim's value.

Missing Metadata Fields

If a custom metadata path references a missing field, Wristband includes the claim in the custom_claims object with a value of null.

Custom Claim Examples

These examples use the same custom claim definitions. Each JSON excerpt shows the custom_claims object in the specified token payload or UserInfo response.

Custom Claim NameInclude InPath Expression
role_namesAccess Tokenrole.name
tenant_nameAccess Token, ID Tokentenant.name
departmentAccess Token, UserInfo Responseuser.publicMetadata.department

User Sign-In

A user in the acme tenant signs in with the editor and viewer roles. Their public metadata contains the following JSON object: {"department": "engineering"}.

Access token payload

{
  "custom_claims": {
    "role_names": ["editor", "viewer"],
    "tenant_name": "acme",
    "department": "engineering"
  }
}

ID token payload

{
  "custom_claims": {
    "tenant_name": "acme"
  }
}

UserInfo response

The application calls the UserInfo Endpoint with the user's access token.

{
  "custom_claims": {
    "department": "engineering"
  }
}

User Sign-In With Missing Metadata

A user in the globex tenant signs in with the viewer role and empty public metadata ({}). The department path references a missing field, so Wristband includes the claim with a value of null in both configured destinations.

Access token payload

{
  "custom_claims": {
    "role_names": ["viewer"],
    "tenant_name": "globex",
    "department": null
  }
}

ID token payload

{
  "custom_claims": {
    "tenant_name": "globex"
  }
}

UserInfo response

{
  "custom_claims": {
    "department": null
  }
}

Tenant-Level OAuth2 Client

An OAuth2 client owned by the acme tenant has the reader role and authenticates using the client_credentials grant. Wristband resolves role_names from the client's role assignments and tenant_name from the tenant that owns the client. It omits department because that claim requires an authenticated user.

Access token payload

{
  "custom_claims": {
    "role_names": ["reader"],
    "tenant_name": "acme"
  }
}

Application-Level OAuth2 Client

An application-level OAuth2 client has the reader role and authenticates using the client_credentials grant. Wristband resolves role_names from the client's role assignments. It omits department and tenant_name because those claims require user and tenant context, respectively.

Access token payload

{
  "custom_claims": {
    "role_names": ["reader"]
  }
}

Configuring Custom Claims in the Dashboard

  1. From the Dashboard Home page, select the application you want to configure.
  2. In Application View, navigate to Security → Token Settings.
  3. In the Custom Token Claims section, enter a Custom Claim Name.
  4. Under Include In, select one or more destinations for the claim.
  5. Select a Path Expression.
  6. Click Create Claim.

Figure 1: Create a custom claim in Token Settings.

Creating a Custom Metadata Claim

Use the custom claim form to create a claim from a user or tenant custom metadata field.

  1. Enter a Custom Claim Name and select one or more destinations under Include In.
  2. From the Path Expression dropdown, select a metadata prefix, such as user.publicMetadata.
  3. In Metadata Path, enter the field path that follows the prefix. For example, if the full path is user.publicMetadata.department, enter department.
  4. Click Create Claim.

Figure 2: Select a metadata prefix and enter the field path.

Viewing Existing Custom Claims

The table at the bottom of the Custom Token Claims section lists the application's existing claims.

Figure 3: View the application's existing custom claims.

Deleting Custom Claims

  1. In the custom claims table, open the More Options (⋮) menu for the claim you want to delete.
  2. Select Delete Custom Claim.

Figure 4: Delete a custom claim from its More Options menu.



Did this page help you?