Hi! I am trying to set a custom jwt template to re...
# ask-a-descoper
e
Hi! I am trying to set a custom jwt template to resolve a custom claim named: "userCustomAttributes" type dynamic with the value "user.customAttributes" I tried doing it that way and also via the advanced mode where I tries to put:
Copy code
"userCustomAttributes": {
   "isBlocked": "{{user.customAttributes.blocked}}"
 },
But it didn't work. Can it be done? would love your help please
d
Custom Claims Configuration Yes, you can include custom attributes in JWT templates. Based on the documentation, there are two approaches to add custom claims with user custom attributes. Simple Configuration Method 1. In JWT Templates, add a custom claim with: - Key:
userCustomAttributes
- Type: Dynamic - Value:
user.customAttributes
This will include the entire customAttributes object in your JWT . Advanced Configuration Method For your advanced mode approach, the syntax should be:
Copy code
{
  "userFeatureFlags": {
    "isBlocked": "{{user.customAttributes.blocked}}"
  }
}
Troubleshooting Your Configuration The issue with your current advanced configuration might be: • Missing quotes around the template variable • Ensure the custom attribute
blocked
exists on the user • Verify the user has the customAttributes populated Alternative Approach You can also use the Custom Claims action in Descope Flows to add these claims dynamically during authentication . • Add a Custom Claims action to your flow • Set Key:
userCustomAttributes
• Set Type: Dynamic • Set Value:
user.customAttributes
The dynamic values are populated from available Descope user data . Custom Claims Overview | Descope Documentation Add User Information to JWT Response Using Descope Flows Dynamic Keys & Values | Descope Documentation
e
It didn't work unfortunately
d
Troubleshooting Steps Let's identify what might be causing the issue. Here are the most common problems: Check User Has Custom Attributes 1. Verify the user actually has
customAttributes
populated 2. Check if the specific attribute
blocked
exists on the user 3. Ensure the JWT template is assigned to your application Correct Syntax for Advanced Mode Try this exact syntax in advanced mode:
Copy code
{
  "userCustomAttributes": "{{user.customAttributes}}",
  "userFeatureFlags": {
    "isBlocked": "{{user.customAttributes.blocked}}"
  }
}
Alternative Dynamic Reference Based on the documentation, you might need to use
unauthUser
instead :
Copy code
{
  "userCustomAttributes": "{{unauthUser.customAttributes}}",
  "userFeatureFlags": {
    "isBlocked": "{{unauthUser.customAttributes.blocked}}"
  }
}
Verify JWT Template Assignment • Ensure your JWT template is set as the default for your project • Check that the template is being used by your authentication flow Test with Simple Attribute First Try testing with a basic user attribute to confirm the template works:
Copy code
{
  "testClaim": "{{user.email}}"
}
If none of these work, the issue might be with how the custom attributes are stored on the user or the template assignment. Can you confirm if the user has custom attributes populated and which approach you tried? Dynamic Keys & Values | Descope Documentation
e
After trying the exact template you gave me I'm getting this in the decoded JWT:
Copy code
"userCustomAttributes": "{{user.customAttributes}}",
      "userFeatureFlags": "{{user.customAttributes}}"
