---
title: Add Users and Claims in Keycloak for the Nodinite Docker Sandbox
description: Add users to the Keycloak identity provider of the Nodinite Docker sandbox, and decide what they see with Nodinite Claims, Policies, and Roles. Learn which Keycloak user attributes and realm roles reach the token, and how to match them.
---

# :fa-users: Add Users and Claims in Keycloak

Give colleagues their own sign-in to the :Nodinite: [Docker sandbox][Docker Sandbox], and decide what each of them sees. The sandbox signs users in through Keycloak, an OAuth 2.0 and OpenID Connect identity provider, so access works with [Claims][], [Policies][], and [Roles][] instead of Windows accounts. This is the same model as any :Nodinite: installation in OAuth 2.0 mode ([Install Nodinite v7 - OpenID][Install OpenID]), which makes the sandbox a good place to learn it.

* ✅ Add users in the Keycloak admin console, with their own password  
* ✅ Give a user a value in the token, as a user attribute or a realm role  
* ✅ Match that value with a :Nodinite: Claim, group Claims in a Policy, and grant Roles  

![In the Keycloak admin console, open the realm dev, add the user contoso.finance, set a password that isn't temporary, and assign the realm role nodinite-finance, animated walkthrough (7.12)][1]  
*Animated walkthrough: a new Keycloak user with a password and a realm role, which reaches the token as `roles`. Steps 1 and 2 below.*  

## :fa-diagram-project: Understanding How a Keycloak User Gets Access

:Nodinite: never stores sandbox users. At sign-in, Keycloak issues an access token with claims about the user, and the [Web API][] matches those claims with the [Claims][] of every [Policy][Policies]. A user who matches all Claims of a Policy gets that Policy's [Roles][], and the Roles decide what the user sees.

<div class="mermaid">
flowchart LR
    subgraph KC["fa:fa-id-card Keycloak, realm dev"]
        direction TB
        User["fa:fa-user User"]
        Attr["fa:fa-tag Attribute Group"]
        Role["fa:fa-user-tag Realm role"]
        User --> Attr
        User --> Role
    end
    subgraph Token["fa:fa-key Access token"]
        direction TB
        GroupClaim["Group"]
        RolesClaim["roles"]
    end
    subgraph Nod["fa:fa-shield-halved Nodinite"]
        direction TB
        Claim["fa:fa-key Claim"] --> Policy["fa:fa-shield-halved Policy"]
        Policy --> NRole["fa:fa-users-class Role"]
    end
    Attr --> GroupClaim
    Role --> RolesClaim
    Token -->|"matched"| Claim
    style KC fill:#FFD525
    style Token fill:#2678BD
    style Nod fill:#93d16d
</div>

*Diagram: a Keycloak user attribute or realm role becomes a claim in the access token; :Nodinite: matches it with a [Claim][Claims], and the [Policy][Policies] that holds the Claim grants its [Roles][].*

### :fa-puzzle-piece: What Reaches the Token

The sandbox's Keycloak realm is called `dev`, and the [Web Client][] signs in through its `webclient` client. That client puts these values in the token:

| In Keycloak | Claim in the token | Key of the :Nodinite: Claim | Example value |
| --- | --- | --- | --- |
| User attribute `Group` | `Group` | `Group` | `Admin` |
| Realm roles | `roles` | `http://schemas.microsoft.com/ws/2008/06/identity/claims/role` | `nodinite-finance` |

The Key of a `roles` claim is the long name, not `roles`: .NET renames the standard role claim before :Nodinite: compares, so a Claim with the Key `roles` never matches. See [How the Key is matched][Claim Key Matching].

### :fa-user-shield: The Sample Administrator

The sandbox ships with the user `Administrator`, whose attribute `Group` is `Admin`. The token therefore carries `Group` = `Admin`, the [Claim][Claims] that the sandbox's Policy for the Administrators [Role][Roles] requires. Give another user the same attribute, and that user is an administrator too.

Membership of the Keycloak **group** *Admin* is not the same thing. Keycloak writes group membership into the token as the group's full path, `Group` = `/Admin`, which doesn't match the Claim `Group` = `Admin`, so such a user gets no Role. Use the attribute.

### :fa-scale-balanced: Attribute or Realm Role? {#attribute-or-realm-role}

| | User attribute | Realm role |
| --- | --- | --- |
| Set on | Each user, as a key and a value | The realm, then assigned to users |
| Best for | Making a user an administrator, as `Administrator` is | Groups of users with the same access, such as a team |
| Claim Key in :Nodinite: | `Group` | `http://schemas.microsoft.com/ws/2008/06/identity/claims/role` |
| Rename later | Change it on every user | Change it once on the role |

## :fa-clipboard-check: Before You Start

* The sandbox is running; see [Install the Docker Sandbox][Install Docker Sandbox].
* You can sign in to the [Web Client][] as `Administrator` (password `P1ngP0ng`).
* You know what the new user should see: which [Roles][] to grant, or which Role to create with [Add or manage Role][].

## :fa-user-plus: Step 1: Add the User in Keycloak

1. Open the Keycloak admin console at `http://<environment name>.localhost:8080/admin`, for example `http://demosandbox.localhost:8080/admin`, with the **Keycloak (sign-in)** port you chose. Sign in with the Keycloak administrator: username `admin`, password `P1ngP0ng`. This account manages Keycloak only; it is not a :Nodinite: user. The console's yellow banner, *You are logged in as a temporary admin user*, is expected in the sandbox.
2. In the menu on the left, click **Manage realms**, then the realm **dev**. The **master** realm, marked *Current realm* at first, is Keycloak's own; :Nodinite: users never go there.

   ![The Manage realms page of the Keycloak admin console, with master marked Current realm and dev as a link (7.12)][3]  
   *Open **dev**: it holds the :Nodinite: users and the `webclient` client.*  

3. Open **Users** and click **Add user**. Enter the **Username**, and optionally the **Email**, **First name**, and **Last name**, then click **Create**.
4. Open the **Credentials** tab and click **Set password**. Enter the password twice, and switch **Temporary** off unless the user should choose a new password at the first sign-in. Click **Save**, then **Save password** in the *Set password?* dialog.

   ![The Set password dialog for contoso.finance with both password fields filled and Temporary off (7.12)][5]  
   *With **Temporary** off, the user signs in with this password, without a password change.*  

>[!IMPORTANT]
>Keycloak keeps what you change in its admin console, such as users and passwords, inside its container. When the container is recreated, for example by an update that brings a new Keycloak, Keycloak imports the shipped realm again and your changes are gone. Note the users you add, so you can add them again.

## :fa-tag: Step 2: Give the User a Value in the Token

Do one of these, depending on your choice in [Attribute or Realm Role?](#attribute-or-realm-role).

### Make the User an Administrator

1. On the user, open the **Attributes** tab.
2. Click **Add attributes**, enter the **Key** `Group` and the **Value** `Admin`, and click **Save**.

   ![The Attributes tab of the user contoso.admin with the Key Group and the Value Admin, before Save (7.12)][4]  
   *The attribute `Group` = `Admin` is what makes `Administrator` an administrator, too.*  

The user now matches the same Claim as `Administrator`. Skip to [Step 4](#step-4-sign-in-as-the-new-user).

### Give the User a Realm Role

1. Open **Realm roles**, click **Create role**, enter a **Role name** such as `nodinite-finance`, and save. Skip this when the role exists.
2. Open the user, then the **Role mapping** tab, and click **Assign role**.
3. In the menu that opens, choose **Realm roles**, tick the role, and click **Assign**.

## :fa-shield-halved: Step 3: Match the Value in Nodinite

Sign in to the [Web Client][] as `Administrator`, and in **Administration**:

1. **Add the Claim**: under **Claims**, add a Claim with the Key `http://schemas.microsoft.com/ws/2008/06/identity/claims/role` and the Value `nodinite-finance`. See [Add or manage Claim][].
2. **Add the Policy**: under **Policies**, add a Policy, such as *Contoso: Finance Users*, that holds the Claim and grants the [Role][Roles] the user should have. See [Add or manage Policy][].
3. **Check the Role**: its permission sets decide what the user sees: [Log Views][Permission Set for Log Views], [Monitor Views][Permission Set for Monitor Views], the [Repository Model][Permission Set for the Repository Model], and [C4 Diagram Sets][Permission Set for C4 Diagram Sets]. A Role with [Log Views][] but without the Log permission gives the user *403 Forbidden, Access level Log Views is required* on **Log**. See [Add or manage Role][].

![As Administrator, add the Claim with the role key and the value nodinite-finance, then the Policy Contoso: Finance Users with that Claim and the Role Contoso: Finance; signed in as contoso.finance, only the Role's two Log Views show, animated walkthrough (7.12)][2]  
*Animated walkthrough: the Claim and Policy in :Nodinite:, then the new user's view: exactly the [Log Views][Permission Set for Log Views] of the Role.*  

>[!WARNING]
>**Policies can lock everyone out.** A Policy matches only when the token carries **all** its Claims, so a Claim that Keycloak never sends matches nobody, administrators included. A Policy with no Claims matches everyone. Never change the Policy that makes `Administrator` an administrator, and keep `Administrator` signed in while you test. Details: [What is a Policy?][Policies]

## :fa-right-to-bracket: Step 4: Sign In as the New User {#step-4-sign-in-as-the-new-user}

1. Open a private browser window, so you stay signed in as `Administrator` in the other one.
2. Open the [Web Client][] address, such as `http://demosandbox.localhost:8081`, and sign in with the new user's username and password.
3. Check that the user sees what the Role grants, and nothing more.

:Nodinite: keeps each user's Policies and Roles for about 15 seconds, so a Claim or Policy change reaches a signed-in user quickly, without a new sign-in. A change in Keycloak, such as a new attribute or realm role, reaches :Nodinite: with the user's next token: sign out and in again.

### :fa-circle-question: The User Signs In but Sees Nothing

* The token doesn't carry the value: check the attribute key (`Group`, case as shown) or the realm role assignment in Keycloak. Membership of the Keycloak group *Admin* gives `/Admin`, not `Admin`.
* The user sees *Access level Log Views is required*: the Role has Log Views, but not the Log permission.
* The Claim Key is `roles` instead of the long role Key; see [How the Key is matched][Claim Key Matching].
* The Policy holds a second Claim that the user doesn't match.

## :fa-hand-point-right: Next Steps

* :fa-key: [Add or manage Claim][]  
* :fa-shield-halved: [Add or manage Policy][]  
* :fa-users-class: [Add or manage Role][]  
* :fa-rotate: [Update the Docker Sandbox][Update Docker Sandbox]  

## :fa-link-horizontal: Related Topics

* :fab fa-docker: [Run Nodinite with Docker Compose][Docker Sandbox]  
* :fa-rocket: [Install the Docker Sandbox][Install Docker Sandbox]  
* :fa-key: [What is a Claim?][Claims]  
* :fa-shield-halved: [What is a Policy?][Policies]  
* :fa-users-class: [What is a Role?][Roles]  
* :fa-lock: [Install Nodinite v7 - OpenID][Install OpenID]  
* :fa-user-shield: [Access Management][]  

[1]:{ndm}/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak_AddUser.gif
[2]:{ndm}/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Sandbox_ClaimPolicy_SignIn.gif
[3]:{ndm}/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak/Keycloak_RealmDev.png
[4]:{ndm}/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak/Keycloak_UserAttributes.png
[5]:{ndm}/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak/Keycloak_SetPassword.png

[Access Management]:{ndr}/Administration/3.%20Access%20Management/Overview.md
[Add or manage Claim]:{ndr}/Administration/3.%20Access%20Management/4.%20Claims/Features/Add%20or%20manage%20Claim.md
[Add or manage Policy]:{ndr}/Administration/3.%20Access%20Management/5.%20Policies/Features/Add%20or%20manage%20Policy.md
[Add or manage Role]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/Add%20or%20manage%20Role.md
[Claim Key Matching]:{ndr}/Administration/3.%20Access%20Management/4.%20Claims/Features/What%20is%20a%20Claim.md#fa-right-left-how-the-key-is-matched
[Claims]:{ndr}/Administration/3.%20Access%20Management/4.%20Claims/Features/What%20is%20a%20Claim.md
[Docker Sandbox]:{ndr}/Install%20and%20Update/Troubleshooting/Docker/Overview.md
[Install Docker Sandbox]:{ndr}/Install%20and%20Update/Troubleshooting/Docker/Install%20the%20Docker%20Sandbox.md
[Install OpenID]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20-%20OpenID.md
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.md
[Permission Set for C4 Diagram Sets]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/Permission%20Set%20for%20C4%20Diagram%20Sets.md
[Permission Set for Log Views]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/Permission%20Set%20for%20Log%20Views.md
[Permission Set for Monitor Views]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/Permission%20Set%20for%20Monitor%20Views.md
[Permission Set for the Repository Model]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/Permission%20Set%20for%20the%20Repository%20Model.md
[Policies]:{ndr}/Administration/3.%20Access%20Management/5.%20Policies/Features/What%20is%20a%20Policy.md
[Roles]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/What%20is%20a%20Role.md
[Update Docker Sandbox]:{ndr}/Install%20and%20Update/Troubleshooting/Docker/Update%20the%20Docker%20Sandbox.md
[Web API]:{ndr}/Core%20Services/Web%20API/Overview.md
[Web Client]:{ndr}/Core%20Services/Web%20Client/Overview.md