OpenID Connect (OIDC) & OAuth2 client library for TypeScript/JavaScript applications
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Flexible storage options for user data and request state with built-in implementations and custom storage interfaces.
Core interface for state persistence.
/**
* Interface for storing and retrieving state data
*/
interface StateStore {
set(key: string, value: string): Promise<void>;
get(key: string): Promise<string | null>;
remove(key: string): Promise<string | null>;
getAllKeys(): Promise<string[]>;
}Web storage implementation using localStorage or sessionStorage.
/**
* StateStore implementation using Web Storage API
*/
class WebStorageStateStore implements StateStore {
constructor(args?: { store?: Storage; prefix?: string });
set(key: string, value: string): Promise<void>;
get(key: string): Promise<string | null>;
remove(key: string): Promise<string | null>;
getAllKeys(): Promise<string[]>;
}In-memory storage implementation.
/**
* In-memory storage implementation
*/
class InMemoryWebStorage implements StateStore {
setItem(key: string, value: string): void;
getItem(key: string): string | null;
removeItem(key: string): void;
key(index: number): string | null;
readonly length: number;
}DPoP (Demonstration of Proof-of-Possession) state management.
interface DPoPStore {
set(key: string, value: string): Promise<void>;
get(key: string): Promise<string | null>;
remove(key: string): Promise<void>;
}
class IndexedDbDPoPStore implements DPoPStore {
constructor(dbName?: string, storeName?: string);
set(key: string, value: string): Promise<void>;
get(key: string): Promise<string | null>;
remove(key: string): Promise<void>;
}
class DPoPState {
constructor(args: { dpopJkt: string; nonce?: string });
readonly dpopJkt: string;
readonly nonce?: string;
}import { UserManager, WebStorageStateStore, InMemoryWebStorage } from "oidc-client-ts";
// Custom storage configuration
const userManager = new UserManager({
authority: "https://demo.identityserver.io",
client_id: "interactive.public",
redirect_uri: "http://localhost:3000/callback",
// User storage in localStorage
userStore: new WebStorageStateStore({
store: window.localStorage,
prefix: "myapp.user."
}),
// State storage in sessionStorage
stateStore: new WebStorageStateStore({
store: window.sessionStorage,
prefix: "myapp.state."
}),
});
// Custom storage implementation
class CustomStateStore implements StateStore {
private data = new Map<string, string>();
async set(key: string, value: string): Promise<void> {
this.data.set(key, value);
}
async get(key: string): Promise<string | null> {
return this.data.get(key) || null;
}
async remove(key: string): Promise<string | null> {
const value = this.data.get(key) || null;
this.data.delete(key);
return value;
}
async getAllKeys(): Promise<string[]> {
return Array.from(this.data.keys());
}
}Storage interface for DPoP key pairs and nonce values used in OAuth 2.0 DPoP token binding.
/**
* Interface for storing and retrieving DPoP state data
*/
interface DPoPStore {
set(key: string, value: DPoPState): Promise<void>;
get(key: string): Promise<DPoPState>;
remove(key: string): Promise<DPoPState>;
getAllKeys(): Promise<string[]>;
}
/**
* DPoP state containing key pairs and nonce
*/
class DPoPState {
constructor(
keys: CryptoKeyPair,
nonce?: string
);
readonly keys: CryptoKeyPair;
nonce?: string;
}IndexedDB-based implementation for DPoP storage.
/**
* DPoPStore implementation using IndexedDB for persistent storage
*/
class IndexedDbDPoPStore implements DPoPStore {
constructor(args?: {
dbName?: string;
tableName?: string;
});
set(key: string, value: DPoPState): Promise<void>;
get(key: string): Promise<DPoPState>;
remove(key: string): Promise<DPoPState>;
getAllKeys(): Promise<string[]>;
}Usage Example:
import { UserManager, IndexedDbDPoPStore, DPoPState } from "oidc-client-ts";
// Configure UserManager with DPoP support
const userManager = new UserManager({
authority: "https://your-oidc-provider.com",
client_id: "your-client-id",
redirect_uri: "http://localhost:3000/callback",
response_type: "code",
scope: "openid profile email",
dpop: {
bind_authorization_code: true,
store: new IndexedDbDPoPStore({
dbName: "myapp-dpop",
tableName: "dpop_keys"
})
}
});Install with Tessl CLI
npx tessl i tessl/npm-oidc-client-ts