Skip to content

Integrate with the libraries

Pick the Authio library for each kind of application, take a client from the console to its first call, see what each access token format asks of every library, and call the Admin API from Node.js and .NET.

Authio publishes libraries for Node.js, on npm under the @hyper.authio organization, and for .NET, on NuGet under the Authio. prefix. Every one of them takes the realm’s issuer, the client ID and, for a confidential client, a secret or a private key. They read the endpoints and the keys from the discovery document, validate what comes back and already understand Authio’s claims. None of them assumes anything about the client: what it is registered with (PKCE, authentication method, algorithm, token format) you declare in the library’s configuration, and what does not match is refused.

Pick the library

The applicationNode.js.NET
A Next.js web app, signing in on the server@hyper.authio/provider-nextauth 6.2.0, on Auth.js v5 or NextAuth v4—
A SPA (React, Vue, Angular) with no tokens in the browser@hyper.authio/bff 0.15.0, on an Express serverAuthio.AspNetCore.Bff 0.12.0
A SPA or a native app that keeps its own tokensNo Authio library keeps tokens in the browser: oidc-client-ts or another certified OpenID Connect library; see Any OIDC clientAuthio.Client 0.12.0, with IAuthioLoginClient, in a desktop app, a mobile app or a CLI
An API that validates tokens@hyper.authio/express 0.15.0 on Express, or @hyper.authio/server 0.15.0 on another frameworkAuthio.AspNetCore 0.12.0
A worker, a job or a CLI, with nobody signed in@hyper.authio/client 0.15.0Authio.Client 0.12.0
Automating the console through the Admin API@hyper.authio/admin 0.15.0Authio.Client 0.12.0
Tests without a real realm@hyper.authio/testing 0.15.0Authio.Testing 0.12.0
An MCP server@hyper.authio/mcp 0.8.0Authio.Mcp.AspNetCore 0.8.0

