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

nodejs-keycloak

v1.0.5

Published

`nodejs-keycloak` is a Node.js package for communicating with a Keycloak server. It allows you to verify JWT tokens generated by Keycloak and, if provided with a username and password, perform various Keycloak API operations such as obtaining access token

Downloads

14

Readme

nodejs-keycloak

nodejs-keycloak is a Node.js package for communicating with a Keycloak server. It allows you to verify JWT tokens generated by Keycloak and, if provided with a username and password, perform various Keycloak API operations such as obtaining access tokens, refresh tokens, or creating new realms.

Installation

You can install the package via npm:

npm install nodejs-keycloak

Usage

Importing the Package

First, import the package and get the Keycloak class:

const { KeycloakClient } = require("nodejs-keycloak");

Initializing the Keycloak Instance

Create an instance of the Keycloak class by providing the Keycloak server URL and realm name. Optionally, you can provide a username and password.

const keycloak = new KeycloakClient({
  serverUrl: "http://localhost:8080",
  realm: "your-realm",
  client_id: "web-client",
  username: "your-username", // optional
  password: "your-password", // optional
});

Verifying JWT Tokens

Once the Keycloak instance is ready, you can use it to verify JWT tokens generated by the Keycloak server:

const token = "my-jwt-token";
keycloak
  .verifyJwt(token)
  .then((decoded) => {
    console.log(decoded);
  })
  .catch((error) => {
    console.log(error);
  });

Or

const token = "my-jwt-token";
try{
  const decoded = await keycloak.verifyJwt(token)
  console.log(decoded)
}
catch(error){
  console.log(error)
}

Keycloak API Operations

If the username and password are provided, you can use the same instance to call Keycloak APIs.

Get Access Token

keycloak
  .getAccessToken()
  .then((token) => {
    console.log(token);
  })
  .catch((error) => {
    console.log(error);
  });

Or

try{
  const token = await keycloak.getAccessToken()
  console.log(token)
}
catch(error){
  console.log(error)
}

Get Refresh Token

keycloak
  .getRefreshToken()
  .then((token) => {
    console.log(token);
  })
  .catch((error) => {
    console.log(error);
  });

Or

try{
  const token = await keycloak.getRefreshToken()
  console.log(token)
}
catch(error){
  console.log(error)
}