Extensions

Extensions

Extensions are your own code, run by Quasr, to customize or extend the platform. Each extension is a small Node.js function which Quasr builds and deploys for you, and runs either synchronously while a token is being issued, or asynchronously whenever a matching event occurs in your tenant.

Typical use cases are:

  • injecting custom claims or modifying scopes in access tokens and identity tokens, for example with data from your own systems
  • delivering One-Time Passwords (OTP) through your own email or SMS service (see External channel)
  • reacting to events in real time, for example syncing new signups to your CRM or alerting on failed logins

Synchronous (Tokens)

An extension can be linked to an application as its Access Token Extension (config.tokens.access.ext) and/or Identity Token Extension (config.tokens.identity.ext). The extension is then run right before the token is generated, and the object it returns is added to the token as custom claims.

  • Access token - The returned object replaces the scopes and adds custom claims. The granted scopes are passed in detail.scope.
  • Identity token - The returned object adds custom claims. The granted claims are passed in detail.claims.

Following rules apply to the returned object:

  • it must be a JSON object, anything else is ignored
  • registered claims (iss, aud, sub, iat, nbf, exp, jti), claims already set by Quasr (such as client_id) and claims starting with https://api.quasr.io/claims/ cannot be overwritten and are ignored
  • claims with the same name as a claim from your attributes overwrite that claim

If the extension fails (after retries, see Errors) or doesn't return an object, the token is still issued, but without any customization by the extension.

Asynchronous (Events)

An extension with a rule is run for every event in your tenant matching that rule. A rule filters on following event fields, which are described in the event catalog:

  • Types (config.rule.type: [string]) - The event types, e.g. AUTHENTICATION or COMMUNICATION.
  • Origins (config.rule.origin: [string]) - The event origins, e.g. the ID of a factor.
  • Actions (config.rule.action: [string]) - The event actions, e.g. send-otp.
  • Results (config.rule.result: [string]) - The event results, i.e. SUCCESS, PENDING or FAILED.
  • Reasons (config.rule.reason: [string]) - The event reasons, e.g. DELIVERY_PENDING.
  • Accounts (config.rule.account: [string]) - The IDs of the accounts the event concerns.

An event matches when, for every field that is set, its value is one of the listed values. Fields which are not set match any value. A rule only ever matches events of your own tenant.

The rule of an extension can only be changed while the extension is disabled (see Lifecycle).

  1. 1The event types to run for, here registrations
  2. 2Only Enable Account events: when a signup is completed
  3. 3Only successful events

Code

The code of an extension is a single JavaScript (CommonJS) file which exports an asynchronous handler function. It receives the event as only argument and runs on Node.js 24, so you can use the built-in modules and fetch to call your own services. Other npm packages are not available. A new extension starts from following code:

exports.handler = async function(event) {   console.log(event);}

The event passed to the extension is the event which triggered it, extended with:

  • variables - The (decrypted) variables of the extension, see Configuration.
  • claims - The claims of the account the event concerns, for each of the attributes configured on the extension. For attributes which require validation an additional {claim}_verified boolean is included.

For example, an access token extension receives:

{    "type": "CUSTOMIZATION",    "origin": "{client_id}",    "action": "create-token",    "result": "PENDING",    "tenant_id": "{tenant_id}",    "account_id": "{account_id}",    "detail": {        "source": "oauth2/token",        "subtype": "oauth2:access",        "scope": [            "openid",            "email"        ]    },    "variables": {        "api_key": "{api_key}"    },    "claims": {        "email": "jane@example.com",        "email_verified": true    }}

Asynchronous extensions receive the detail of the event as listed in the event catalog, including its values (which are passed to extensions but never logged).

  1. 1Passed to the code as event.variables, and stored encrypted
  2. 2The claims of these attributes are passed as event.claims
  3. 3Read-only while the extension is enabled

Logs

Every line your extension logs (e.g. with console.log) becomes a Log Extension event with the extension's ID as origin, which you can view in the Events tab of the extension in the Admin UI or through the listEvents operation of the Management API. Lines logged with console.error get result FAILED. Every run produces a Run Extension event with result SUCCESS or FAILED.

The runs and logs of an extension, in its Statistics

Its Run Extension and Log Extension events, in its Events tab

Errors

When an extension throws an error or times out, the run is retried up to 5 times with an increasing delay (1, 2, 4, 8 and 16 seconds). If it still fails, a Run Extension event with result FAILED is produced.

Configuration

An extension has following properties:

  • Label (label: string) - A name for the extension, defaults to Extension.
  • Status (status: string) - One of PENDING, ENABLED, DISABLED or LOCKED, see Lifecycle.
  • Runtime (config.runtime: string) - The runtime of the extension. Currently only nodejs24.x is supported, which is also the default.
  • Latency (config.latency: number) - The number of seconds to wait before running the extension, 0 (default). Enterprise tenants can set it between 0 and 60. Keep this at 0 for token extensions.
  • Timeout (config.timeout: number) - The maximum duration of a run in seconds, 5 (default). Enterprise tenants can set it between 5 and 30. Token extensions should finish well within 5 seconds, whatever their timeout.
  • Variables (config.variables: string) - A JSON object (as string) of values passed to the extension in event.variables, such as API keys of your own services. Variables are stored encrypted.
  • Attributes (config.attributes: [string]) - The IDs of the attributes whose claims are passed to the extension in event.claims.
  • Code (config.code: string) - The code of the extension (required), see Code.
  • Rule (config.rule: object) - The events which trigger the extension, see Asynchronous.

Following properties are read-only:

  • Memory (config.memory: number) - The memory available to the extension, 128 MB.
  • Concurrency (config.concurrency: number) - The maximum number of simultaneous runs, 25.
  • Build (build.status: string) - The status of the latest build: QUEUED, STARTED, SUCCEEDED or FAILED.
  • Statistics (statistics: object) - The number of pending, successful and failed runs and logs of the extension this month, updated daily.
  • Expires At (expires_at: string) - When the extension will be deleted if it isn't used, see Limits.

Lifecycle

Each extension is built and deployed as its own isolated function, which only has permission to write its logs.

  • PENDING - The extension is being built and deployed, which typically takes a few minutes. This happens when it's created or enabled.
  • ENABLED - The extension was deployed successfully and is run when triggered.
  • DISABLED - The extension is not deployed and not run. An extension also becomes disabled when its build fails, in which case build.status is FAILED.
  • LOCKED - The extension is not deployed and not run, and cannot be updated or deleted.

While an extension is enabled, only its label, latency, variables and attributes can be updated. To change its code, runtime, timeout or rule, first disable the extension, update it, and enable it again, which rebuilds and redeploys it.

Limits

  • A tenant can have up to 5 extensions by default (enabled or not); enterprise tenants can have up to 10 (see Tenants — Configuration). Creating more results in a QUOTA_REACHED error.
  • A new extension expires 1 day after its creation, and every successful run extends this to 30 days after that run. Unused extensions are therefore deleted automatically. On enterprise tenants, extensions created since the tenant became an enterprise tenant no longer expire once they have run successfully.
  • Runs are limited by the memory, timeout and concurrency listed in Configuration.
  • Values above the limits of the tenant's tier result in an INVALID_PARAMETER error, also when updating an extension whose value was set before these limits applied.

Management

Extensions can be managed via the Admin UI, the Management API or the Agent API.

  • Admin UI - In the Admin UI extensions are listed, and can be created, at https://{tenant_id}.admin.quasr.io/extensions.
  • Management API - In the Management API the createExtension, getExtension, listExtensions, updateExtension or deleteExtension operation can be used. These require admin scopes, see Authorization.
  • Agent API - In the Agent API the create-extension, get-extension, list-extensions, update-extension or delete-extension tool can be used, with the same admin scopes. The config.variables of an extension are redacted in tool results, see Redaction.
  1. 1The number of runs
  2. 2Has an event rule: an asynchronous extension (without one it runs for tokens)
  3. 3Receives the claims of attributes

Examples

Custom claims from your own system

An access token extension (no rule) which adds the customer tier from your own API, with { "api_key": "..." } as variables:

exports.handler = async function(event) {    try {        const response = await fetch(`https://api.example.com/customers/${event.account_id}`, {            headers: { 'Authorization': `Bearer ${event.variables.api_key}` }        });        const customer = await response.json();        return {            scope: event.detail.scope,            customer_tier: customer.tier        };    } catch (error) {        console.error(error.message);        return {            scope: event.detail.scope        };    }}
Deliver OTPs through your own service

An extension with a rule on type COMMUNICATION and action send-otp, for a One-Time Password factor with the External channel:

exports.handler = async function(event) {    const response = await fetch('https://api.example.com/messages', {        method: 'POST',        headers: {            'Authorization': `Bearer ${event.variables.api_key}`,            'Content-Type': 'application/json'        },        body: JSON.stringify({            to: event.values.input,            text: `Your code is ${event.values.otp}`        })    });    if (!response.ok) throw new Error(`Delivery failed (${response.status})`);}
2026.11.22 | © Copyright 2026 Quasr BV