Socket
Book a DemoInstallSign in
Socket

@trigo/keycloak-api

Package Overview
Dependencies
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trigo/keycloak-api

Node.js Keycloak Admin API Wrapper

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
44
266.67%
Maintainers
3
Weekly downloads
 
Created
Source

Node.js Keycloak API Wrapper

Usage

const KeycloakApi = require('@trigo/keycloak-api');

const config = {
	authorizationEndpoint: 'https://<keycloak>/auth',
	clientId: '<clientId>',
	username: '<username>', // admin user
	password: '<password>',
	
};
const api = new KeycloakApi(config);
await api.waitForKeycloak(); // required 

Features

Ever function requires a function param called tokenProvider. It should return a access token.

Example

const tokenProvider = async () => {
    const res = await api.getToken({
        realm: 'master',
        grantType: 'password',
        clientId: 'admin-cli',
        username: '<username>',
        password: '<password>',
    });
    return res.data.access_token;
};

We will refer to this example in the following function calls.

Realms

createRealm

const {statusCode, data} = await api.createRealm({ realm: 'sparta', tokenProvider })

Users

getUsers

Get list of users. Optional query object as key value.


const query = {
	username: 'leonidas',
};

const {statusCode, data} = await api.getUsers({ realm: 'sparta', query, tokenProvider });

statusCode contains the HTTP status code. data array of Keycloak Users.

createUser

Creates a new user.


const user = {
	username: 'leonidas',
};

const {statusCode, data} = await api.createUser({ realm: 'sparta', user, tokenProvider });

statusCode contains the HTTP status code. data the keycloak user object.

Groups

getGroups

Returns all keycloak Groups


const {statusCode, data} = await api.getGroups({ realm: 'sparta', tokenProvider });

statusCode contains the HTTP status code. data array of keycloak groups.

createGroup

Creates a new user group.


const group = {
	name: 'Spartiates',
	attributes: {
		'size': ['300'],
	},
};

const parentGroupId = 300; // Optional

const {statusCode, data} = await api.createGroup({ realm: 'sparta', group, parentGroupId, tokenProvider });

statusCode contains the HTTP status code. data the keycloak group object.

deleteGroup

Deletes a user group by groupId


const {statusCode} = await api.deleteGroup({ realm: 'sparta', groupId: 300, tokenProvider });

statusCode contains the HTTP status code.

makeGroupChildOfGroup

If group exists it sets the parent otherwise it creates the group as a child


const {statusCode} = await api.makeGroupChildOfGroup({ realm: 'sparta', parentGroupId: '42', group: { id: '43', name: 'child group' }, tokenProvider });

statusCode contains the HTTP status code.

FAQs

Package last updated on 20 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts