Keycloak Timeline Setup - Configuration Reference¶
Overview¶
The Timeline Navigation feature needs a bsn claim in the JWT: the frontend takes the citizen's BSN (Burgerservicenummer) from it, and the backend checks a citizen's lookup against it. This page explains how the claim gets there.
Why This Is Needed¶
The Problem¶
- Timeline needs a BSN to fetch BRP data
- The token carries none by default
- On test realms the BSN is a user attribute; where DigiD is real it is to come from the DigiD subject
The Solution¶
A protocol mapper puts the user attribute bsn in the token as bsn. The realm export has it; scripts/keycloak-add-brp-raadpleger.sh adds it, with the role and the test citizens' attribute, to an existing realm. The steps below do the mapper by hand.
Configuration Steps¶
1. Access Keycloak Admin Console¶
URL: http://localhost:8080 (local)
https://acc.keycloak.open-regels.nl (ACC)
https://keycloak.open-regels.nl (PROD)
Login: admin / <admin-password>
2. Navigate to Client Scopes¶
- Select Realm:
ronl(top-left dropdown) - In left menu, click Clients
- Find and click
ronl-business-api - Click Client scopes tab
- Click on
ronl-business-api-dedicated(in the table)
3. Add Protocol Mapper¶
- Click Mappers tab
- Click Add mapper button
- Select By configuration
- Select User Attribute
4. Configure Mapper¶
Fill in the form:
| Field | Value |
|---|---|
| Name | bsn |
| Mapper Type | User Attribute |
| User Attribute | bsn |
| Token Claim Name | bsn |
| Claim JSON Type | String |
| Add to ID token | โ๏ธ ON |
| Add to access token | โ๏ธ ON |
| Add to userinfo | โ๏ธ ON |
| Multivalued | โ OFF |
- Click Save
Verification¶
Test the Configuration¶
- Login to MijnOmgeving with a test citizen
- Open browser DevTools (F12)
- Go to the Network tab and select a request to
/v1/ - Copy the token from its
Authorization: Bearerheader and decode the payload, as under Inspecting a token in the browser - Verify the token contains:
{
"bsn": "999992235",
"municipality": "utrecht",
"sub": "uuid-here",
"realm_access": { "roles": ["citizen"] },
"loa": "hoog"
}
If It's Not Working¶
Token missing bsn:
- Clear browser cache and cookies
- Logout and login again (force new token)
- Verify mapper is saved correctly
- Check mapper is in
ronl-business-api-dedicatedscope (not a different scope) - Check the user has the attribute
bsn
Still not working:
- Restart Keycloak:
docker compose restart keycloak - Check Keycloak logs:
docker compose logs keycloak
Production Considerations¶
DigiD Integration¶
In production with real DigiD, you'll also need:
- BSN Mapper โ Maps the DigiD subject to the
bsnclaim - Municipality Mapper โ Maps organization to
municipalityclaim - LoA Mapper โ Maps DigiD assurance level to
loaclaim
See Authentication & IAM.
Security Notes¶
bsnis personal data: keep it out of logs. The BRP route's own log lines carry none; its audit entry does, on purpose. The frontend still writes the decoded token, with this claim, to the browser console (#477)- โ Token lifetime should be 15 minutes maximum
- โ Tokens must be validated on every request
Troubleshooting¶
Mapper Not Appearing in Token¶
Check:
- Mapper is added to correct client scope (
ronl-business-api-dedicated) - Client scope is assigned to client (
ronl-business-api) - "Add to access token" is enabled
- User has logged out and back in (to get new token)
- User has the attribute
bsn. A realm whose user profile drops unmanaged attributes loses the value silently; the read-back ofscripts/keycloak-add-brp-raadpleger.shcatches that
Wrong Value in Token¶
If bsn holds another value than expected:
- Check the User Attribute field is set to
bsn - Check the value of the attribute on the user in Keycloak's Users section
If bsn is missing:
- The user may not have the attribute
- Check user attributes in Keycloak Users section
Multiple Mappers Conflict¶
If you have multiple mappers for bsn:
- Delete all except one
- Logout/login to refresh token
- Verify only one
bsnclaim in token
Related Configuration¶
Other Timeline-Related Settings¶
Beyond this mapper, ensure these are also configured:
- Shared Package Types โ
KeycloakUserandAuthenticatedUserincludebsn - Backend tsconfig โ Removed
composite: true(see Technical Architecture)
Test Users Setup¶
Verify test users have correct attributes:
{
"username": "test-citizen-utrecht",
"attributes": {
"municipality": ["utrecht"],
"assurance_level": ["hoog"],
"bsn": ["999992235"]
},
"realmRoles": ["citizen"]
}
Import test users from: config/keycloak/ronl-realm.json
Configuration Checklist¶
Use this checklist when setting up timeline in a new environment:
- Keycloak realm
ronlexists - Client
ronl-business-apiexists - Client scope
ronl-business-api-dedicatedexists - Protocol mapper
bsnโbsncreated - Mapper enabled for access token, ID token, userinfo
- Test citizen has the attribute
bsn - Token verified to contain
bsn - Timeline feature tested and working
- Documentation updated with environment-specific URLs
Realm Export/Import¶
Exporting Realm with Mapper¶
To export realm configuration including the mapper:
# Inside Keycloak container
/opt/keycloak/bin/kc.sh export \
--dir /tmp/export \
--realm ronl \
--users realm_file
# Copy from container
docker cp keycloak:/tmp/export/ronl-realm.json ./config/keycloak/
Importing Realm¶
# From project root
docker compose exec keycloak \
/opt/keycloak/bin/kc.sh import \
--file /opt/keycloak/data/import/ronl-realm.json
Note: Manual mapper configuration is recommended over import to avoid UUID mismatches.
API Impact¶
Before Configuration¶
JWT Token:
Timeline Behavior:
- The Tijdlijn tab reads Geen tijdlijn gegevens beschikbaar voor deze gebruiker
- A direct call to
POST /v1/brp/personenat levelhooganswers403 BSN_CLAIM_MISSING
After Configuration¶
JWT Token:
{
"sub": "uuid-abc-123",
"bsn": "999992235",
"municipality": "utrecht",
"realm_access": { "roles": ["citizen"] }
}
Timeline Behavior:
- โ Fetches person data from BRP API for the BSN in the claim
- โ Timeline loads successfully