Skip to main content

API reference

The public surface of

@thunderid/browser, as documented in its reference pages.

functionConfiguration

The `initialize()` method accepts a configuration object that controls how the SDK connects to your ThunderID instance and manages authentication.

Example
import { ThunderIDBrowserClient } from '@thunderid/browser'
const auth = new ThunderIDBrowserClient()
await auth.initialize({
clientId: '<your-client-id>',
baseUrl: 'https://localhost:8090',
})
functionEvent Hooks

The Browser SDK provides an event-driven system for reacting to authentication lifecycle events. Register callbacks using the `on()` method to respond to sign-in, sign-out, HTTP request events, and more.

Example
import { Hooks } from '@thunderid/browser'
auth.on(Hooks.SignIn, (user) => {
console.log('User signed in:', user.displayName)
})
auth.on(Hooks.SignOut, () => {
console.log('User signed out')
window.location.href = '/'
})
functionThunderIDBrowserClient

The `ThunderIDBrowserClient` is the core class of the `@thunderid/browser` SDK. It manages the full authentication lifecycle for browser-based applications, including sign-in, sign-out, token management, and authenticated HTTP requests.

Organization Unit Methods
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`. `scope: 'siblings'` narrows the list to the accessible units that share the parent of the current unit; `limit` and `offset` page it. Pass `fetcher: createHttpClientFetcher()` to attach the access token.

getCurrentOrganizationUnit()
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<User | undefined>

Signs in again, bounded to another organization unit, reusing the SSO session where it can. In redirect mode, it exchanges a device secret from a `device_sso` sign-in at `{baseUrl}/ou/{ouId}/oauth2/token`. Without one, it tries a silent `prompt=none` sign-in in a hidden iframe, then redirects to the unit's authorization endpoint unless `redirect` is `false`. App-native mode starts an `AUTHENTICATION` flow with `ouId`. Backend mode calls the backend's `ouSwitch` endpoint (`POST {ouSwitch}?ouId=<id>`, `/api/auth/switch` by default), reads the session again in place, and falls back to the backend's sign-in with `ouId` when the backend needs the user. A failed switch keeps the previous session, unless the backend reports that its session has ended, and throws a code from `OrganizationUnitSwitchErrorCodes`.

Example
import { ThunderIDBrowserClient } from '@thunderid/browser'
const auth = new ThunderIDBrowserClient()
await auth.initialize({
clientId: '<your-client-id>',
baseUrl: 'https://localhost:8090',
afterSignInUrl: window.location.origin,
afterSignOutUrl: window.location.origin,
})
export default auth
ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.