d
Template Variables Not Resolving The issue is that the template variables aren't being processed - they're appearing as literal strings in the JWT. This indicates a few possible problems: Check JWT Template Assignment 1. Verify the JWT template is set as the default template for your project 2. Navigate to Project Settings > JWT Templates and ensure your template has the "Default" badge 3. If not default, click the three dots menu and select "Set as Default" Verify Template Type Ensure you created a User JWT Template, not an Access Key template, since you're trying to access user attributes. Test Template Activation Try logging out and logging back in after setting the template as default. JWT templates only apply to newly issued tokens. Alternative Syntax If the issue persists, try this syntax without quotes around the template variables:
Copy code
{
  "userCustomAttributes": {{user.customAttributes}},
  "userFeatureFlags": {
    "isBlocked": {{user.customAttributes.blocked}}
  }
}
Verify Custom Attributes Exist Check that your test user actually has
customAttributes
populated by: 1. Going to User Management in the console 2. Finding your test user 3. Confirming custom attributes are present The literal template strings in your JWT suggest the template engine isn't processing the variables, which typically means the template isn't active or properly assigned.
e
Tries everything as instructed. still doesn't work and for new syntax I can't save the changes (It says: "Expected property name or '}' in JSON at position 252 (line 10 column 32)")
d
JSON Syntax Error The error indicates invalid JSON syntax. In JWT templates, you must keep the quotes around template variables. The issue isn't the syntax - it's that your template isn't being applied. Root Cause Analysis Since the template variables appear as literal strings, your JWT template isn't being processed. This typically means: 1. Template not assigned to your authentication method 2. Using wrong template type 3. Template not saved properly Immediate Steps 1. Go to Project Settings > JWT Templates 2. Find your template and click "Applications" tab 3. Assign it to your specific authentication application/flow 4. Save and test with a fresh login Verify Template Application Check if you're using: • Descope SDKs - Template should be assigned to your project default • OIDC/OAuth flows - Template should be assigned to the specific OIDC application • Custom flows - Template should be assigned to the flow Alternative Approach If JWT templates continue failing, use the Custom Claims action in your authentication flow instead: 1. Edit your sign-up/sign-in flow 2. Add Custom Claims action after authentication 3. Set Key:
userCustomAttributes
, Type: Dynamic, Value:
user.customAttributes
This approach bypasses JWT templates entirely and adds claims directly during authentication . The documentation doesn't cover this specific template assignment issue in detail. I'd recommend confirming with Descope support how JWT templates are properly assigned to your authentication method. Custom Claims Overview | Descope Documentation
e
I believe it's being applied, I see new attributes I add in the decoded JWT, it's just not resolving values well
d
Template Variables Not Resolving Values Since new attributes appear but variables aren't resolving, this suggests the user might not have the
customAttributes
populated or the reference path is incorrect. Debug Steps 1. Test with known user data first:
Copy code
{
  "testEmail": "{{user.email}}",
  "testUserId": "{{user.userId}}"
}
2. Check if user has custom attributes: - Go to User Management in console - Find your test user - Verify
customAttributes
field exists and has data 3. Try alternative reference paths:
Copy code
{
  "userCustomAttributes": "{{user.customAttributes}}",
  "specificAttribute": "{{user.customAttributes.blocked}}"
}
Common Issues • User doesn't have
customAttributes
set • Custom attribute
blocked
doesn't exist on the user • Wrong attribute name (case-sensitive) Verify User Data Create a test user with custom attributes via the Management API or console, then test the template. If
{{user.email}}
resolves but
{{user.customAttributes}}
doesn't, the user likely has no custom attributes set. The template engine is working (since you see new attributes), but the specific data path
user.customAttributes
is returning empty/null values.
👎 1
b
Hey @Eden Ben Shoshan, To achieve this, please follow the steps below: • First, configure the custom attribute in the Users section under Manage in the Descope console. • Then, update the JWT template either in Standard mode or Advanced mode.This will show you the suggestions for the custom attribute which you have added in the custom attribute section I’m sharing a snapshot for your reference.
e
Hi @Bhagwanta Yeole This is exactly what I did but it didn't work. Am I missing something? In the decoded JWT I see the the data failing to parse and showing like in the attached photo (I'm clarifying again that this is what the claim is, it fails to resolve and just show up as a weird string in the token)
Copy code
"anotherTryWithUser": "{{user.customAttributes}}",
 "userFeatureFlags": "{{user.customAttributes}}"
worth mentioning that it does work for tenant's customAttributes
b
You need to give the specific custom attribute that you wanted to come in the JWT.
e
I tried both as shown in userFeatureFlags
I have the request custom attribute on the users, and I double checked I'm editing a users JWT template
b
Can we connect over call?
e
definitely, thank you!
✅ 1