Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@flowcore/sdk-oidc-client

flowcore-io152MIT1.3.1TypeScript support: included

A Flowcore SDK module that provides open id connect provider functionality, for use with the Flowcore platform.

flowcore, typescript, sdk, open id connect, oidc

readme

Flowcore SDK Module - Open ID Connect Provider

A Flowcore SDK module that provides open id connect provider functionality, for use with the Flowcore platform.

Installation

install with npm:

npm install @flowcore/sdk-oidc-client

or yarn:

yarn add @flowcore/sdk-oidc-client

Usage

Create a new instance of the OIDC client:

import { OidcClient } from '@flowcore/sdk-oidc-client';

const client = new OidcClient("your client id", "your client secret", "well known endpoint");

Get Token

Get a token from the OIDC provider, this will fetch the token from the provider and cache it for future use:

const tokenSet = await client.getToken();

Note: The token will be automatically refreshed when it expires, the client will handle this for you. It will also resolve the url for the token endpoint from the well known endpoint. The token will be returned as a string. This client throws an error if the token cannot be retrieved.

Force Refresh Token

To force a refresh of the token ignoring the cached version, you can pass true to the getToken method:

const tokenSet = await client.getToken(true);

Decode Token

The library also provides a method to decode the token:

const decodedToken = OidcClient.DecodeToken(token);

Note: Then decoded token returns the token as an typed object based on the TokenInfo interface, exported from this library. To extend the token info, you can extend the TokenInfo interface and pass it as a generic to the DecodeToken method.

interface CustomTokenInfo extends TokenInfo {
 customField: string;
}

const decodedToken = OidcClient.DecodeToken<CustomTokenInfo>(token);

Custom OIDC Scope

To override the default scope, you can pass the scope to the options object in the constructor:

const client = new OidcClient("your client id", "your client secret", "well known endpoint", { scope: "custom scope" });

Token expiration buffer

To set a buffer for the token expiration, you can pass the buffer in seconds to the options object in the constructor:

const client = new OidcClient("your client id", "your client secret", "well known endpoint", { expirationBuffer: 60 });

NB! The buffer is in seconds, and the default is 20 seconds. If you set the buffer to more than the token expiration time, it will be refreshed every time you call getToken.

Development

yarn install

or with npm:

npm install

changelog

Changelog

1.3.1 (2024-04-17)

Bug Fixes

  • use access token url if it exists (3191a22)

1.3.0 (2024-04-16)

Features

  • added functionality to specify expiration token buffer (ae86060)

1.2.0 (2024-03-28)

Features

  • added configurable scope and d.ts exports (c1874cd)

1.1.2 (2024-03-28)

Bug Fixes

  • docs: removed badges as this is a private repo (166e211)
  • metadata: added npm keywords (a5f36ba)

1.1.1 (2024-03-28)

Bug Fixes

  • ci: added build validation to the test phase (c896129)
  • ci: removed test and lint from publish as this has already been done in the test phase (f4fea1e)
  • docs: fixed oidc client module name (79b74e8)

1.1.0 (2024-03-28)

Features

  • added a way to ignore cached token when getting the token from the client (28dbee9)

1.0.1 (2024-03-28)

Bug Fixes

  • added run dependencies to build step (2a03011)

1.0.0 (2024-03-28)

Features

  • initial version with very simple oidc integration that has been tested with keycloak (23852a6)

Bug Fixes

  • added better error handling (43eee6f)
  • added notice that this client throws errors (0b0285b)
  • removed all non development dependencies (fc901e4)
  • removed peer dependency and added node engine compatibility (18e8f36)
  • removed reference to dayjs as it is not used (24d52d6)