Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keycloak-js

Package Overview
Dependencies
Maintainers
4
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keycloak-js

A client-side JavaScript OpenID Connect library that can be used to secure web applications.

  • 26.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
437K
decreased by-9.41%
Maintainers
4
Weekly downloads
 
Created

What is keycloak-js?

The keycloak-js npm package is a JavaScript adapter for Keycloak, an open-source identity and access management solution. It allows developers to integrate Keycloak's authentication and authorization capabilities into their web applications.

What are keycloak-js's main functionalities?

Initialize Keycloak

This feature initializes the Keycloak instance and checks if the user is authenticated. If the user is not authenticated, it redirects them to the login page.

const keycloak = new Keycloak();
keycloak.init({ onLoad: 'login-required' }).then(authenticated => {
  console.log(authenticated ? 'Authenticated' : 'Not authenticated');
}).catch(err => {
  console.error('Failed to initialize Keycloak', err);
});

Login

This feature triggers the login process, redirecting the user to the Keycloak login page.

keycloak.login().then(() => {
  console.log('User logged in');
}).catch(err => {
  console.error('Failed to login', err);
});

Logout

This feature logs the user out of the application and redirects them to the Keycloak logout page.

keycloak.logout().then(() => {
  console.log('User logged out');
}).catch(err => {
  console.error('Failed to logout', err);
});

Check Authentication

This feature checks if the user's token is still valid and refreshes it if necessary.

keycloak.updateToken(30).then(refreshed => {
  if (refreshed) {
    console.log('Token refreshed');
  } else {
    console.log('Token not refreshed, valid for ' + Math.round(keycloak.tokenParsed.exp + keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds');
  }
}).catch(err => {
  console.error('Failed to refresh token', err);
});

Get User Profile

This feature retrieves the user's profile information from Keycloak.

keycloak.loadUserProfile().then(profile => {
  console.log('User profile', profile);
}).catch(err => {
  console.error('Failed to load user profile', err);
});

Other packages similar to keycloak-js

Keywords

FAQs

Package last updated on 01 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc