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:
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.
detail.scope.detail.claims.scope (an array of strings or a space-delimited string), typically event.detail.scope or a subset of it, otherwise the access token will be issued without any scopes.Following rules apply to the returned object:
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 ignoredIf 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.
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:
config.rule.type: [string]) - The event types, e.g. AUTHENTICATION or COMMUNICATION.config.rule.origin: [string]) - The event origins, e.g. the ID of a factor.config.rule.action: [string]) - The event actions, e.g. send-otp.config.rule.result: [string]) - The event results, i.e. SUCCESS, PENDING or FAILED.config.rule.reason: [string]) - The event reasons, e.g. DELIVERY_PENDING.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).
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:
{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).
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
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.
An extension has following properties:
label: string) - A name for the extension, defaults to Extension.status: string) - One of PENDING, ENABLED, DISABLED or LOCKED, see Lifecycle.config.runtime: string) - The runtime of the extension. Currently only nodejs24.x is supported, which is also the default.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.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.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.config.attributes: [string]) - The IDs of the attributes whose claims are passed to the extension in event.claims.config.code: string) - The code of the extension (required), see Code.config.rule: object) - The events which trigger the extension, see Asynchronous.Following properties are read-only:
config.memory: number) - The memory available to the extension, 128 MB.config.concurrency: number) - The maximum number of simultaneous runs, 25.build.status: string) - The status of the latest build: QUEUED, STARTED, SUCCEEDED or FAILED.statistics: object) - The number of pending, successful and failed runs and logs of the extension this month, updated daily.expires_at: string) - When the extension will be deleted if it isn't used, see Limits.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.
QUOTA_REACHED error.INVALID_PARAMETER error, also when updating an extension whose value was set before these limits applied.Extensions can be managed via the Admin UI, the Management API or the Agent API.
https://{tenant_id}.admin.quasr.io/extensions.createExtension, getExtension, listExtensions, updateExtension or deleteExtension operation can be used. These require admin scopes, see Authorization.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.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 }; }}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})`);}