The Node.js packages need Node.js 20.19 or later and work as ES modules and CommonJS (@hyper.authio/mcp is ESM only). The .NET packages run on .NET 8 and .NET 10. The six @hyper.authio/* packages of the Node.js SDK and the @hyper.authio/cli CLI are released together, under one version, and so are the four Authio.* ones; the Next.js provider and the MCP packages have versions of their own.

From the client to the first call

  1. Create the client

    In Clients, click New client and pick the Kind of application: Web application for an app with a server (Next.js or a BFF), Single-page or native app for code that runs in the browser or on the device, Machine for a service with nobody signed in. The kind sets Client authentication, PKCE and the grants. A server keeps a secret; a browser and an installed app cannot.

  2. Register where the sign-in returns

    Under Configuration, add the app’s Redirect URIs, character for character, one per environment. A Machine client needs none.

    The applicationRedirect URIAlso register
    Next.js (Auth.js or NextAuth)https://<your app>/api/auth/callback/authioThe signed-out page under Post-logout redirect URIs
    BFF (.NET or Express)https://<your app>/signin-oidc/signout-callback-oidc under Post-logout redirect URIs and /bff/backchannel-logout as the Back-channel logout URI
    SPA with oidc-client-tsThe route that calls signinCallback(), such as https://<your app>/callbackThe app’s origin among the client’s allowed origins
  3. Keep the secret

    For a confidential client, the secret is shown once, in the dialog that opens when you click Create client: copy it to the application’s secret store and click I’ve copied it. No read of the client returns the value; to replace it, use Revoke and generate new secret in the Security section. To keep no secret at all, register a public key on the client and authenticate with private_key_jwt.

  4. Allow the scopes

    openid, profile and email for the sign-in, offline_access to be issued a refresh token, roles for roles and permissions to reach the token, and the scopes of your APIs. A scope the client does not allow is refused at the authorization request.

  5. Pick the access token format

    Under Security › Token Configuration, the Access Token Format starts at JWT (self-contained). Lightweight and Opaque (reference) ask whoever reads the token to introspect it: see Access token formats before changing it. The Refresh Token Format, under Token Lifetime Settings, changes no code.

  6. Pick where the app keeps its session

    For a web app with a server (a confidential client with authorization_code), Security › Application Session declares the Application Session Model: Cookie, the default, keeps the tokens in the session cookie; Hybrid keeps them in Redis and the claims in the cookie; Server keeps everything in Redis. Authio only stores the choice, and the Next.js recipe of the Guide follows it: see Application session model.

  7. Open the client’s Guide

    In the client page’s header, Guide writes the recipe for each kind of application with that client’s own values: issuer, client ID, scopes, authentication method, algorithms and token format. At the top, Before you start lists what stops the recipe from working and the decisions worth making now, each with the shortcut to its setting.

  8. Install and configure

    Node.jsBash
    npm install @hyper.authio/provider-nextauth@^6.2.0 next-auth@5.0.0-beta.32   # Next.js
    npm install @hyper.authio/express@^0.15.0 express        # an Express API
    npm install @hyper.authio/bff@^0.15.0 express            # the host of a SPA
    npm install @hyper.authio/client@^0.15.0                 # a worker
    npm install -D @hyper.authio/testing@^0.15.0             # tests

    Copy the recipe from the Guide, or follow the library’s page: Next.js, Node.js, .NET and MCP.

  9. Test it

    The Guide’s last step ticks itself off when the first token is issued to the client. Under Tools, Test it in the bench opens the client in the Wire Bench, which sends real requests and shows what came back, and Watch it live shows its sign-ins on the Live Auth Stream. For an API, test the negative case too: no token, 401; without the scope or the permission, 403.

Access token formats

Each client chooses how Authio hands out its access tokens. The ID token stays a JWT in every format, and the introspection answer always carries every claim of the complete token.

FormatWhat the token carriesWhoever reads it needs
JWT (self-contained), Jwt, the defaultEvery claim: roles and permissions (*_resource_access), subscription, profile and emailNothing: it validates locally, against the realm’s JWKS. Introspection is only there to notice revocations before the token expires.
Lightweight, LightweightOnly who signed in and how: sub, aud, exp, client_id, scope, sid, acr, amr, act, org_id…Introspection, for the roles, the permissions, the plan, the profile and the email. The signature is still checked locally.
Opaque (reference), ReferenceNothing: an opaque handleIntrospection, for everything.

What each library asks for

LibraryLightweightOpaque (reference)
@hyper.authio/provider-nextauth 6.2.0accessTokenClaims: 'introspection'Nothing: it introspects by default
@hyper.authio/bff 0.15.0accessTokenClaims: 'introspection'Nothing: it always introspects
Authio.AspNetCore.Bff 0.12.0Authio:Bff:AccessTokenClaims = IntrospectionNothing: it always introspects
@hyper.authio/server and @hyper.authio/express 0.15.0introspection: 'activeCheck' or 'introspectionOnly'introspection: 'introspectionOnly'
Authio.AspNetCore 0.12.0Introspection = ActiveCheck or IntrospectionOnlyIntrospection = IntrospectionOnly
@hyper.authio/mcpintrospection: 'activeCheck' or 'introspectionOnly', from 0.6.0introspection: 'introspectionOnly'
Authio.Mcp.AspNetCoreIntrospection = ActiveCheck or IntrospectionOnly, from 0.6.0Introspection = IntrospectionOnly
@hyper.authio/client, Authio.Client and oidc-client-tsNothing: they only send the tokenNothing: they only send the token

No library guesses the format from the claims a token lacks. Without the option, a lightweight token is still valid but arrives without roles: checkAccess and every role or permission rule refuse it. On Next.js and the BFFs, introspection costs one request per sign-in and per refresh, and navigating costs none. On an API, the answer is cached per jti for 30 seconds, never past the token’s expiry. With activeCheck, a claim the token carries keeps its signed value, and the answer only adds the ones it lacks.

auth.ts (Next.js)TypeScript
import { createAuthio } from '@hyper.authio/provider-nextauth/v5'

export const authio = createAuthio({
  checks: ['pkce', 'state', 'nonce'],
  // Lightweight: roles and permissions come from Authio's introspection.
  accessTokenClaims: 'introspection',
})

On a .NET API, introspection also needs builder.Services.AddAuthioClient(builder.Configuration.GetSection("Authio")) beside the bearer scheme. On the BFF, AddAuthioBff already calls it.

The platform’s client is always a JWT

The client the console signs in through offers neither Lightweight nor Opaque: the console and the Admin API read its permissions from the access token, so it always receives the complete JWT.

When introspection fails

On Next.js and the BFFs, what happens depends on the option and on the moment:

Introspection of the access tokenAt sign-inOn a refresh
With accessTokenClaims: 'introspection', answers active: falseThe sign-in failsThe session ends
With accessTokenClaims: 'introspection', fails (network, 429, 5xx)The sign-in failsThe session keeps its claims until the next refresh
Without the option, opaque token, answers active: falseThe sign-in goes on without those claimsThe session keeps its claims
Without the option, opaque token, failsThe sign-in failsThe session keeps its claims until the next refresh

On a refresh, the new tokens are always kept, since the refresh token may already have rotated. On an API, activeCheck and introspectionOnly refuse the request while Authio does not answer.

Who can introspect a token

Authio answers introspection according to who asks (RFC 7662). A token requested with resource (RFC 8707) is active only to the resource server’s Introspection client; to the client that requested it, it answers active: false. A token requested without resource belongs to the client itself and answers to it. That is why an API introspects with the credentials of its resource server’s introspection client, while Next.js and the BFFs, which use the client’s own, only read the claims of tokens requested without resource. Introspection always needs a client that authenticates: a public client cannot do it.

Reference refresh tokens

Under Token Lifetime Settings, the Refresh Token Format can be Opaque (reference): the client receives an opaque 43-character value, and Authio keeps the token behind it. No library reads the refresh token, they only send it back to Authio on a refresh, on /revoke and on /introspect, so the code does not change. The change applies to the refresh tokens issued after it.

Application session model

Under Application Session, the Application Session Model says where the web app keeps the session of the people who sign in: Cookie (the tokens in the cookie, past 4 KB once they are encrypted), Hybrid (the tokens in Redis, the claims in the cookie, about 1 KB to 3.5 KB) or Server (everything in Redis, a few hundred bytes in the cookie). It shows for a confidential client with authorization_code and for the platform’s client; a public client keeps its tokens in the browser or on the device, and a machine signs nobody in. Nothing changes in the tokens. With @hyper.authio/provider-nextauth, Hybrid is a sessionStore and Server adds sessionClaims: 'store' (6.0.0): see Three session models.

The Admin API from the libraries

Both SDKs carry a client for the Admin API, the API behind the console. On Node.js, @hyper.authio/admin covers every operation under /api/v1/admin, typed from the API’s OpenAPI document and grouped by area, such as admin.realm.getByRealmId or admin.secret.create. The routes of Authio AI, under /api/v1/admin/assistant/, are the console’s own and stay out (0.14.0). On .NET, IAuthioAdminClient, which AddAuthioClient registers from Authio.Client, covers the users of a realm and of a client, role assignment, roles, imports, sessions, groups and account credentials; the other routes are called through an HttpClient with the same credential, as Routes without a method in .NET shows. Both authenticate with an account credential, unwrap the response envelope, retry once an idempotent call answered 429 or 503 with Retry-After, and throw a typed error when the API refuses.

Authenticate with an account credential

Create the credential in API secrets, as the Admin API reference walks through, give it only what the job needs and keep its value out of source control. An API key (ak_…) or a personal access token (pat_…) is sent as it is; an account client secret (cs_…) is first exchanged for a short-lived token at the authio realm, under the client ID cred_ followed by the credential’s ID without dashes. An exchanged token can be narrowed further with administration scopes.

CredentialNode.js: createAuthioAdminClient.NET: the Authio section
API key, ak_…credential, sent as Authorization: Bearer, or as x-api-key with presentAs: 'x-api-key'AdminCredential, with AdminAuthentication ApiKey (x-api-key, the default) or Bearer
Personal access token, pat_…credential, sent like an API key, or exchanged first with exchangePersonalAccessToken: trueAdminCredential, with AdminAuthentication ApiKey, Bearer or PersonalAccessTokenExchange
Account client secret, cs_…credential and credentialId, the credential’s ID (or its cred_… client ID); always exchangedAdminCredential, with AdminAuthentication ClientCredentials and AdminClientId set to its cred_… client ID
Narrowing an exchanged tokenscopes: ['admin:user:read']AdminScopes, such as ["admin:user:read"]; refused with ApiKey and Bearer
admin.ts (Node.js)TypeScript
import { createAuthioAdminClient } from '@hyper.authio/admin'

export const admin = createAuthioAdminClient({
  authority: 'https://authio.api.hyperio.tech',
  credential: process.env.AUTHIO_ADMIN_CREDENTIAL!, // ak_…, pat_… or cs_…
  credentialId: process.env.AUTHIO_ADMIN_CREDENTIAL_ID, // only for a cs_ secret
})

const realm = await admin.realm.getByRealmId({ realm: 'acme' })
const page = await admin.realmClient.getClientsPaginated({ realm: 'acme', pageSize: 50 })

Routes without a method in .NET

On Node.js, @hyper.authio/admin has a method for every route. On .NET, a route IAuthioAdminClient does not cover, such as reading a realm or putting a client in quarantine, is called through a named HttpClient given AddAuthioAccountCredential() from Authio.Client. It authenticates every call with the credential of the Authio section (AdminCredential, as AdminAuthentication says), exchanges a cs_… (or a pat_…, with PersonalAccessTokenExchange) for a token, which it keeps and renews on a 401, and retries once an idempotent call answered 429 or 503 with Retry-After. It needs AddAuthioClient registered. Point the BaseAddress at https://authio.api.hyperio.tech/api/v1/admin/, with the trailing slash, and call each route by its relative path, with no leading slash.

Node.jsTypeScript
const realm = await admin.realm.getByRealmId({ realm: 'acme' })

await admin.clientQuarantine.start({
  body: { realmId: 'acme', clientId: 'acme-web', access: 'Closed', endsAccess: true },
})

That client only authenticates and retries: it neither unwraps the { statusCode, success, notifications, data } envelope nor throws AuthioAdminApiException. Read the result in data and handle a refusal by its status, its errorCode and the body’s notifications, which Error codes explains. Every route, with the body it takes, is in the Admin API reference.

Give a credential Admin API permissions

An API key, an account client secret or a personal access token can hold permissions of the Admin API directly, without a role: its adminScopes, each written admin:{permission}:{method}, such as admin:realm:read. They are what the credential’s page in API secrets shows as Admin API permissions, and they are still narrowed to what whoever made the credential may do today; a realm scope (allowedScopeIds) gives nothing on the Admin API. On an update, adminScopes left out or null keeps the ones the credential has, [] takes them all away and a list replaces them. A value that names no permission and method is refused with 400 ValidationFailed (AdminScopeInvalid on adminScopes), and one you do not hold with 403 WiderThanCaller, with nothing changed.

An update is a PUT that replaces the rest of the credential: the name, the description, the expiry, whether it is active, its roles and its scopes. On Node.js, send secret.update everything you keep, as secret.getById reads it. On .NET, start from ToUpdateRequest() and change only what has to change with with { … }; AuthioAdminPermissions, AuthioAdminMethods and AuthioAdminScopeFormatter build the values.

Node.jsTypeScript
const credential = await admin.secret.create({
  body: {
    name: 'nightly-sync',
    type: 'ApiKey',
    adminScopes: ['admin:user:read', 'admin:user:update'],
  },
})

store(credential.value!) // the only answer that carries the value

`Description` is required in `Authio.Client` 0.11.0

Authio clears the description an update leaves out, so AuthioAdminUpdateSecretRequest.Description became required, like every other member the PUT resets. A request built with ToUpdateRequest() copies it and needs no change; one built by hand stops compiling until it names the description to keep (null clears it). Code already compiled keeps running. On Node.js, secret.update sends what you give it: leave description out and it is cleared.

Read what a refusal says

A refusal throws AuthioAdminError on Node.js and AuthioAdminApiException on .NET, with the HTTP status, the errorCode to branch on, the notifications, the request ID and the Retry-After of a 429 or 503. When the refusal explains itself with an object in the envelope’s data, @hyper.authio/* 0.12.0 keeps it in AuthioAdminError.data and Authio.Client 0.11.0 in AuthioAdminApiException.ErrorData. Two refusals say what to do next there:

errorCodeWhat data holdsNode.js.NET
WiderThanCaller (403)adminScopes: the Admin API permissions you may not give, because you, the calling credential or the narrowed token do not hold themrefusedAdminScopesOf(error)GetRefusedAdminScopes()
SecondFactorConfirmationRequired (400)methods: what the account can prove itself with, among AuthenticatorApp, RecoveryCode, Password and Passkey; empty when only an administrator can helpsecondFactorConfirmationMethodsOf(error)GetSecondFactorConfirmationMethods() (0.12.0)

The two Node.js helpers answer undefined for any other error, so they double as the check; on .NET, GetRefusedAdminScopes() answers an empty list and GetSecondFactorConfirmationMethods() null. GetErrorData<T>() reads any data as a type of yours, and answers default when there is none or it does not fit. Every code, with what to do about it, is in Error codes.

Node.jsTypeScript
import { AuthioAdminError, refusedAdminScopesOf } from '@hyper.authio/admin'

try {
  await admin.secret.create({
    body: { name: 'realm-reader', type: 'PersonalAccessToken', adminScopes: ['admin:realm:read'] },
  })
} catch (error) {
  if (!(error instanceof AuthioAdminError)) throw error

  error.errorCode // 'WiderThanCaller'
  error.data // { adminScopes: ['admin:realm:read'] }
  refusedAdminScopesOf(error) // ['admin:realm:read']
}

Prove the second factor

Taking a second factor off your own account (turning the authenticator app off, issuing new recovery codes, removing one of your passkeys or phones) asks for proof that the account is yours, and so does turning the app on next to a factor you already have; see Removing your own factor. The proof is a code the app shows now or an unused recovery code, as { code }, the password, as { password }, or one of the account’s passkeys, as { passkey: { ceremonyId, assertion } } (@hyper.authio/admin 0.13.0). These routes act on whoever calls and accept only a person signed in, never an API key or a personal access token, so the client authenticates with that person’s access token, in accessToken.

Node.jsTypeScript
import { createAuthioAdminClient, secondFactorConfirmationMethodsOf } from '@hyper.authio/admin'

const me = createAuthioAdminClient({
  authority: 'https://authio.api.hyperio.tech',
  accessToken: () => getAccessToken(), // a person signed in to the console
})

try {
  await me.passkey.removeMine({ passkeyId })
} catch (error) {
  const methods = secondFactorConfirmationMethodsOf(error) // ['AuthenticatorApp', 'Password', 'Passkey'], or undefined
  if (!methods) throw error

  await me.passkey.removeMine({ passkeyId, body: { code: await askForCode(methods) } })
}

await me.totp.enable({ body: { code: newAppCode, confirmation: { password } } })

totp.disable, totp.regenerateRecoveryCodes and passkey.removeMine take the proof as body, and so do userTotp.reset, passkey.revoke and authenticatorDeviceAdmin.revokeDevice when the person they name is you; totp.enable takes it in confirmation, beside the new app’s code. totp.getStatus() says beforehand whether it will be asked (holdsSecondFactor), whether the account has a password (hasPassword) and whether it has a passkey (hasPasskey, 0.13.0). Without it the call is refused with SecondFactorConfirmationRequired, whose data.methods lists Passkey when the account has one; a wrong proof answers SecondFactorConfirmationInvalid and counts toward the realm’s lockout. On .NET, IAuthioAdminClient calls none of these routes, nor the one behind beginProof(): they are the person’s own (/users/me/…), and it authenticates with an account credential, which they refuse. A refusal that reaches .NET some other way, such as in a test with Authio.Testing, is read with GetSecondFactorConfirmationMethods() (Authio.Client 0.12.0), which lists Passkey among the methods as secondFactorConfirmationMethodsOf does on Node.js.

A passkey is confirmed in the person’s browser, never on the server: the server only asks Authio for the options and relays the assertion the browser returns, untouched, as the proof, and Authio checks it. passkey.beginProof() answers { ceremonyId, options }, a challenge that holds once, for the installation’s ceremony time, with the account’s passkeys. Like the routes that take the proof, it is the person’s own, so the client is created with that person’s accessToken; an API key or a personal access token is refused with 403. The page runs the ceremony with the options and sends back the assertion as PublicKeyCredential.toJSON() writes it. It has to be on an origin the installation accepts for its passkeys, which Authio lists at /.well-known/webauthn; elsewhere the browser refuses the ceremony, so keep the code and the password on offer. Ask for new options for every proof, since the challenge is spent whether the proof holds or not: a passkey that does not hold, or a challenge that expired, answers SecondFactorConfirmationInvalid with the notification on the passkey field, and beginProof() answers NoCredentialsRegistered for an account without a passkey.

Node.jsTypeScript
// On the server: a challenge for the passkeys of the person signed in
const { ceremonyId, options } = await me.passkey.beginProof()

// In the browser: the ceremony, and the assertion back to the server as JSON
const credential = await navigator.credentials.get({ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(options) })
const assertion = (credential as PublicKeyCredential).toJSON()

// On the server: the proof, as it came
await me.passkey.removeMine({ passkeyId, body: { passkey: { ceremonyId, assertion } } })
// or, turning the app on: me.totp.enable({ body: { code: newAppCode, confirmation: { passkey: { ceremonyId, assertion } } } })

Next steps