A Flowcore SDK module that provides open id connect provider functionality, for use with the Flowcore platform.
npm install @flowcore/sdk-oidc-clientA Flowcore SDK module that provides open id connect provider functionality, for use with the Flowcore platform.
install with npm:
``bash`
npm install @flowcore/sdk-oidc-client
or yarn:
`bash`
yarn add @flowcore/sdk-oidc-client
Create a new instance of the OIDC client:
`typescript
import { OidcClient } from '@flowcore/sdk-oidc-client';
const client = new OidcClient("your client id", "your client secret", "well known endpoint");
`
Get a token from the OIDC provider, this will fetch the token from the provider and cache it for future use:
`typescript`
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.
To force a refresh of the token ignoring the cached version, you can pass true to the getToken method:
`typescript`
const tokenSet = await client.getToken(true);
The library also provides a method to decode the token:
`typescript`
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.TokenInfo
> To extend the token info, you can extend the interface and pass it as a generic to the DecodeToken method.`
>
> typescript`
> interface CustomTokenInfo extends TokenInfo {
> customField: string;
> }
>
> const decodedToken = OidcClient.DecodeToken
>
To override the default scope, you can pass the scope to the options object in the constructor:
`typescript`
const client = new OidcClient("your client id", "your client secret", "well known endpoint", { scope: "custom scope" });
To set a buffer for the token expiration, you can pass the buffer in seconds to the options object in the constructor:
`typescript`
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.
`bash`
yarn install
or with npm:
`bash``
npm install