PasskeyBase

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.

Initialization
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.
});
OptionTypeRequiredDescription
clientIdstringYesYour OAuth client ID from the dashboard.
domainstringYesYour tenant domain (e.g., myapp.auth.ing).
redirectUristringNoDefault redirect URI after authentication.
scopesstring[]NoOAuth scopes to request. Default: ['openid'].
audiencestringNoAPI 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.

loginWithRedirect()
// 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.

handleRedirectCallback()
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.

enrollPasskey()
// 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 API

logout()

Ends the user's session and optionally redirects to a specified URL.

logout()
// 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.

types.ts
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;
}