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

Tagsauthenticationauthorization
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 authenticate, you need the client ID and then you need username and password for the password grant type, or client secret for the client_credentials grant type. In the second JSON field, you can set the extra config you can find in the examples here.

Here is 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 groups = 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" });