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

utilities.mddocs/

Utilities and Logging

Utility functions for cryptography, JWT handling, URL manipulation, and configurable logging system.

Capabilities

Logging

Configurable logging system with multiple log levels.

/**
 * Logger instance with contextual name
 */
class Logger {
  constructor(name: string);
  
  debug(message: string, ...args: unknown[]): void;
  info(message: string, ...args: unknown[]): void;
  warn(message: string, ...args: unknown[]): void;
  error(message: string, ...args: unknown[]): void;
  
  create(name: string): Logger;
}

/**
 * Global log configuration
 */
class Log {
  static readonly NONE: number;
  static readonly ERROR: number;
  static readonly WARN: number;
  static readonly INFO: number;
  static readonly DEBUG: number;
  
  static level: number;
  static logger: Console;
}

Cryptographic Utilities

PKCE and cryptographic helper functions.

/**
 * Cryptographic utilities for OIDC operations
 */
class CryptoUtils {
  /** Generate RFC4122 version 4 UUID without hyphens */
  static generateUUIDv4(): string;
  
  /** Generate PKCE code verifier */
  static generateCodeVerifier(): string;
  
  /** Generate PKCE code challenge from verifier */
  static generateCodeChallenge(codeVerifier: string): Promise<string>;
  
  /** Generate basic auth header */
  static generateBasicAuth(client_id: string, client_secret: string): string;
}

JWT Utilities

JWT token parsing and validation.

/**
 * JWT utilities for token processing
 */
class JwtUtils {
  /** Decode JWT token and return claims (does not validate) */
  static decode(token: string): JwtClaims;
}

URL Utilities

URL manipulation and parsing functions.

/**
 * URL utilities for OIDC operations
 */
class UrlUtils {
  /** Read parameters from URL query string or fragment */
  static readParams(url: string, responseMode?: "query" | "fragment"): URLSearchParams;
}

Timer Utilities

Timer management for scheduled operations.

/**
 * Timer utility for scheduling operations
 */
class Timer {
  constructor(name: string, logger?: Logger, timerDuration?: number, callback?: () => void);
  
  init(duration: number): void;
  cancel(): void;
  addHandler(callback: () => void): void;
  removeHandler(callback: () => void): void;
}

Event Utilities

Event emitter implementation.

/**
 * Event emitter for user and token events
 */
class Event<T = void> {
  constructor(name: string);
  
  addHandler(callback: (data: T) => void): void;
  removeHandler(callback: (data: T) => void): void;
  raise(data: T): void;
}

Popup Utilities

Popup window management utilities.

Version Information

Library version constant.

/**
 * Library version from package.json
 */
const Version: string;
/**
 * Popup window feature configuration
 */
interface PopupWindowFeatures {
  location?: boolean;
  toolbar?: boolean;
  height?: number;
  width?: number;
  left?: number;
  top?: number;
  closePopupWindowAfterInSeconds?: number;
}

/**
 * Popup window management utilities
 */
class PopupUtils {
  static center(options: { width: number; height: number }): { left: number; top: number };
  static serialize(features: PopupWindowFeatures): string;
}

Usage Examples

Logging Configuration

import { Log, Logger } from "oidc-client-ts";

// Configure global logging
Log.level = Log.INFO;
Log.logger = console;

// Create contextual logger
const logger = new Logger("MyApp");
logger.info("Application started");
logger.debug("Debug information"); // Won't show unless level is DEBUG

// Create sub-logger
const authLogger = logger.create("Auth");
authLogger.warn("Authentication warning");

Custom Crypto Operations

import { CryptoUtils } from "oidc-client-ts";

// Generate PKCE parameters
const codeVerifier = CryptoUtils.generateCodeVerifier();
const codeChallenge = await CryptoUtils.generateCodeChallenge(codeVerifier);

console.log("PKCE Parameters:", {
  verifier: codeVerifier,
  challenge: codeChallenge,
});

// Generate UUID for state parameter
const state = CryptoUtils.generateUUIDv4();

// Basic auth header
const authHeader = CryptoUtils.generateBasicAuth("client_id", "client_secret");

JWT Processing

import { JwtUtils } from "oidc-client-ts";

const idToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...";
const claims = JwtUtils.decode(idToken);

console.log("JWT Claims:", {
  issuer: claims.iss,
  subject: claims.sub,
  audience: claims.aud,
  expiration: new Date(claims.exp * 1000),
  name: (claims as any).name,
});

URL Manipulation

import { UrlUtils } from "oidc-client-ts";

// Read query parameters
const queryUrl = "https://provider.com/callback?code=abc123&state=xyz789";
const queryParams = UrlUtils.readParams(queryUrl, "query");
console.log("Query params:", Object.fromEntries(queryParams));
// { code: "abc123", state: "xyz789" }

// Read fragment parameters
const fragmentUrl = "https://provider.com/callback#access_token=abc123&token_type=Bearer&expires_in=3600";
const fragmentParams = UrlUtils.readParams(fragmentUrl, "fragment");
console.log("Fragment params:", Object.fromEntries(fragmentParams));
// { access_token: "abc123", token_type: "Bearer", expires_in: "3600" }

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