---
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.
---

# <i class="fal fa-users" aria-hidden="true"></i> Add Users and Claims in Keycloak

Give colleagues their own sign-in to the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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.*  

## <i class="fal fa-diagram-project" aria-hidden="true"></i> Understanding How a Keycloak User Gets Access

<span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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; <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> matches it with a [Claim][Claims], and the [Policy][Policies] that holds the Claim grants its [Roles][].*

### <i class="fal fa-puzzle-piece" aria-hidden="true"></i> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> compares, so a Claim with the Key `roles` never matches. See [How the Key is matched][Claim Key Matching].

### <i class="fal fa-user-shield" aria-hidden="true"></i> 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.

<h3 id="attribute-or-realm-role"><i class="fal fa-scale-balanced" aria-hidden="true"></i> Attribute or Realm Role?</h3>

| | 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> | `Group` | `http://schemas.microsoft.com/ws/2008/06/identity/claims/role` |
| Rename later | Change it on every user | Change it once on the role |

## <i class="fal fa-clipboard-check" aria-hidden="true"></i> 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][].

## <i class="fal fa-user-plus" aria-hidden="true"></i> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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; <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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.*  

<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p>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.</p></div>
</aside>

## <i class="fal fa-tag" aria-hidden="true"></i> 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**.

## <i class="fal fa-shield-halved" aria-hidden="true"></i> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>, then the new user's view: exactly the [Log Views][Permission Set for Log Views] of the Role.*  

<aside aria-label="Warning" class="nodinite-note nodinite-note--warning">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-triangle-exclamation"></i> Warning</p>
<div class="nodinite-note__content"><p><strong>Policies can lock everyone out.</strong> A Policy matches only when the token carries <strong>all</strong> 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 <code>Administrator</code> an administrator, and keep <code>Administrator</code> signed in while you test. Details: <a href="https://docs.nodinite.com/administration/access-management/policies/features/what-is-a-policy/">What is a Policy?</a></p></div>
</aside>

<h2 id="step-4-sign-in-as-the-new-user"><i class="fal fa-right-to-bracket" aria-hidden="true"></i> Step 4: Sign In as the New User</h2>

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.

<span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> with the user's next token: sign out and in again.

### <i class="fal fa-circle-question" aria-hidden="true"></i> 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.

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-key" aria-hidden="true"></i> [Add or manage Claim][]  
* <i class="fal fa-shield-halved" aria-hidden="true"></i> [Add or manage Policy][]  
* <i class="fal fa-users-class" aria-hidden="true"></i> [Add or manage Role][]  
* <i class="fal fa-rotate" aria-hidden="true"></i> [Update the Docker Sandbox][Update Docker Sandbox]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fab fa-docker" aria-hidden="true"></i> [Run Nodinite with Docker Compose][Docker Sandbox]  
* <i class="fal fa-rocket" aria-hidden="true"></i> [Install the Docker Sandbox][Install Docker Sandbox]  
* <i class="fal fa-key" aria-hidden="true"></i> [What is a Claim?][Claims]  
* <i class="fal fa-shield-halved" aria-hidden="true"></i> [What is a Policy?][Policies]  
* <i class="fal fa-users-class" aria-hidden="true"></i> [What is a Role?][Roles]  
* <i class="fal fa-lock" aria-hidden="true"></i> [Install Nodinite v7 - OpenID][Install OpenID]  
* <i class="fal fa-user-shield" aria-hidden="true"></i> [Access Management][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak_AddUser.gif
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Sandbox_ClaimPolicy_SignIn.gif
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak/Keycloak_RealmDev.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak/Keycloak_UserAttributes.png
[5]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/IMUpdate/Troubleshooting/Docker/Keycloak/Keycloak_SetPassword.png

[Access Management]:https://docs.nodinite.com/administration/access-management/overview/
[Add or manage Claim]:https://docs.nodinite.com/administration/access-management/claims/features/add-or-manage-claim/
[Add or manage Policy]:https://docs.nodinite.com/administration/access-management/policies/features/add-or-manage-policy/
[Add or manage Role]:https://docs.nodinite.com/administration/access-management/roles/features/add-or-manage-role/
[Claim Key Matching]:https://docs.nodinite.com/administration/access-management/claims/features/what-is-a-claim/#fa-right-left-how-the-key-is-matched
[Claims]:https://docs.nodinite.com/administration/access-management/claims/features/what-is-a-claim/
[Docker Sandbox]:https://docs.nodinite.com/install-and-update/troubleshooting/docker/overview/
[Install Docker Sandbox]:https://docs.nodinite.com/install-and-update/troubleshooting/docker/install-the-docker-sandbox/
[Install OpenID]:https://docs.nodinite.com/install-and-update/getting-started/version-7/install-nodinite-v7-openid/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[Permission Set for C4 Diagram Sets]:https://docs.nodinite.com/administration/access-management/roles/features/permission-set-for-c4-diagram-sets/
[Permission Set for Log Views]:https://docs.nodinite.com/administration/access-management/roles/features/permission-set-for-log-views/
[Permission Set for Monitor Views]:https://docs.nodinite.com/administration/access-management/roles/features/permission-set-for-monitor-views/
[Permission Set for the Repository Model]:https://docs.nodinite.com/administration/access-management/roles/features/permission-set-for-the-repository-model/
[Policies]:https://docs.nodinite.com/administration/access-management/policies/features/what-is-a-policy/
[Roles]:https://docs.nodinite.com/administration/access-management/roles/features/what-is-a-role/
[Update Docker Sandbox]:https://docs.nodinite.com/install-and-update/troubleshooting/docker/update-the-docker-sandbox/
[Web API]:https://docs.nodinite.com/core-services/web-api/overview/
[Web Client]:https://docs.nodinite.com/core-services/web-client/overview/