SDK Reference
Complete API reference for the @passkeybase/js SDK.
Constructor
Create a new PasskeyBase instance. You typically create one instance per application and reuse it.
import { PasskeyBase } from '@passkeybase/js';
const pb = new PasskeyBase({
clientId: 'pk_live_abc123', // Required. Your OAuth client ID.
domain: 'myapp.auth.ing', // Required. Your tenant domain.
redirectUri: '/callback', // Optional. Default redirect URI.
scopes: ['openid', 'profile'], // Optional. Default: ['openid']
audience: 'https://api.myapp.com', // Optional. API audience for access tokens.
});| Option | Type | Required | Description |
|---|---|---|---|
clientId | string | Yes | Your OAuth client ID from the dashboard. |
domain | string | Yes | Your tenant domain (e.g., myapp.auth.ing). |
redirectUri | string | No | Default redirect URI after authentication. |
scopes | string[] | No | OAuth scopes to request. Default: ['openid']. |
audience | string | No | API audience identifier for access tokens. |
loginWithRedirect()
Redirects the user to the PasskeyBase hosted login page. After authentication, the user is redirected back to your redirectUri with an authorization code.
// Redirect to hosted login page
await pb.loginWithRedirect();
// With options
await pb.loginWithRedirect({
redirectUri: '/custom-callback',
scopes: ['openid', 'profile', 'email'],
state: 'custom-state-value',
});handleRedirectCallback()
Call this method on your callback page. It extracts the authorization code from the URL, exchanges it for tokens using the PKCE code verifier, and returns the result.
const result = await pb.handleRedirectCallback();
// result: {
// accessToken: string;
// idToken: string;
// expiresIn: number;
// tokenType: 'Bearer';
// state?: string;
// }enrollPasskey()
Opens a popup window where an already-authenticated user can create a new passkey and link it to their account. Requires an enrollment token from your backend.
// Enroll a passkey for an already-authenticated user
await pb.enrollPasskey(enrollmentToken);
// With options
await pb.enrollPasskey(enrollmentToken, {
popupWidth: 500,
popupHeight: 600,
});
// enrollmentToken is obtained from your backend via the Management APIlogout()
Ends the user's session and optionally redirects to a specified URL.
// Redirect to logout endpoint
await pb.logout();
// With post-logout redirect
await pb.logout({
returnTo: window.location.origin,
});TypeScript Types
All types are exported from the package and can be imported directly.
interface PasskeyBaseOptions {
clientId: string;
domain: string;
redirectUri?: string;
scopes?: string[];
audience?: string;
}
interface LoginWithRedirectOptions {
redirectUri?: string;
scopes?: string[];
state?: string;
}
interface AuthResult {
accessToken: string;
idToken: string;
expiresIn: number;
tokenType: 'Bearer';
state?: string;
}
interface EnrollPasskeyOptions {
popupWidth?: number;
popupHeight?: number;
}
interface LogoutOptions {
returnTo?: string;
}