Realms API
The Realms API provides endpoints for managing realms (multi-tenancy units) and realm-level configuration. Realms are isolated namespaces for users, clients, and configuration.
Base URL
/admin/realms
Authentication
Most realm endpoints require super-admin role access:
-H "x-admin-api-key: your-api-key-here"
Admins with the super-admin role (and the admin API key) can manage all realms. A realm admin can list and read the realms assigned to them; creating, updating, deleting and importing realms needs super-admin.
List Realms
GET /admin/realms
Returns the realms the caller may read, as a JSON array.
Request Example
curl -X GET "http://localhost:3000/admin/realms" \
-H "x-admin-api-key: your-api-key-here"
Response
[
{
"id": "realm-uuid-123",
"name": "master",
"displayName": "Master Realm",
"enabled": true,
"registrationAllowed": true,
"accessTokenLifespan": 300,
"refreshTokenLifespan": 1800,
"offlineTokenLifespan": 2592000,
"...": "...",
"createdAt": "2023-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z"
}
]
Each entry carries all realm settings except secrets; the example is shortened.
Create Realm
POST /admin/realms
Creates a new realm. Requires super-admin role.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique realm name (lowercase, no spaces) |
displayName | string | No | Human-readable name |
enabled | boolean | No | Enable realm (default: true) |
registrationAllowed | boolean | No | Allow user self-registration (default: true) |
captchaEnabled | boolean | No | Require a CAPTCHA for self-registration. When true, captchaProvider and that provider's site key and secret key are required (400 otherwise); the secret may instead come from RECAPTCHA_SECRET_KEY / HCAPTCHA_SECRET_KEY. See Self-Registration and CAPTCHA |
captchaProvider | string | No | recaptcha (reCAPTCHA v3) or hcaptcha |
recaptchaSiteKey, recaptchaSecretKey | string | No | reCAPTCHA v3 keys (the secret is encrypted at rest) |
hcaptchaSiteKey, hcaptchaSecretKey | string | No | hCaptcha keys (the secret is encrypted at rest) |
captchaScoreThreshold | number | No | Lowest reCAPTCHA v3 score accepted, 0 to 1 (default 0.5) |
passwordMinLength | integer | No | Minimum password length (default 8) |
passwordRequireUppercase, passwordRequireLowercase, passwordRequireDigits, passwordRequireSpecialChars | boolean | No | Character class requirements (default false) |
passwordHistoryCount | integer | No | Recent passwords that cannot be reused (default 0). The current password always counts, including a password imported from another IdP; see Password history |
passwordMaxAgeDays | integer | No | Password expiry in days (default 0, never) |
accessTokenLifespan | integer | No | Access token lifetime in seconds (default 300) |
refreshTokenLifespan | integer | No | Refresh token lifetime in seconds (default 1800) |
offlineTokenLifespan | integer | No | Lifetime of an offline session and its offline_access refresh tokens, counted from sign-in (default 2592000, 30 days). There is no separate offline idle timeout. |
maxSessionsPerUser | integer | No | Concurrent sessions per user (default 10, 0 = no limit). The oldest is ended when a new one would go over. Offline sessions don't count and are never ended by it. |
ssoSessionIdleTimeout | integer | No | Idle timeout in seconds (default 0, off). A browser SSO session not used for this long ends, and a normal refresh token not used for this long expires; offline tokens are not affected. 0 or at least 60; make it longer than accessTokenLifespan. See Idle timeout. |
bruteForceEnabled | boolean | No | Temporary lockout after repeated failed sign-ins. Defaults to true for a new realm. |
maxLoginFailures | integer | No | Failures within failureResetTime that lock the account (default 10) |
lockoutDuration | integer | No | Lockout length in seconds (default 300) |
failureResetTime | integer | No | Window in seconds in which failures are counted (default 900) |
permanentLockoutAfter | integer | No | Lockouts after which the account is disabled; 0 (default) never disables it |
smtpHost, smtpPort, smtpUser, smtpPassword, smtpFrom, smtpSecure | No | SMTP settings (smtpPort default 587) | |
emailProvider, emailProviderConfig | No | smtp, resend, sendgrid, mailgun or postmark, and its settings | |
themeName, loginTheme, accountTheme, emailTheme, theme | No | Theme selection and color overrides |
The DTO has more settings (MFA, WebAuthn, SMS, magic links, events, locales, sessions, CAPTCHA above); the server's /api lists them all. A field the DTO does not know is rejected with 400.
Password history
With passwordHistoryCount above 0, a new password is refused ("Password was used recently") when it matches the user's current password or one of their last passwordHistoryCount passwords. It applies to every way a password changes: the account console, the expired-password page, a reset by email (checked before the link is used up, so the user can try another password with the same link) and an admin setting it (PUT /admin/realms/{realm}/users/{id}/reset-password, 400).
The current password counts even when it is not in the stored history: a password imported from Keycloak, Auth0, Authentik or Zitadel, one set while the history was off, or one rehashed at sign-in. When a password is replaced, the old hash is added to the history if it was not there yet, with its algorithm, so an imported password stays refused for the next changes too. Imported hashes are checked in their own format (bcrypt, PBKDF2, and the unlabelled PBKDF2 rows imported before 0.11.0). Before 0.13.0 the imported password was not part of the history, so a migrated user could "change" their password to the same one.
Request Example
curl -X POST "http://localhost:3000/admin/realms" \
-H "x-admin-api-key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"name": "partner-portal",
"displayName": "Partner Portal",
"registrationAllowed": false,
"passwordMinLength": 10,
"passwordRequireSpecialChars": true,
"accessTokenLifespan": 600,
"bruteForceEnabled": true,
"maxLoginFailures": 5
}'
Response
{
"id": "realm-uuid-789",
"name": "partner-portal",
"displayName": "Partner Portal",
"enabled": true,
"registrationAllowed": false,
"accessTokenLifespan": 600,
"refreshTokenLifespan": 1800,
"offlineTokenLifespan": 2592000,
"passwordMinLength": 10,
"passwordRequireSpecialChars": true,
"bruteForceEnabled": true,
"maxLoginFailures": 5,
"lockoutDuration": 300,
"failureResetTime": 900,
"permanentLockoutAfter": 0,
"...": "...",
"createdAt": "2024-02-01T10:00:00Z",
"updatedAt": "2024-02-01T10:00:00Z"
}
Get Realm
GET /admin/realms/:realmName
Returns a single realm by name.
Request Example
curl -X GET "http://localhost:3000/admin/realms/partner-portal" \
-H "x-admin-api-key: your-api-key-here"
Response
{
"id": "realm-uuid-789",
"name": "partner-portal",
"displayName": "Partner Portal",
"enabled": true,
"registrationAllowed": false,
"accessTokenLifespan": 600,
"refreshTokenLifespan": 1800,
"offlineTokenLifespan": 2592000,
"passwordMinLength": 10,
"passwordRequireSpecialChars": true,
"bruteForceEnabled": true,
"maxLoginFailures": 5,
"lockoutDuration": 300,
"failureResetTime": 900,
"permanentLockoutAfter": 0,
"...": "...",
"createdAt": "2024-02-01T10:00:00Z",
"updatedAt": "2024-02-01T10:00:00Z"
}
Update Realm
PUT /admin/realms/:realmName
Updates an existing realm. Requires super-admin role. Only the fields you send change: PUT and PATCH behave the same. The name cannot be changed; sending name is rejected with 400.
Request Example
curl -X PUT "http://localhost:3000/admin/realms/partner-portal" \
-H "x-admin-api-key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"displayName": "Partner Portal Updated",
"registrationAllowed": false,
"passwordMinLength": 12
}'
Partial Update Realm
PATCH /admin/realms/:realmName
Partially updates a realm. Only provided fields are modified.
Request Example
curl -X PATCH "http://localhost:3000/admin/realms/partner-portal" \
-H "x-admin-api-key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"registrationAllowed": true,
"passwordMinLength": 8
}'
Delete Realm
DELETE /admin/realms/:realmName
Permanently deletes a realm and all associated data (users, clients, roles, etc.). Requires super-admin role.
This action is irreversible. Ensure you have exported any important data before deleting a realm.
Request Example
curl -X DELETE "http://localhost:3000/admin/realms/partner-portal" \
-H "x-admin-api-key: your-api-key-here"
Response
Returns HTTP 204 No Content on success.
Export Realm
GET /admin/realms/:realmName/export
Exports the realm's configuration as JSON (format version: 2). Import the file on the same or another Idenplane server with Import Realm.
Query Parameters
| Parameter | Default | Description |
|---|---|---|
includeUsers | false | Include users, their role and group mappings, custom attribute values and organization memberships. Never their passwords or MFA factors. |
includeSecrets | false | Include secrets (see Secrets). |
Request Example
# Configuration only, no secrets
curl "http://localhost:3000/admin/realms/partner-portal/export" \
-H "x-admin-api-key: your-api-key-here"
# With users, still without secrets
curl "http://localhost:3000/admin/realms/partner-portal/export?includeUsers=true" \
-H "x-admin-api-key: your-api-key-here"
# Everything, for a full migration
curl "http://localhost:3000/admin/realms/partner-portal/export?includeUsers=true&includeSecrets=true" \
-H "x-admin-api-key: your-api-key-here"
What is included
The export contains every realm setting and every client setting. An allow-list in the code covers every database column. A test fails when a new column is neither exported nor excluded with a reason, so a new setting cannot be left out by mistake.
| Section | Contents |
|---|---|
realm | All realm settings: token lifespans, email (SMTP and provider), password policy, brute force, registration, CAPTCHA, email verification, MFA, WebAuthn, SMS MFA and OTP, magic links, impersonation, events and their retention, rate limits, themes and locales, sessions, adaptive authentication, SCIM, account deletion, mTLS, auth flows. browserFlow names the bound flow. |
authenticationFlows | Flows with their steps. |
clientScopes | Scopes with their protocol mappers. |
clients | All client settings: post-logout redirect URIs, step-up (requiredAcr), token endpoint authentication, the tlsClientAuth* rules and certificate-bound tokens. Also the bound flow (authFlow), the default and optional scopes, the service account with its roles and groups (serviceAccount) and the registered certificates (tlsCertificates). |
roles, groups | Realm and client roles, and groups with their parent and role mappings. |
identityProviders, samlServiceProviders, userFederations | Brokering, SAML service providers, and LDAP federation with its mappers. |
tlsTrustAnchors, tlsRevokedCertificates | The realm's certificate authorities and its deny-list. |
customAttributes, registrationFields, organizations, consentCategories, themes | Profile attributes, the registration form, organizations with their SSO connections, consent categories with their policies, and theme builder themes. |
webhooks, auditLogStreams, policies, continuousRiskPolicies, scimAttributeMappings, serviceAccounts, nhiCredentialPolicies, proxyApplications | The rest of the realm configuration. |
users | Only with includeUsers=true. |
omitted | What the export left out, and why. The import ignores it. |
References between objects use names, never database ids:
- a flow by name;
- a client by
clientId; - a scope by name;
- a role by name and
clientId; - a group by name;
- a user by username.
Never exported:
- The realm's signing keys. The imported realm gets a new key pair, so tokens issued by the old realm are not valid there.
- Password hashes and other user credentials: TOTP, passkeys, recovery codes and enrolled phone numbers.
- Sessions, tokens and one-time codes.
- API keys and SCIM tokens.
- Brute-force and risk counters.
- All event and audit logs.
- NHI identities and their credentials. Their OAuth clients are listed under
omitted. - The theme builder's version history. Each theme's current content is exported.
Secrets
Without includeSecrets, the file contains no secrets. With it, the file contains:
- each client's secret hash. The secret itself cannot be recovered; the hash keeps the same secret working after import;
- the SMTP password, the CAPTCHA secret keys, and the email and SMS provider credentials, decrypted;
- identity provider client secrets, LDAP bind credentials and webhook signing secrets, decrypted;
- audit stream HTTP headers and organization SSO connection configuration, with their encrypted values decrypted. Without
includeSecretsthese two are left out whole.
Realm signing keys and TOTP seeds are never exported; the imported realm gets a new key pair.
Values encrypted at rest are exported decrypted. The importing server encrypts them again with its own WEBHOOK_SECRET_KEY, so the two servers do not need the same key.
A file made with includeSecrets holds live credentials. Store and transfer it as you would a password vault.
A file without secrets still imports, and the response lists warnings. Objects that cannot work without their secret are imported disabled:
- identity providers;
- LDAP federations;
- organization SSO connections;
- webhooks, which also get a new random secret.
Confidential clients that authenticate with a secret have none until you regenerate it.
Response
{
"version": 2,
"secretsIncluded": false,
"usersIncluded": false,
"realm": { "name": "partner-portal", "displayName": "Partner Portal", "browserFlow": "browser-mfa", "...": "..." },
"authenticationFlows": [{ "name": "browser-mfa", "steps": ["..."] }],
"clients": [{ "clientId": "portal", "authFlow": null, "defaultScopes": ["openid"], "serviceAccount": null, "tlsCertificates": [], "...": "..." }],
"roles": [{ "name": "admin", "description": null, "clientId": null }],
"groups": [{ "name": "staff", "parentName": null, "roles": [{ "name": "admin", "clientId": null }] }],
"...": "...",
"omitted": []
}
The full shape is in the OpenAPI document (/api).
Import Realm
POST /admin/realms/import
Creates a realm from an export file. Requires the super-admin role.
Query Parameters
| Parameter | Default | Description |
|---|---|---|
overwrite | false | Replace an existing realm with the same name |
Request Example
curl -X POST "http://localhost:3000/admin/realms/import?overwrite=true" \
-H "x-admin-api-key: your-api-key-here" \
-H "Content-Type: application/json" \
-d @realm-export.json
To import under another name, change realm.name in the file.
The request body may be up to 10 MB, the limit of the import endpoints (every other endpoint keeps 100 KB). A larger file is refused with 413 Payload Too Large.
Validation and safety
-
The whole file is checked before anything is written. The checks cover types, allowed values, unknown fields, references that do not resolve, duplicate names, client authentication rules and certificates. Every authentication flow goes through the same validator as the flow API. Any problem returns
400with every problem and its path:{"statusCode": 400,"message": "Invalid realm import: clients[0].authFlow: no flow named 'browser-mfa' in authenticationFlows","errors": [{ "path": "clients[0].authFlow", "message": "no flow named 'browser-mfa' in authenticationFlows" }]} -
One transaction. If anything fails, nothing is created.
-
overwriteis safe. The old realm is deleted inside the same transaction, so a failed import leaves it exactly as it was. A successful import replaces all of the old realm's data, including users, sessions and signing keys. Tokens the old realm issued stop being valid. -
Defaults. A field missing from the file takes the server's default, as for a new realm.
-
Wildcard origins. The web origin
"*"is removed from clients, with a warning. -
Authorization policies are checked like the policies API checks them: an unknown operator, a value the operator cannot use (an invalid CIDR or regular expression,
inwithout an array), or an unknowneffectorlogicis a400with its path, for examplepolicies[0].subjectConditions[1].
Response
{
"realmName": "partner-portal",
"version": 2,
"clientsImported": 3,
"rolesImported": 5,
"groupsImported": 2,
"scopesImported": 7,
"idpsImported": 1,
"usersImported": 0,
"flowsImported": 1,
"warnings": []
}
Importing a realm whose name already exists returns 409 unless overwrite=true is set.
Version compatibility
| File | Import |
|---|---|
version: 2 | Strict: validated as above. |
version: 1 (files from Idenplane before format 2, including "1.0") | Imported with the same field mapping as before, in one transaction. References that do not resolve are skipped, as before. |
| Any other version | 400. |
Version 1 files never contained the settings that format 2 added, so those settings take their defaults. After importing a version 1 file, check the realm's sign-in protection, rate limits, CAPTCHA, registration, themes and other settings. Export again from the current server to get a complete version 2 file.
Before you upgrade
- Scripts that read export files. The file is now
version: 2. Scope assignments moved from the top-levelclientScopeAssignmentsinto each client'sdefaultScopesandoptionalScopes, and the file has many new sections. Update any script that reads or edits export files. - Unknown versions are refused. An import accepts
version1 (1,"1","1.0") or 2 (2,"2","2.0") and answers400to anything else. A version 1 section that is not an array of objects is also400now. - Version 2 imports are strict. A realm that the server holds today can fail to import again in two cases:
- Flows that fail today's flow validator. Flows created before the stricter validation were not migrated. Run
POST /admin/realms/{realm}/auth-flows/{id}/validateon each flow and fix it before exporting. - Realm names that are not lowercase slugs, which a version 1 import could create. Change
realm.namein the file.
- Flows that fail today's flow validator. Flows created before the stricter validation were not migrated. Run
- Realms already moved with an export file kept the defaults for every setting version 1 did not carry. Check them, or export and import them again.
Signing Keys
Each realm signs its access tokens, ID tokens, logout tokens and SAML responses with an RSA key (RS256). A realm can publish more than one key:
- The current key is the newest. Everything new is signed with it.
- Previous keys stay published in the realm's JWKS (
/realms/{realm}/protocol/openid-connect/certs) and SAML metadata, so what they signed keeps verifying, until an admin retires them.
A token is verified with the published key its kid header names. A token whose key was retired, or whose kid the realm does not publish, is refused everywhere: userinfo, introspection, revocation, logout and the admin console. The console tab is Realm settings → Signing keys.
All three endpoints need an admin. Rotating and retiring need super-admin. Both are written to the server log, and recorded as admin events when the realm records them (adminEventsEnabled).
List Signing Keys
GET /admin/realms/:realmName/keys
[
{ "kid": "6f1c…", "algorithm": "RS256", "createdAt": "2026-12-01T09:00:00.000Z", "current": true },
{ "kid": "0b9e…", "algorithm": "RS256", "createdAt": "2026-06-01T09:00:00.000Z", "current": false }
]
There is no key material in the response. The public keys are in the JWKS.
Rotate the Signing Key
POST /admin/realms/:realmName/keys/rotate
| Field | Type | Description |
|---|---|---|
retirePrevious | boolean | Optional, default false. Also retire every other key of the realm at once. |
A new key is generated and becomes the current key. Every process picks it up with its next request.
curl -X POST "http://localhost:3000/admin/realms/partner-portal/keys/rotate" \
-H "x-admin-api-key: your-api-key-here" -H "Content-Type: application/json" -d '{}'
{ "current": "6f1c…", "retired": [], "keys": [ … ] }
A planned rotation (retirePrevious false): nothing stops working.
- Relying parties that read the JWKS pick up the new key by its
kid. - SAML service providers that refresh the metadata trust both keys.
- Retire the previous key once nothing it signed is still in use. Wait at least the realm's longest token lifetime, and longer if a client verifies against a pinned key or certificate.
A key that leaked (retirePrevious true): every other key is deleted in the same step.
- Every access token, ID token and logout token signed before stops verifying here.
- Every SAML assertion signed before stops verifying too.
- Users sign in again. Their refresh tokens and SSO sessions are not tokens signed with the key, so they are not ended by the rotation; end them from the sessions API if the incident calls for it.
- Relying parties that cache the JWKS refuse new tokens until they fetch it again.
Retire a Signing Key
DELETE /admin/realms/:realmName/keys/:kid
The key is deleted, private half included. It leaves the JWKS and the SAML metadata, and nothing it signed verifies any more. This cannot be undone.
200with{ "retired": "<kid>", "keys": [ … ] }.409for the current key: rotate first.404for a key the realm does not have.
Before you rotate
- Relying parties with a pinned key must add the new key before the old one is retired. A pinned key is a public key or certificate copied into their configuration, not read from the JWKS or metadata.
- SAML service providers that do not read the metadata need the new key too. Its public key is in the metadata as soon as you rotate.
- Import and export do not carry keys. An imported realm gets its own new key.
List Available Themes
GET /admin/realms/themes
Returns list of themes available for realm customization.
Request Example
curl -X GET "http://localhost:3000/admin/realms/themes" \
-H "x-admin-api-key: your-api-key-here"
Response
[
{
"name": "idenplane",
"displayName": "Idenplane (Default)",
"description": "...",
"colors": { "...": "..." },
"warnings": []
},
{
"name": "midnight",
"displayName": "Midnight",
"description": "...",
"colors": { "...": "..." },
"warnings": []
}
]
The built-in themes are idenplane and midnight.
Send Test Email
POST /admin/realms/:realmName/email/test
Sends a test email to verify SMTP configuration.
Request Body
{
"to": "admin@example.com"
}
Request Example
curl -X POST "http://localhost:3000/admin/realms/partner-portal/email/test" \
-H "x-admin-api-key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"to": "admin@example.com"
}'
Response
{
"success": true,
"message": "Test email sent successfully"
}
HTTP 200 means the provider accepted the message. When it was not sent the response is an error with the reason in message:
| Status | When |
|---|---|
400 | to is missing or not an email address, or the realm has no usable email settings |
404 | The realm does not exist |
502 | The email provider refused the message or could not be reached. The message names the likely cause (credentials, connection, a refused address) without the provider's own error text, which goes to the server log. |
{
"statusCode": 502,
"message": "The test email could not be sent: could not connect to the mail server. Check the host, port and TLS setting."
}
POST /admin/realms/:realmName/smtp/test sends a test message to the realm's own sender address, answers {"success": true}, and fails the same way.
Realm Object Schema
{
"id": "string (UUID)",
"name": "string",
"displayName": "string",
"enabled": "boolean",
"registrationAllowed": "boolean",
"passwordMinLength": "integer",
"passwordRequireUppercase": "boolean",
"passwordRequireLowercase": "boolean",
"passwordRequireDigits": "boolean",
"passwordRequireSpecialChars": "boolean",
"passwordHistoryCount": "integer",
"passwordMaxAgeDays": "integer",
"accessTokenLifespan": "integer (seconds)",
"refreshTokenLifespan": "integer (seconds)",
"offlineTokenLifespan": "integer (seconds)",
"maxSessionsPerUser": "integer",
"ssoSessionIdleTimeout": "integer (seconds, 0 = off)",
"bruteForceEnabled": "boolean",
"maxLoginFailures": "integer",
"lockoutDuration": "integer (seconds)",
"failureResetTime": "integer (seconds)",
"permanentLockoutAfter": "integer",
"smtpHost": "string",
"smtpPort": "integer",
"smtpFrom": "string",
"smtpSecure": "boolean",
"loginTheme": "string",
"accountTheme": "string",
"emailTheme": "string",
"...": "more settings; see /api",
"createdAt": "string (ISO 8601)",
"updatedAt": "string (ISO 8601)"
}
Error Responses
| Status | Error | Description |
|---|---|---|
| 400 | ValidationError | Invalid request body or parameters |
| 401 | Unauthorized | Missing or invalid API key |
| 403 | Forbidden | Requires super-admin role |
| 404 | NotFound | Realm not found |
| 409 | Conflict | Realm name already exists |
Password Policy
The password policy is a set of realm fields, not a policy string:
| Field | Default | Description |
|---|---|---|
passwordMinLength | 8 | Minimum password length |
passwordRequireUppercase | false | At least one uppercase letter |
passwordRequireLowercase | false | At least one lowercase letter |
passwordRequireDigits | false | At least one digit |
passwordRequireSpecialChars | false | At least one special character |
passwordHistoryCount | 0 | Previous passwords that cannot be reused |
passwordMaxAgeDays | 0 | Days until a password expires; 0 never |
Passwords are hashed with Argon2id.