CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-oidc-client-ts

OpenID Connect (OIDC) & OAuth2 client library for TypeScript/JavaScript applications

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

events.mddocs/

Event System

Comprehensive event system for user state changes, token expiration, and error handling with callback registration and management.

Capabilities

UserManagerEvents

Event system for UserManager with user lifecycle and token events.

/**
 * Event management for UserManager user state changes
 */
class UserManagerEvents {
  // Event registration
  addUserLoaded(callback: UserLoadedCallback): void;
  addUserUnloaded(callback: UserUnloadedCallback): void;
  addUserSignedIn(callback: UserSignedInCallback): void;
  addUserSignedOut(callback: UserSignedOutCallback): void;
  addUserSessionChanged(callback: UserSessionChangedCallback): void;
  addSilentRenewError(callback: SilentRenewErrorCallback): void;
  
  // Event removal
  removeUserLoaded(callback: UserLoadedCallback): void;
  removeUserUnloaded(callback: UserUnloadedCallback): void;
  removeUserSignedIn(callback: UserSignedInCallback): void;
  removeUserSignedOut(callback: UserSignedOutCallback): void;
  removeUserSessionChanged(callback: UserSessionChangedCallback): void;
  removeSilentRenewError(callback: SilentRenewErrorCallback): void;
}

// Event callback types
type UserLoadedCallback = (user: User) => Promise<void> | void;
type UserUnloadedCallback = () => Promise<void> | void;
type UserSignedInCallback = () => Promise<void> | void;
type UserSignedOutCallback = () => Promise<void> | void;
type UserSessionChangedCallback = () => Promise<void> | void;
type SilentRenewErrorCallback = (error: Error) => Promise<void> | void;

AccessTokenEvents

Event system for access token lifecycle management.

/**
 * Event handling for access token expiration and renewal
 */
class AccessTokenEvents {
  addAccessTokenExpiring(callback: AccessTokenCallback): void;
  addAccessTokenExpired(callback: AccessTokenCallback): void;
  removeAccessTokenExpiring(callback: AccessTokenCallback): void;
  removeAccessTokenExpired(callback: AccessTokenCallback): void;
}

type AccessTokenCallback = (...ev: unknown[]) => Promise<void> | void;

Usage Examples

import { UserManager, User } from "oidc-client-ts";

const userManager = new UserManager({
  // ... configuration
  automaticSilentRenew: true,
  accessTokenExpiringNotificationTimeInSeconds: 60,
});

// User lifecycle events
userManager.events.addUserLoaded((user: User) => {
  console.log("User loaded:", user.profile?.name);
  updateUIForAuthenticatedUser(user);
});

userManager.events.addUserSignedIn((user: User) => {
  console.log("User signed in:", user.profile?.name);
  redirectToApplication();
});

userManager.events.addUserSignedOut(() => {
  console.log("User signed out");
  redirectToLogin();
});

userManager.events.addSilentRenewError((error: Error) => {
  console.error("Silent renewal failed:", error);
  handleSilentRenewFailure();
});

// Token events
const accessTokenEvents = new AccessTokenEvents();
accessTokenEvents.addAccessTokenExpiring((user: User) => {
  console.log(`Token expiring in ${user.expires_in} seconds`);
  showExpirationWarning();
});

Install with Tessl CLI

npx tessl i tessl/npm-oidc-client-ts

docs

configuration.md

errors.md

events.md

index.md

oidc-client.md

storage.md

user-management.md

user-tokens.md

utilities.md

tile.json