@fundwave/oidc-client v3.0.0
OIDC Client
@fundwave/oidc-client is a lightweight client-side library that allows you to prepare headers for your network-calls by automatically refreshing tokens (if expired) with the provided OIDC server.
Installation
npm install @fundwave/oidc-clientInitialization
import { OIDCClient } from "@fundwave/oidc-client";
const oidcClient = new OIDCClient();
// Set the URL-String where token refresh requests will be sent
oidcClient.setBaseUrl("https://my-awesome-oidc-server.com");
// Set the path on the server which is responsible for the refresh
oidcClient.setRefreshPath("refresh-token");Note: the
refreshPathproperty defaults to token/refresh
Usage
Once the class has been instantiated, you can
use the
prepareHeadersmethod to get the required headers for your callsconst headers = await oidcClient.prepareHeaders();Optionally, directly use the
getAccessTokenmethod to update the tokens (access and refresh) at browser's storageawait oidcClient.getAccessToken();If the refresh-token call returns a
401/403or any other error status, the library will throw an custom-eventlogged-out
Notes:
Tokens aren't refreshed every time the
prepareHeadersmethod is called. Tokens are only refreshed when the token is about to expire.If your client app makes parallel calls to the same object of oidc-client, this library will still make only one active call to your OIDC server. This will reduce network calls and avoid exceeding any rate limits with your OIDC server.
Access Token is maintained at browser's session storage with the key being
tokenRefresh Token is maintained at browser's local storage with the key being
refreshTokenThe library will read tokens sent by your OIDC server from either the response body or headers
7 months ago
7 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
3 years ago
3 years ago
3 years ago
3 years ago