identity-model-oidc-client-js
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Top Related Projects
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
Quick Overview
The DuendeArchive/identity-model-oidc-client-js repository is a JavaScript library for implementing OpenID Connect (OIDC) and OAuth2 protocols in browser-based applications. It provides a robust set of tools for handling authentication, token management, and secure communication with OIDC providers.
Pros
- Comprehensive implementation of OIDC and OAuth2 protocols
- Supports various flows including implicit, code, and PKCE
- Well-documented with clear examples and API references
- Actively maintained with regular updates and bug fixes
Cons
- Learning curve for developers new to OIDC concepts
- Limited built-in support for specific identity providers (requires custom configuration)
- Dependency on browser APIs may limit usage in some environments
- Requires careful implementation to ensure security best practices
Code Examples
- Creating an OIDC client:
import { UserManager } from 'oidc-client';
const config = {
authority: 'https://your-oidc-provider.com',
client_id: 'your-client-id',
redirect_uri: 'https://your-app.com/callback',
response_type: 'code',
scope: 'openid profile email'
};
const userManager = new UserManager(config);
- Initiating login:
userManager.signinRedirect().catch(error => {
console.error('Error during sign-in:', error);
});
- Handling the callback after authentication:
userManager.signinRedirectCallback().then(user => {
console.log('User logged in:', user);
}).catch(error => {
console.error('Error processing sign-in response:', error);
});
- Retrieving the current user:
userManager.getUser().then(user => {
if (user) {
console.log('User is authenticated:', user.profile);
} else {
console.log('User is not authenticated');
}
});
Getting Started
To get started with identity-model-oidc-client-js:
-
Install the library:
npm install oidc-client
-
Import and configure the UserManager:
import { UserManager } from 'oidc-client'; const config = { authority: 'https://your-oidc-provider.com', client_id: 'your-client-id', redirect_uri: 'https://your-app.com/callback', response_type: 'code', scope: 'openid profile email' }; const userManager = new UserManager(config);
-
Implement login, logout, and callback handling in your application using the UserManager methods.
-
Secure your API requests by including the access token in the Authorization header:
userManager.getUser().then(user => { if (user) { const headers = new Headers(); headers.append('Authorization', `Bearer ${user.access_token}`); fetch('https://api.example.com/data', { headers }) .then(response => response.json()) .then(data => console.log(data)); } });
Competitor Comparisons
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Pros of identity-model-oidc-client-js
- Actively maintained and updated repository
- Comprehensive documentation and examples
- Strong community support and regular contributions
Cons of identity-model-oidc-client-js
- Larger codebase, potentially more complex to integrate
- May have a steeper learning curve for beginners
- Requires more frequent updates to stay current
Code Comparison
identity-model-oidc-client-js:
import { UserManager } from 'oidc-client';
const userManager = new UserManager({
authority: 'https://example.com',
client_id: 'client_id',
redirect_uri: 'https://app.example.com/callback',
response_type: 'code',
scope: 'openid profile email'
});
Both repositories appear to be the same project, as the comparison is between identical repositories. The code snippet provided is an example of how to use the library in a typical OpenID Connect implementation. It demonstrates the initialization of a UserManager with configuration options for authentication.
In this case, there are no significant differences to highlight between the repositories, as they are the same project. The library provides a robust implementation of OpenID Connect and OAuth 2.0 protocols for JavaScript applications, offering features like token management, silent renew, and session monitoring.
OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
Pros of openid-client
- More comprehensive OpenID Connect support, including advanced features like Dynamic Client Registration
- Better TypeScript support with stricter typing
- Actively maintained with frequent updates and bug fixes
Cons of openid-client
- Steeper learning curve due to its more extensive API
- Less browser-friendly, primarily designed for server-side usage
- Fewer examples and documentation compared to identity-model-oidc-client-js
Code Comparison
identity-model-oidc-client-js:
const userManager = new UserManager(settings);
userManager.signinRedirect();
openid-client:
const client = new Client(issuer, {
client_id: 'client_id',
client_secret: 'client_secret',
});
const authorizationUrl = client.authorizationUrl({
scope: 'openid email profile',
});
The code snippets demonstrate the difference in approach between the two libraries. identity-model-oidc-client-js provides a higher-level abstraction with the UserManager
, while openid-client offers more granular control over the OpenID Connect flow.
Both libraries serve their purposes well, but openid-client is better suited for more complex server-side implementations, while identity-model-oidc-client-js is more accessible for browser-based applications and simpler use cases.
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Pros of oidc-client-ts
- Written in TypeScript, providing better type safety and developer experience
- More active development and maintenance, with recent updates and contributions
- Smaller bundle size, potentially improving performance for web applications
Cons of oidc-client-ts
- Less comprehensive documentation compared to identity-model-oidc-client-js
- Fewer examples and integrations available for different frameworks and scenarios
- Potentially less stable due to more frequent changes and updates
Code Comparison
identity-model-oidc-client-js:
import { UserManager } from 'oidc-client';
const userManager = new UserManager({
authority: 'https://example.com',
client_id: 'client_id',
redirect_uri: 'https://app.example.com/callback'
});
oidc-client-ts:
import { UserManager } from 'oidc-client-ts';
const userManager = new UserManager({
authority: 'https://example.com',
client_id: 'client_id',
redirect_uri: 'https://app.example.com/callback'
});
The basic usage and configuration of both libraries are very similar, with the main difference being the import statement and the potential for stronger typing in oidc-client-ts.
JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
Pros of AppAuth-JS
- Implements the full OAuth 2.0 and OpenID Connect specifications, providing comprehensive support for various authentication flows
- Actively maintained with regular updates and a larger community of contributors
- Designed to be framework-agnostic, making it more versatile for different JavaScript environments
Cons of AppAuth-JS
- Steeper learning curve due to its comprehensive nature and adherence to full specifications
- May require more configuration and setup compared to identity-model-oidc-client-js
- Larger bundle size, which could impact performance in some applications
Code Comparison
AppAuth-JS:
const authorizationHandler = new AuthorizationRequestHandler();
const request = new AuthorizationRequest({
client_id: 'client_id',
redirect_uri: 'https://app.example.com/callback',
scope: 'openid profile email',
response_type: AuthorizationRequest.RESPONSE_TYPE_CODE,
});
authorizationHandler.performAuthorizationRequest(configuration, request);
identity-model-oidc-client-js:
const userManager = new UserManager(settings);
userManager.signinRedirect({
scope: 'openid profile email',
redirect_uri: 'https://app.example.com/callback'
}).then(() => {
console.log('Redirect to authorization endpoint');
});
Both libraries provide similar functionality for handling OAuth 2.0 and OpenID Connect flows, but AppAuth-JS offers a more granular approach with separate classes for different request types, while identity-model-oidc-client-js provides a higher-level abstraction with its UserManager class.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
No Longer Maintained
This library, while functional, is no longer being maintained.
A successor project that is showing great progress in updating and modernizing is "oidc-client-ts" and can be found here.
oidc-client
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.
Install
Node.js
Node.js v4.4 or later required.
NPM
npm install oidc-client --save
NOTE: if you're not already using babel-polyfill make sure you run
npm install --save babel-polyfill
as well. Then include it in your build.
CommonJS
If you don't use a package manager or a module loader, then you can get the library from the dist
folder on github here.
Including in the browser
If you intend to use this library directly in a browser and are not using UMD/AMD then there is a compiled version in the ~/dist folder. It is already bundled/minified and contains the necessary dependencies and polyfills (mainly for ES6 features such as Promises).
If you are using UMD/AMD and/or you already have included an ES6 polyfill (such as babel-polyfill.js) then you can include the UMD packaged version of the file from the ~/lib folder.
Building the Source
git clone https://github.com/IdentityModel/oidc-client-js.git
cd oidc-client-js
npm install
npm run build
Running the Sample
npm start
and then browse to http://localhost:15000.
Running the Tests
npm test
Docs
Some initial docs are here.
Feedback, Feature requests, and Bugs
All are welcome on the issue tracker.
Top Related Projects
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot