Skip to main contentArrow Right
Two logos next to each other on a dark blue background: the Descope logo mark on the left and the JSON Web Token (JWT) logo, a multicolored pinwheel of 12 bars, on the right. The image contains no text.

Table of Contents

Summarize with AI

Don't have the time to read the entire post? Our human writers will be sad, but we understand. Summarize the post with your preferred LLM here instead.

In this blog, you will learn how to add the user’s email as a custom attribute to the JWT response / payload using Descope. Adding custom attributes to the JWT response payload is important for getting various user data parameters and building a more customized experience. With the power of Descope Flows, we can accomplish this task in a matter of minutes. 

Descope Flows allows you to create entire authentication flows and user journeys with our no-code designer. It’s literally as simple as drag and drop! 

Prerequisites

Sign up at Descope to create a free account, and be sure to check out our amazing docs. If you are unfamiliar with Descope Flows there is an awesome blog that explains all about it here! 

If you haven’t created a project, get started by logging in to Descope. Create your project, select your authentication methods, and click continue. Open a “sign-up-or-in” Flow.

Action: Custom Claims

This action is called Custom Claims and this is where we add the custom attributes to our JWT.

Descope Console Flows editor in dark mode with an "Add Action" dialog open over the flow canvas. The dialog's search field contains the text "Custom" and returns one result: "Custom Claims," described as "Create and update custom claims on the user's JWT." A "Cancel" link sits at the bottom right of the dialog. Behind the dialog, the left navigation shows the project "descope-jwt-eml" and the items Home, Getting Started, Authentication Methods, Flows (selected), Styles, Connectors, Users, Access Keys, Tenants, Authorization, Audit, Project, and Company, and the top bar shows a Save button and the signed-in user "Eric Sheen (Intern)."
Fig: The Custom Claims Action

Click the “Custom Claims” option and populate the fields with the values below:

  1. Edit the Step name to be something like “Add Email JWT”. 

  2. Set the Key to eml for email. By setting the Type to Dynamic you will be able to see the list of various possible attributes as you type. 

  3. Set the value to user.email to add the user's email in the JWT.

Custom Claims pop-up in the Descope Console, opened over the Sign Up or In flow (Active) in the project descope-jwt-eml. Under the heading "Action: Custom Claims" is the text "Create and update custom claims on the user's JWT." The Step name field is set to "Add Email JWT". An info box lists three points that are partly covered by a dropdown: "New custom claims will be appended to the JWT.", "If the custom claim already exists, the new value will override", and "Claim values can be dynamic, use dynamic type for autocompl". A claim row has Key set to "eml", Type set to "Dynamic", and Value set to "user.email". The Value autocomplete dropdown is open and lists unauthUser.totp, unauthUser.userId, unauthUser.verifiedEmail, unauthUser.verifiedPhone, unauthUser.webauthn, and user.email, which is highlighted. Below are an "+ Add custom claim" link and Cancel and Done buttons. The Console sidebar lists Home, Getting Started, Authentication Methods, Flows (selected), Styles, Connectors, Users, Access Keys, Tenants, and IdP Applications.
Fig: Populate the Custom Claims pop-up

Now let’s add our Action to the Flow!

Connecting our Action to the Flow

Descope Flows editor showing the end of the Sign Up or In flow (ID: sign-up-or-in, Active) on a dark canvas at 57% zoom, with download, upload, and Save controls at the top right. A condition step named "Is new user?" has two outputs, "New user" and "Existing user". New user connects to a User Information screen, whose Submit output connects to an Update User / Properties action. The Success output of Update User / Properties and the Existing user output both connect to an action named Add Email JWT. The Success output of Add Email JWT connects to the END node. A separate screen step named Verified Successfully sits above at the left edge of the canvas.
Fig: Add custom claims to a Descope Flow

Near the end of the Flow, drag and place the “Add Email JWT” Action as shown above. After this, make two connections: 

  • Connect Update User / Properties → Add Email JWT → End. 

  • Connect Existing User → Add Email JWT → End. 

Once you're done, remember to click save on the top right corner! The very end result should look like the figure above.

The Result

You can see the new JWT you’ve created with your custom claims in the Getting Started Wizard.

Getting Started page in the Descope Console for the project descope-jwt-eml. The left side shows the end of a frontend code sample (onError={(err) => { console.log("Error!", err) }} /> </AuthProvider>) and a section titled "Backend: Implement session validation" with a Read More link and Go, Node, and Python tabs. The Go tab is selected and shows: // Use the code below to add the session validation to your serve; // More info: https://docs.descope.com/build/guides/session/#Go; authorized, userToken, err := descopeClient.Auth.ValidateSessionWithToken(sessionToken). On the right, a preview panel shows the end of an authentication response with fields including "verifiedEmail": true, "verifiedPhone": true, "roleNames": [], "userTenants": [], "status": "enabled", "externalIds" (redacted), "picture": "https://lh3.googleuse" (cut off), "test": false, "customAttributes": {}, "createdTime": 1684518128, "TOTP": false, "SAML": false, "OAuth": { "google": true }, and "firstSeen": false. Below it, under "Your user's session JWT:", the payload reads "amr": [ "email" ], "drn": "DS", "eml" (value redacted), "exp": 1685484147, "iat": 1685483547, "iss" (redacted), and "sub" (redacted), followed by a header with "alg": "RS256", "kid" (cut off), and "typ": "JWT". An "Explore in sample app" link sits below the panel. The "eml" key in the payload is the custom claim added in the flow.
Fig: Inspect the JWT response in the Descope Getting Started Wizard

If you want to see your flows running on a proper website, you can click the “Explore in sample app” button. From there, you can log in and see the JWT response in the browser’s local storage. 

While this blog covers adding email to the JWT, you can add any other custom fields that suit your needs with Custom Claims. Adding claims with Descope Flows make setup and ongoing modifications a breeze!

Reaction GIF set in an office. A man in a light blue shirt and tie sits at a desk in the foreground with one hand raised in the air, as if offering a high five, while a smiling woman looks toward him from behind a reception desk in the background.

If you have any questions or want to start your Descope journey, sign up for our platform and join AuthTown, our open user community for developers to learn about authentication.