What is oidc-client?
The oidc-client npm package is a JavaScript library designed to handle OpenID Connect (OIDC) and OAuth2 protocols. It provides functionalities for user authentication, token management, and session handling in client-side applications.
What are oidc-client's main functionalities?
User Authentication
This feature allows you to authenticate users via OIDC. The code sample demonstrates how to configure the UserManager with the necessary parameters and initiate a sign-in redirect.
const oidc = new Oidc.UserManager({
authority: 'https://example.com',
client_id: 'client_id',
redirect_uri: 'https://app.com/callback',
response_type: 'id_token token',
scope: 'openid profile api1'
});
oidc.signinRedirect();
Token Management
This feature handles token management, including retrieving the current user's tokens. The code sample shows how to get the current user and check if they are logged in.
oidc.getUser().then(function(user) {
if (user) {
console.log('User logged in', user);
} else {
console.log('User not logged in');
}
});
Session Handling
This feature manages user sessions, including handling events when a user is loaded or unloaded. The code sample demonstrates how to add event listeners for user session events.
oidc.events.addUserLoaded(function(user) {
console.log('User loaded', user);
});
oidc.events.addUserUnloaded(function() {
console.log('User logged out');
});
Other packages similar to oidc-client
passport
Passport is a popular authentication middleware for Node.js. It supports various authentication strategies, including OIDC and OAuth2. Unlike oidc-client, which is client-side focused, Passport is designed for server-side authentication.
auth0-js
Auth0.js is a client-side library for integrating with Auth0's authentication and authorization services. It provides similar functionalities to oidc-client, such as user authentication and token management, but is specifically tailored for use with Auth0.
openid-client
OpenID Client is a server-side library for Node.js that implements the OpenID Connect and OAuth2 protocols. It offers comprehensive support for these protocols, similar to oidc-client, but is intended for server-side applications.
oidc-client
OpenID Connect (OIDC) client library
Install
To install you can either get the oidc-client via bower, via the dist folder in this repo, or you can clone this repo and run gulp yourself.
As of now, there are not really any docs (sorry), but there are some samples in this repo.