API reference
The public surface of
@thunderid/node, as documented in its reference pages.ThunderIDNodeClient`ThunderIDNodeClient` is an abstract base class that extends `ThunderIDJavaScriptClient` with Node.js-specific configuration. Use this class as the foundation when building a new framework-specific authentication client for a Node.js runtime. Examples include adapters for other Node.js server frameworks.
getAccessibleOrganizationUnits(config)Promise<AccessibleOrganizationUnitList>An exported function rather than a method. Lists the organization units the signed-in user can access, from `GET /users/me/ous`. Pass the access token from `getAccessToken(userId)` in `headers`.
getCurrentOrganizationUnit(userId?)Promise<CurrentOrganizationUnit | null>The organization unit the session was issued for, from its `ouId`, `ouHandle`, and `ouName` claims, or `null` when it names none. The claims are not verified, so use the result for display only.
switchOrganizationUnit(organizationUnitId, options)Promise<undefined>Builds the unit's authorization URL, `{baseUrl}/ou/{ouId}/oauth2/authorize`, and hands it to `options.authURLCallback` to redirect the user to. Complete it with `signIn(authURLCallback, userId, code, state)` on the callback, which redeems the code at `/ou/{ouId}/oauth2/token` and replaces the tokens of the session `options.userId`. Until then, and when the callback carries an error, the previous session stays as it was.
import { ThunderIDNodeClient, ThunderIDNodeConfig } from '@thunderid/node'interface MyFrameworkConfig extends ThunderIDNodeConfig {customOption?: string}class MyFrameworkClient extends ThunderIDNodeClient<MyFrameworkConfig> {// Add framework-specific methods or override inherited ones here}export default MyFrameworkClient
ThunderIDNodeConfig`ThunderIDNodeConfig` is the configuration type for the ThunderID Node.js SDK. The type extends the base `Config` from `@thunderid/javascript` and adds a Node.js-specific option for controlling session cookie lifetime.
import { ThunderIDNodeConfig } from '@thunderid/node'const config: ThunderIDNodeConfig = {clientId: '<your-client-id>',serverOrigin: 'https://localhost:8090',afterSignInUrl: 'http://localhost:3000/callback',afterSignOutUrl: 'http://localhost:3000',sessionCookieExpiryTime: 28800, // 8 hours}
CookieConfig`CookieConfig` is a constants class that exposes the default values used for session cookie configuration in the ThunderID Node.js SDK. Use these constants when setting cookies for session management or when passing options to `getSessionCookieOptions`.
import { CookieConfig } from '@thunderid/node'// Use the default session cookie nameres.cookie(CookieConfig.SESSION_COOKIE_NAME, sessionId, {httpOnly: CookieConfig.DEFAULT_HTTP_ONLY,maxAge: CookieConfig.DEFAULT_MAX_AGE * 1000, // convert to millisecondssameSite: CookieConfig.DEFAULT_SAME_SITE,secure: CookieConfig.DEFAULT_SECURE,})
CookieOptions`CookieOptions` defines the shape of cookie configuration options used in the ThunderID Node.js SDK. Pass a `CookieOptions` object to `getSessionCookieOptions` to override the default cookie settings.
interface CookieOptions {httpOnly?: booleanmaxAge?: numbersameSite?: boolean | 'lax' | 'strict' | 'none'secure?: boolean}
generateSessionId()`generateSessionId` generates a unique session identifier string. Use this utility to create a new session ID when a user signs in and store the value in a cookie or server-side session store.
import { generateSessionId, CookieConfig, getSessionCookieOptions } from '@thunderid/node'app.get('/sign-in', (req, res) => {const sessionId = generateSessionId()res.cookie(CookieConfig.SESSION_COOKIE_NAME,sessionId,getSessionCookieOptions({ maxAge: 3600 }),)auth.signIn((authUrl) => res.redirect(authUrl),sessionId,)})
getSessionCookieOptions()`getSessionCookieOptions` merges the provided partial `CookieOptions` with the default values from `CookieConfig`. Any property you omit falls back to its default.
optionsrequiredPartialCookie options to apply. Unspecified properties use the defaults from `CookieConfig`.
import { getSessionCookieOptions } from '@thunderid/node'// Override only maxAge; all other properties use defaultsconst options = getSessionCookieOptions({ maxAge: 86400 }) // 24 hours