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
Comprehensive error types for authentication failures, timeouts, and protocol errors with detailed error information.
OAuth2/OIDC error responses from the authorization server.
/**
* Error representing OAuth2/OIDC error responses
*/
class ErrorResponse extends Error {
constructor(args: {
error: string;
error_description?: string;
error_uri?: string;
state?: string;
session_state?: string;
});
/** OAuth2 error code */
readonly error: string;
/** Human-readable error description */
readonly error_description?: string;
/** URI with error information */
readonly error_uri?: string;
/** State parameter from request */
readonly state?: string;
/** Session state */
readonly session_state?: string;
}Request timeout errors.
/**
* Error for request timeout scenarios
*/
class ErrorTimeout extends Error {
constructor(message?: string);
}DPoP-specific error handling. Note: These errors may be thrown internally but are not exported classes.
/**
* Error for DPoP nonce validation failures (internal error type)
*/
class ErrorDPoPNonce extends Error {
constructor(nonce: string, message?: string);
/** The nonce value that caused the error */
readonly nonce: string;
/** Error type marker */
readonly name: "ErrorDPoPNonce";
}import { UserManager, ErrorResponse, ErrorTimeout } from "oidc-client-ts";
const userManager = new UserManager({
// ... configuration
});
try {
const user = await userManager.signinRedirect();
} catch (error) {
if (error instanceof ErrorResponse) {
console.error("OAuth2 Error:", {
code: error.error,
description: error.error_description,
uri: error.error_uri,
});
// Handle specific error codes
switch (error.error) {
case "access_denied":
showMessage("Access was denied by the user");
break;
case "invalid_request":
showMessage("Invalid authentication request");
break;
case "server_error":
showMessage("Authentication server error");
break;
default:
showMessage(`Authentication failed: ${error.error_description}`);
}
} else if (error instanceof ErrorTimeout) {
console.error("Request timeout:", error.message);
showMessage("Authentication request timed out");
} else {
console.error("Unknown error:", error);
showMessage("An unexpected error occurred");
}
}Install with Tessl CLI
npx tessl i tessl/npm-oidc-client-ts