npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@trigo/keycloak-api

v1.3.0

Published

Node.js Keycloak Admin API Wrapper

Downloads

830

Readme

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, header} = 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, header} = await api.getUsers({ realm: 'sparta', query, tokenProvider });

statusCode contains the HTTP status code. data array of Keycloak Users. header node-fetch style raw headers

createUser

Creates a new user.


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

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

statusCode contains the HTTP status code. data the keycloak user object. header node-fetch style raw headers

Groups

getGroups

Returns all keycloak Groups


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

statusCode contains the HTTP status code. data array of keycloak groups. header node-fetch style raw headers

createGroup

Creates a new user group.


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

const parentGroupId = 300; // Optional

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

statusCode contains the HTTP status code. data the keycloak group object. header node-fetch style raw headers

deleteGroup

Deletes a user group by groupId


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

statusCode contains the HTTP status code. header node-fetch style raw headers

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. header node-fetch style raw headers