Okta

Octa

Introduction

Auth0 allows you to add arbitrary claims to tokens (token customization) in the authentication and authorization process by using a function called Actions. As a result, the information required by the resource server can be passed at once via the token.
For example, you can implement the process of adding the profile information of the logged-in user to the ID token as a custom claim, or the process of adding the role information to the access token as a custom claim.

In this page, we will introduce the settings and actual operations using examples of the process of adding the logged-in user's profile information to the ID token and the process of adding role information to the access token.

premise

The information on functions and settings described on this page is current as of January 2023.

Setting overview

The settings required for token customization using the Actions function are as follows.

1. Create a new Action
  • Definition of custom logic by code editing (JavaScript writing)
2. Incorporate the created Action into Flow
  • Specify the trigger that activates the created Action
    • Triggers are selected from pre-defined ones on the Auth0 side

From here, we will introduce specific setting methods and operation examples.

Configuration example A: Add user profile information to the ID token as a custom claim

0. Preparation

Add arbitrary profile information to user's [user_metadata]

Add arbitrary profile information to user's [user_metadata]
1. Create a new Action
  • On the Auth0 admin screen, click Actions > Flows > Login
On the Auth0 admin screen, click Actions > Flows > Login
  • Click [Build Custom]
Click [Build Custom]
  • Select the name of the action to be created, the trigger of the action, and the execution environment, and click [Create].

This time, select [Login / Post Login] in [Trigger] to incorporate Action into the login flow.

Select the name of the action to be created, the trigger of the action, and the execution environment, and click [Create].
  • Describe the logic to be implemented in the code editor (JavaScript description)

Use api.idToken.setCustomClaim() as a Function to set a custom claim to the ID token

Describe the logic to be implemented in the code editor (JavaScript description)
  • Click Deploy
Click Deploy
  • Confirm that the created Action was successfully deployed
Confirm that the created Action was successfully deployed
2. Incorporate the created Action into Flow
  • On the Auth0 admin screen, click Actions > Flows > Login
On the Auth0 admin screen, click Actions > Flows > Login
  • From the Action list displayed in the [Custom] tab on the right side of the screen, drag and drop the Action created in "1. Create a new Action" and apply it to the flow diagram on the left side of the screen.
From the Action list displayed in the [Custom] tab on the right side of the screen, drag and drop the Action created in "1. Create a new Action" and apply it to the flow diagram on the left side of the screen.
  • Click [Apply]
Click [Apply]
  • Confirm that it was reflected normally
Confirm that it was reflected normally

Operational example A: Add user profile information as a custom claim to the ID token

1. Perform login operation on the web application screen linked with Auth0

This time, we used a sample application (SPA/JavaScript) provided by Okta.

2. Open the profile page and confirm that the added information is displayed
Open your profile page and confirm that you can see the information you added

Setting example B: Add user role information to access token as custom claim

0. Preparation

Assign roles to users

Assign roles to users
1. Create a new Action

Perform 1) and 2) in the same way as "Setting example A: Add user profile information to ID token as a custom claim"

  • Select the name of the action to be created, the trigger of the action, and the execution environment, and click [Create].

This time, select [Login / Post Login] for [Trigger] to incorporate Action into the login flow.

Select the name of the action to be created, the trigger of the action, and the execution environment, and click [Create].
  • Describe the logic to be implemented in the code editor (JavaScript description)

Use api.accessToken.setCustomClaim() as Function to set custom claim to access token

Select the name of the action to be created, the trigger of the action, and the execution environment, and click [Create].
2. Incorporate the created Action into Flow

Perform ①②③ in the same way as "Setting example A: Add user profile information to ID token as a custom claim"

Select the name of the action to be created, the trigger of the action, and the execution environment, and click [Create].

Operation example B: Add user role information to access token as custom claim

1. Get access token based on Authorization code flow
  • Perform user authentication on the login screen provided by Auth0
  • Get an access token using the issued authorization code
2. Check the acquired access token
  • Decode access token
  • Confirm role information is added
Check the obtained access token

Summary

Auth0's Actions feature allows you to add custom claims to your tokens during the authorization process. It also comes with version control, testing, and debugging functions that are necessary for coding. You can try the functions even in the free Auth0 trial environment, so please feel the high degree of customization.

In Auth0, in addition to the custom logic introduced this time, you can incorporate various custom logic using the Actions function. If you are interested in Auth0's Actions feature, please contact us.

reference

Inquiry/Document request

In charge of Macnica Okta Co., Ltd.

Mon-Fri 8:45-17:30