Skip to main content

Keycloak

Keycloak allows you to manage user authentication and authorization in your apps. This integration provides a client for keycloak admin API

Network Connection needs

This integration needs network access to the server where the service is running.

See the Network access page for details about how to achieve that.

Credential configuration

To configure this credential you need the URL of the server and the realmName. Optionally you can set axios request config in the JSON field, which will be sent in all requests.

To authentication, you need the client ID and then you need username and password for passwrd grant type, or client secret for client_credentials grant type. In the second JSON field you can set the extra config you can find in the examples here.

Here you have an example of a filled credential configuration form in YepCode:

Keycloak snippets available in editor

note

The title is the triggering text for YepCode to autocomplete the script

Integration

New integration from credential
const keycloakAdminClient = await yepcode.integration.keycloak("credential-slug");
New integration from plain authentication data (username and password)
const KeycloakAdminClient = require("@keycloak/keycloak-admin-client").default;

const keycloakAdminClient = new KeycloakAdminClient({
baseUrl: "baseUrl",
realmName: "realm-name"
});

await keycloakAdminClient.auth({
grantType: "password",
clientId: "keycloak-client-id",
username: "username",
password: "password"
});
New integration from plain authentication data (client secret)
const KeycloakAdminClient = require("@keycloak/keycloak-admin-client").default;

const keycloakAdminClient = new KeycloakAdminClient({
baseUrl: "baseUrl",
realmName: "realm-name"
});

await keycloakAdminClient.auth({
grantType: "client_credentials",
clientId: "keycloak-client-id",
clientSecret: "your-client-secret"
});

Change realm to manage

Change realm
keycloakAdminClient.setConfig({
realmName: "realm-name"
});

Find all realm users

Find all realm users
const users = await keycloakAdminClient.users.find();

Find a single user

Find a single user by id
const user = await keycloakAdminClient.users.findOne({ id: "user-id" });
Find a single user by email
const user = await keycloakAdminClient.users.findOne({ email: "user-email" });

Get user roles

Get user roles
const roles = await keycloakAdminClient.users.listRoleMappings({ id: "user-id" });

Get user groups

Get user groups
const roles = await keycloakAdminClient.users.listGroups({ id: "user-id" });

Find all realm groups

Find all realm groups
const groups = await keycloakAdminClient.groups.find();

Find a single group

Find a single group
const group = await keycloakAdminClient.groups.findOne({ id: "group-id" });