Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

@hmcts/div-service-auth-provider-client

Package Overview
Dependencies
Maintainers
18
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hmcts/div-service-auth-provider-client

Client to obtain tokens for service to service calls

latest
npmnpm
Version
3.0.1
Version published
Maintainers
18
Created
Source

Client library for service-auth-provider service

Client library to obtain service to service call tokens.

Requirements

  • Node >=8.0
  • yarn

Installation

As of now, this module is published only in a private repository. We are working on publishing this project to NPM. Until then, the package can be installed from its github URL, examples:

# Install the latest version
yarn add https://github.com/hmcts/div-service-auht-provider-client

# Install a specific version
yarn add https://github.com/hmcts/div-service-auth-provider-client#2.1.4

Usage

First get a client

const serviceAuthProviderClient = require('@hmcts/div-service-auth-provider-client')

const client = serviceAuthProviderClient.init({
  apiBaseUrl: 'https://service-auth-provider-api:4502', // Base URL of service-auth-provider API
  microservice: 'reference', // The name of the IDAM service role
  secret: 'AAAAAAAAAAAAAAAA' // Service secret
})

Obtain a token

client.lease()
  .then(token => {
    // The response payload contains the token in plain text.
    console.log(token)
  })
  .catch(err => {
    // Or an error in case of an error.
    console.error(err)
  })

Check if a token is expired

client.isTokenExpired(token) // true if expired, false otherwise.

Implementation notes

Token expiry

Tokens returned contain an expiry date as a unix timestamp under exp. Ideally, this expiry date should be respected and the token should be renewed using the lease method.

Service secrets

The service needs to be registered with IDAM and a secret is required in order to generate a token.

For early implementations where IDAM registration has not finished yet, the reference details (microservice, secret) can be used from the above example.

FAQs

Package last updated on 24 Sep 2018

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