Token Claims
In order to use information about tenants in your application, you need to add it to the token claims.
IAMS introduced the following mapper to add tenant information to the token claim:
- Active tenant – maps the active tenant to a token claim.
- All tenants – maps all tenants that user is a member of to a token claim.
Configure the Mapper
You can enable the mapper to the individual client or at the Client Scopes.
If you enable the mapper at the Client Scopes, any new client created after that will inherit the mappers and do not need require further configuration.
The default realm created in the Local Development has the mapper configured in Client Scopes.
Enable at Keycloak Client
To enable the 2 mapper for a Keycloak Client, perform the following steps:
-
Login to
Keycloak Admin Console
and switch to the realm. -
Click on
Clients
in the side menu
-
Click on the Client ID of the client to configure.
-
Click on the
Client scopes
tab.
- Click on the client scope with the name ended with
dedicated
.
- Click on
Add mapper
andselect By configuration
.
- Click on
Active tenant
- Enter the following fields:
- Name: active_tenant
- Token Claim Name: active_tenant
- Turn on
Add to lightweight access token
checkbox
- Click on
Save
to add the mapper.
- Click
Cancel
to go back to the Mappers list. You should seeactive_tenant
mapper in the list.
-
Click on
Add mapper
and selectBy configuration
. -
Click on
All tenants
- Enter the following fields:
- Name: all_tenants
- Token Claim Name: all_tenants
- Turn on Add to lightweight access token checkbox
- Click on
Save
to add the mapper.
Enable at Client Scopes
As mentioned, enable the mappers in Client Scopes
will allow any newly created client to automatically inherit the mappers.
Follows the following steps to enable mapper at the Client Scopes:
-
Login to the Web Admin Console and navigate to the realm.
-
Click on
Client scopes
in the side menu:
- Click on
Create client scope
:
- Enter the followings:
- Name: any prefer name
- Type: Default
- Protocol: OpenID Connect
- Turn off the Display on consent screen checkbox
- Click on
Save
to create the client scope.
- Click on
Mappers
tab
- Click on
Configure a new mapper
button:
- Click on
Active tenant
- Enter the following fields:
- Name: active_tenant
- Token Claim Name: active_tenant
- Turn on
Add to lightweight access token
checkbox
- Click on
Save
to add the mapper.
- Click
Cancel
to go back to the Mappers list. You should seeactive_tenant mapper
in the list.
- Click on
Add mapper
and selectBy configuration
.
- Click on
All tenants
- Enter the following fields:
- Name: all_tenants
- Token Claim Name: all_tenants
- Turn on
Add to lightweight access token
checkbox
- Click on
Save
to add the mapper.