What is oidc-client-ts?
The oidc-client-ts package is a TypeScript library for OpenID Connect (OIDC) and OAuth2 authentication. It provides a client-side solution for handling user authentication, token management, and secure API calls.
What are oidc-client-ts's main functionalities?
User Authentication
This code demonstrates how to configure and initiate a user authentication process using the oidc-client-ts package. It sets up the UserManager with the necessary OIDC configuration and starts the sign-in redirect process.
import { UserManager, WebStorageStateStore } from 'oidc-client-ts';
const config = {
authority: 'https://example.com/oidc',
client_id: 'your-client-id',
redirect_uri: 'https://yourapp.com/callback',
response_type: 'code',
scope: 'openid profile',
userStore: new WebStorageStateStore({ store: window.localStorage })
};
const userManager = new UserManager(config);
userManager.signinRedirect();
Token Management
This code snippet shows how to retrieve the current authenticated user and their tokens. If the user is logged in, their information is logged to the console.
userManager.getUser().then(user => {
if (user) {
console.log('User logged in', user);
} else {
console.log('User not logged in');
}
});
Silent Renew
This code demonstrates how to set up silent token renewal. It listens for the access token expiring event and attempts to renew the token silently without user interaction.
userManager.events.addAccessTokenExpiring(() => {
userManager.signinSilent().then(user => {
console.log('Silent renew successful', user);
}).catch(err => {
console.error('Silent renew error', err);
});
});
Logout
This code initiates the logout process by redirecting the user to the OIDC provider's logout endpoint.
userManager.signoutRedirect();
Other packages similar to oidc-client-ts
oidc-client
The oidc-client package is a JavaScript library for OpenID Connect and OAuth2 authentication. It is the predecessor to oidc-client-ts and provides similar functionalities but is written in JavaScript instead of TypeScript.
react-oidc-context
The react-oidc-context package is a React library for integrating OIDC authentication into React applications. It provides hooks and context providers to manage authentication state within a React app, making it easier to use with React compared to oidc-client-ts.
next-auth
The next-auth package is a complete authentication solution for Next.js applications. It supports multiple authentication providers, including OIDC, and provides a higher-level abstraction compared to oidc-client-ts, making it easier to integrate into Next.js projects.
oidc-client-ts
Library to provide OpenID Connect (OIDC) and OAuth2 protocol support for client-side, browser-based JavaScript client
applications. Also included is support for user session and access token management.
This is a forked version of the oidc-client-js library, which has
been archived and is no longer maintained. This version has been refactored from JavaScript to TypeScript. Trying to
keep the API as compatible as possible. However we are aiming to modernize and simplify the library, which will
have an effect on the API.
Contributions and help is much appreciated!
Table of Contents
Documentation
Some initial docs are here.
Installation
Using npm
npm install oidc-client-ts
Building the Source
git clone https://github.com/pamapa/oidc-client-ts.git
cd oidc-client-ts
npm install
npm run build
Running the Sample
npm run parcel:run
and then browse to http://localhost:1234.
Running the Tests
npm test
Contributing
We appreciate feedback and contribution to this repo!
License
This project is licensed under the Apache-2.0 license. See the LICENSE file for more info.