Configure Keycloak for the Desk API
Learn how to set up Keycloak for the Desk API.
The Desk API accepts user mangagement integration from Keycloak. This guide describes how to configure Keycloak to work with the Desk API.
Prerequisites
- You have a Keycloak account and admin privileges.
1
Configure the realms
-
Create a new realm, for example
desk
. -
Select the master realm and create a new client with the following settings:
- Client type: OpenID Connect
- Client ID:
CLIENT_ID
- Name:
CLIENT_NAME
- Client authentication: On
- Authentication flow: Select the Standard flow and Direct access grants checkboxes
All other fields can be left empty or with default value. Replace
CLIENT_ID
andCLIENT_NAME
with the name you want for your Desk API client. -
Select the newly created client, open the Credentials tab and click Regenerate client secret.
-
Select the desk realm and create a new client with the following settings:
- Client type: OpenID Connect
- Client ID:
CLIENT_ID
- Name:
CLIENT_NAME
- Client authentication: On
- Authorization: On
- Authentication flow: Select the Standard flow and Direct access grants checkboxes
All other fields can be left empty or with default values. Replace
CLIENT_ID
andCLIENT_NAME
with the same values used in step (2). -
Select the newly created client, open the Credentials tab and click Regenerate client secret.
2
Add new client scope to client
Select the desk realm, click Client scopes and create a new client scope with the following configurations:
- Name:
group
- Type: default
- Protocol: OpenID Connect
- Include in token scope: On
- Display on consent screen: On
Select the group client scope, open the Mappers tab and click Configure a new mapper. Create three new mappers with the following settings:
-
group_role
-
Mapper type: User Attribute
-
Name:
group_role
-
User attribute:
group_role
-
Token Claim Name:
group_role
-
Claim JSON Type: String
-
Select the following checkboxes:
- Add to ID token
- Add to access token
- Add to userinfo
- Multivalued
- Aggregate attribute values
All other fields can be left empty or with default values.
-
-
Group
-
Mapper type: Group membership
-
Name:
Group
-
Token Claim Name:
groups
-
Select the following checkboxes:
- Full group path
- Add to ID token
- Add to access token
- Add to userinfo
All other fields can be left empty or with default values.
-
-
group_membership
-
Mapper type: Group membership
-
Name:
group_membership
-
Token Claim Name:
group_membership
-
Select the following checkboxes:
- Full group path
- Add to ID token
- Add to access token
- Add to userinfo
All other fields can be left empty or with default values.
-
Add the new client scope to client.
- Still in the desk realm, select the client created in the previous section.
- Open the Client scopes tab.
- Click Add client scope.
- Select the group client scope and click Add.
3
Create groups
For each organization in the Desk API, create a Group and create Roles for that group.
-
Select the desk realm, select Groups and click Create group.
-
Enter a
GROUP_NAME
and click Create. -
Select the created group and select the Attributes tab.
-
Add the following attributes:
display_name
: Choose a display name for the organizationcore_id
: Provide a random UUID for the organization
-
In the realm admin panel, select Realm roles.
-
Create two roles:
GROUP_NAME_READER
: Users with this role assigned can read data in this organization but not write or create entitiesGROUP_NAME_EDITOR
: Users with this role assigned can write data and create entities in this organization
For example, for a group named
HR
, create anHR_READER
role and anHR_EDITOR
role.
4
Define user attributes
For each user of the Desk API, a username and credentials must be specified, three attributes must be defined, and roles must be mapped.
-
Use an email address as the Username and click Create.
-
With the newly created user selected, select the Credentials tab and click Set password. Input a password for the user.
-
Select the Attributes tab and add three attributes:
organisation
: Provide the UUID of the default organization upon loginlanguage
: Provide the two-letter language code for the default language upon loginhomepage
: Provide the path for the default homepage upon login
The Desk API uses the UK-English spelling of 'organisation'.
-
Select the Role mapping tab and click Assign role.
-
Select all of the roles to be mapped to this user.
-
Save your changes.