@flowcore/sdk-oidc-client v1.3.1
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-clientor yarn:
yarn add @flowcore/sdk-oidc-clientUsage
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
TokenInfointerface, exported from this library. To extend the token info, you can extend theTokenInfointerface and pass it as a generic to theDecodeTokenmethod.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 installor with npm:
npm install