Project details
oidc-tools is a lightweight library designed to simplify interactions with OpenID Connect tokens. With straightforward installation and usage, it allows developers to decode tokens, manage authentication flows, and handle logout functionality efficiently. This robust tool is ideal for enhancing security and streamlining OIDC integrations.
oidc-tools is a lightweight library designed for seamless integration with OpenID Connect (OIDC) authentication. This library simplifies the management of OIDC tokens, enabling developers to easily implement secure authentication flows in their applications.
To get started with oidc-tools, follow these usage examples that demonstrate its core functionality:
Begin by importing the library and configuring it with the necessary credentials:
import OidcTools from 'oidc-tools';
const { decodeToken, getLoginUrl, getLogoutUrl } = await OidcTools({
issuerURL: process.env.OIDC_ISSUER_URL,
clientId: process.env.OIDC_CLIENT_ID,
clientSecret: process.env.OIDC_CLIENT_SECRET,
redirectUri: process.env.OIDC_REDIRECT_URI,
cache: true,
cacheDuration: 300000,
usePKCE: true
});
Decode and verify the contents of a JWT token:
try {
const payload = await decodeToken('your-jwt-token');
console.log(payload);
} catch (error) {
console.error('Token verification failed:', error.message);
}
Facilitate user authentication by generating login and logout URLs:
const { url } = getLoginUrl();
console.log(`Redirect user to: ${url}`);
const logoutUrl = getLogoutUrl({
postLogoutRedirectUri: 'https://your-app/logged-out'
});
console.log(`Logout URL: ${logoutUrl}`);
For a comprehensive illustration, the repository includes an example demonstrating a full authentication flow using an HTTP server, available in the examples/auth-flow.js file.
The following methods are provided by oidc-tools:
By leveraging this library, developers can enhance the security and efficiency of their user authentication processes, ensuring a smooth and reliable experience for their applications.
Comments
0Start the conversation
Share the first comment.