liquid-node-authenticator
TypeScript icon, indicating that this package has built-in type declarations

1.1.9 • Public • Published

📦 Liquid Node Authenticator

A Node.js connector library to integrate your microservices with Liquid authentication services. This library requires Node version 18 or above.

Installation

Run npm i liquid-node-authenticator.

Usage

Initialization

import LiquidAuthenticator from "liquid-node-authenticator";

const liquidAuthenticator = new LiquidAuthenticator({
  host: "host_address_of_your_liquid_instance",
  clientId: "your_liquid_client_id",
  clientSecret: "your_liquid_client_secret",
  scope: "scope1,scope2,scope3",
  // Optional
  cacheOptions: {
    client: RedisClient,
    expire: 300, // 5 minutes
  },
  // Optional
  debugging: true, // Print console logs
});

Authenticate a user connecting to your microservice

const tokenDetails = await liquidAuthenticator.authenticate(token);

// Now use tokenDetails.user in the rest of your logic.

Get access token for accessing client level APIs

const { accessToken } = await liquidAuthenticator.getAccessToken();
// Make APIs calls that requires client authentication.

Check if a scope is allowed for a token

const allowed = liquidAuthenticator.checkTokenScope(
  "your:scope:name",
  token /* tokenDetails object acqurired in authenticate() function */
);

if (allowed) {
  // Scope is allowed, continue with action
} else {
  // Scope is NOT allowed, send insufficient priviledge error
}

Package Sidebar

Install

npm i liquid-node-authenticator

Weekly Downloads

15

Version

1.1.9

License

MIT

Unpacked Size

51.5 kB

Total Files

7

Last publish

Collaborators

  • shrihariprakash