The token-based authentication method uses a token to transmit the user ID, role, scope, and other information. When setting up this method, you must specify the conditions for Traceable to extract and transform the JWT token and define the attributes according to your requirements. This authentication method is secure and scalable for user attribution, as it embeds the user's ID, role, and scope in the token, which the server can easily verify.
What will you learn in this topic?
By the end of this topic, you will be able to:
Understand how token-based authentication links API requests to authenticated users.
Learn how to define the authentication scope for your environment and services.
Learn how to extract and transform the JWT token from requests.
Learn how to map JWT claims to authentication attributes for user attribution.
Understand token-based authentication user attribution
Token-based authentication user attribution helps you identify who is accessing your APIs by extracting identity claims from JWT or bearer tokens. It connects each request to a verified user and enriches it with contextual information such as role and scope, improving visibility, control, and threat analysis. The table below explains why you use it, when it applies, and how you can leverage it.
Why use it? | When to use? | How can you leverage it? |
|---|---|---|
You gain deep visibility into authenticated API activity by extracting identity claims such as user ID, role, and scope directly from JWT tokens. This enables accurate, scalable, and context-rich user attribution without relying on static credentials, improving observability and security insights across your APIs. | You use this when your application relies on JWT or bearer tokens for authentication, and identity claims are available in request headers, body, or cookies. It is especially relevant when you need user-level context for analytics, policy enforcement, or security evaluation across environments and services. | You attribute each API request to a verified user and enrich it with contextual claims to strengthen monitoring, auditing, and compliance. You correlate user roles and privileges with anomalies, detect misuse of access controls, and apply conditions and transformations (such as Regex, Base64 decoding, and JSON Path) to accurately extract, validate, preview, and enforce user attribution rules. |
Steps to configure
To configure token-based authentication, complete the following steps:
Step 1 — Define the authentication scope
Specify the Name.
(Optional) Specify a Description for the configuration.
Select the Environment in which you wish to apply the configuration.
Select the Services on which Traceable should apply the configuration. You can either select all or specific services from the drop-down according to your requirements.
(Optional) Specify the URL Regex if you wish to provide a granular scope for user attribution.
Click Next.
.png)
Token-Based Attribution Define Scope Window
Step 2 — Define the conditions to extract and transform the JWT token
(Optional) Click + Add Condition, then select and specify the location, key, operator, and value to use when Traceable checks spans for a match. If a span satisfies the condition, Traceable further evaluates the remaining configurations.
Select the Location and specify the key where Traceable can find the JWT token. While Traceable specifies this configuration by default using commonly used values, you can modify it to suit your requirements.
(Optional) Click + Add Value Transformation to add either of the following custom transformations:
Regex Capture Group — This transformation enables you to extract specific parts of a string or value that match the pattern you define.
Base64 Decoder — This transformation enables you to convert encoded Base64 data back to its decoded or original format.
JSON Path — This transformation enables you to navigate and select a specific key within a nested JSON structure.
While Traceable pre-adds some default transformations, you can add custom transformations. Traceable evaluates these transformations in order, from top to bottom.
Note
You can modify the values, if any, in the pre-added transformations and reorder them according to your requirements.
Do one of the following according to your requirements:
If you use the default values Traceable defines, click Generate Preview in the Preview Attributes section on the right. This shows the payload and details Traceable extracts from the JWT token. You can also click View Details to see the values returned corresponding to each step above.
If you modified the values above, click Reload in the Preview Attributes section on the right. Post-reload, click Generate Preview to view the JWT Token extracted by Traceable. You can also click View Details to see the values returned corresponding to each attribute you configured above.
Click Next.
.png)
User Attribution Token-based Extract Token Step
Step 3 — Define the authentication attributes
From the list of available attributes, select the one(s) you wish to add. Depending on the attribute you select, complete the following steps:
User ID/User Role/User Scope/Custom:
(Optional) Select the checkbox if you wish to Obfuscate the value post-attribution within the platform.
(For Custom only) Specify the Key (Attribute Key) you wish to use as part of the authentication process.
(Optional) Click + Add Condition, then select and specify the location, key, operator, and value to use when Traceable checks spans for a match.
Specify the Claim Location in Token (JSON Path) where Traceable can find the attribute.
(Optional) Click + Add Value Transformation to add either of the following custom transformations:
Regex Capture Group — This transformation enables you to extract specific parts of a string or value that match the pattern you define.
Base64 Decoder — This transformation enables you to convert encoded Base64 data back to its decoded or original format.
JSON Path — This transformation enables you to navigate and select a specific key within a nested JSON structure.
You can also reorder the transformations according to your requirements. Traceable evaluates them in order, from top to bottom.
Repeat the above steps to add one or more attributes, or complete the steps below to add the Auth Type attribute, according to your requirements.
Auth Type — You can select the authentication type from the drop-down list according to your requirements. You can also create a new one according to your requirements.
Generate the preview of the attribute value(s) by doing one of the following:
If you use the default values Traceable defines, click Generate Preview in the Preview Attributes section on the right. This shows the details generated in Step 2 above, and the value(s) extracted for the attributes. You can also click View Details to see the values returned corresponding to each attribute above.
If you modified the values above, click Reload in the Preview Attributes section on the right. Post-reload, click Generate Preview to view the details generated in Step 2 above, and the value(s) extracted for the attributes. You can also click View Details to see the values returned corresponding to each attribute you configured above.
Click Submit.
Examples and Demo
The following examples demonstrate how Traceable performs user attribution by extracting user identity claims from JWT tokens present in API requests:
Example 1 — When a JWT token is sent in the Request Header of an API
In this scenario, you must add Transformations to extract the JWT token from the header and decode it. Then, you can select the attributes you wish to identify. For example, if you consider the following JWT token and its corresponding payload for the demo, and the email claim in the payload contains the user ID. To extract it, you must add a Regex Capture Group transformation as shown in the below demo. Then, upon execution, Traceable extracts random as the user ID.
JWT Token | Payload |
|---|---|
| |
Example 2 — When a JWT token is sent in the Request Body of an API
In this scenario, you must add Transformations to extract the JWT token from the body and decode it. Then, you can select the attributes you wish to identify. For example, if you consider the following JWT token and its corresponding payload, then upon execution, Traceable extracts johndoe.com and Administrator as the user ID and role, respectively. Further, Traceable obfuscates these values on the platform.
JWT Token | Payload |
|---|---|
| |
Example 3 — When a JWT token is sent in the Request Cookie of an API
In this scenario, you must remove existing Transformations to extract the JWT token from the cookie and attribute it. Then, you can select the attributes you wish to identify. For example, if you consider the following JWT token and its corresponding payload, then upon execution, Traceable extracts john.doe as the user ID. Further, Traceable obfuscates these values on the platform.
JWT Token | Payload |
|---|---|
| |
Demo
The following interactive demo walks you through the steps to configure token-based user attribution: