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

oidc-client-ts

Package Overview
Dependencies
Maintainers
0
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oidc-client-ts

OpenID Connect (OIDC) & OAuth2 client library

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
358K
decreased by-7.09%
Maintainers
0
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 04 Oct 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