Docs/Applications

Integrate an application

An application is an OAuth 2.0 and OpenID Connect client: an external SaaS app, a native app or a machine service whose users sign in through Thoryn, or that calls APIs protected by Thoryn. Registering one is the primary integration workflow. Without a registered client, an app cannot start an OAuth flow.

A tenant administrator, or a machine client with the right scopes, can:

  • Register an application with a display name, redirect URIs, grant types, a client type and a set of scopes.
  • Retrieve credentials: the clientId and, for a confidential client, the clientSecret, which is shown exactly once.
  • Run the OIDC flow: the app follows the tenant's discovery document and runs the Authorization Code flow with PKCE against the tenant issuer.
  • Rotate the secret with a 24-hour overlap, and follow token usage over the last 24 hours or 7 days.

You do this on the Applications page in the console. The same operations are available on the management API below, for automation and for the thoryn CLI.

Register an application

POST /api/v1/applications with the tenant:applications.write scope:

request
POST /api/v1/applications
Authorization: Bearer <tenant-admin token>
Content-Type: application/json

{
  "displayName": "Acme Portal",
  "redirectUris": ["https://app.acme.example/login/oauth2/code/thoryn"],
  "scopes": ["openid", "profile", "email", "offline_access"],
  "grantTypes": ["authorization_code", "refresh_token"],
  "clientType": "confidential"
}
  • clientId: optional. When you leave it out, Thoryn generates one (app-<12 hex>). You cannot supply a clientSecret: Thoryn generates it, so the plaintext never comes from a browser. Some ids are reserved: product-api, any URL on a Thoryn token host (400 client_id_reserved), and the resource identifier of a protected resource in the same environment (409 client_id_is_resource_identifier).
  • redirectUris: required for a redirect-based grant. A pure machine client (client_credentials only) registers with an empty list. See Redirect URI rules.
  • grantTypes: defaults to ["authorization_code", "refresh_token"]. Can be changed later with PATCH.
  • clientType: confidential (default) or public. Cannot be changed after creation.
  • scopes: a subset of the scopes you hold yourself (see Scopes you can grant). An authorization_code client sent with no scopes gets openid, profile and email.

The response returns the clientSecret once (null for a public or keyed client). Store it right away. Later reads leave it out.

201 Created
{
  "clientId": "app-3f9c1a20b7e4",
  "clientSecret": "s3cr3t-shown-once...",
  "createdAt": "2026-07-16T09:30:00Z",
  "displayName": "Acme Portal",
  "redirectUris": ["https://app.acme.example/login/oauth2/code/thoryn"],
  "scopes": ["openid", "profile", "email", "offline_access"],
  "grantTypes": ["authorization_code", "refresh_token"],
  "status": "active"
}

Creating a production confidential application that gets a secret, or that registers a jwksUri or jwks, is an elevated action. It requires a passkey sign-in from the last five minutes. Sandbox applications and public clients are not affected.

Client types

The client type decides how the app authenticates to the token endpoint:

  • Confidential: keeps a secret on a server it controls. The default for a server-side integration.
  • Public: a SPA or native app that holds no secret. PKCE (RFC 7636) is mandatory and takes the place of the secret.
  • Keyed: authenticates with a private key (private_key_jwt). Register the public key as an inline jwks JWK Set, a hosted jwksUri (HTTPS only), or both. No secret is generated. A hosted key set must be served at the registered URL itself (redirects are not followed), be at most 64 KiB and arrive within 5 seconds. An inline set with a private or symmetric key is refused (400 jwks_private_member), so a private key pasted by mistake is never stored.

A GitHub Actions workflow needs none of these. A workload identity trust gives it a client without a secret that authenticates with the job's own OIDC token. That client is managed only through its trust.

Run the Authorization Code flow with PKCE

Each tenant is its own OIDC issuer, on its own host: https://{slug}.auth.<platformDomain>. Always start from discovery. The discovery document points the authorization, token, userinfo and JWKS endpoints at the tenant's own host, so a client that follows it uses the right endpoints automatically.

discovery
GET https://{slug}.auth.<platformDomain>/.well-known/openid-configuration

The hosted sign-in screens live on the same host, under /id (for example /id/login). If you allowlist the sign-in host in a CSP form-action or a proxy rule, the issuer host is the one host to list.

The discovery document lists what the server supports: response modes, subject types (public and pairwise), claims, algorithms and the device authorization endpoint (RFC 8628). scopes_supported and grant_types_supported are specific to your tenant: a value appears only when at least one of your clients uses it. Read the document instead of hard-coding endpoints or capabilities.

Your exact issuer URL is shared when we set up your workspace. A full endpoint reference is coming. Ask us if you need it now.

1. Authorization request. Redirect the browser to the authorization endpoint with a PKCE challenge (mandatory for public clients, supported for all):

authorize request
GET /oauth2/authorize
  ?response_type=code
  &client_id=app-3f9c1a20b7e4
  &redirect_uri=https://app.acme.example/login/oauth2/code/thoryn
  &scope=openid%20profile%20email%20offline_access
  &state=<opaque>
  &code_challenge=<base64url(SHA256(verifier))>
  &code_challenge_method=S256

The user signs in, and Thoryn redirects back to your redirect_uri with code, state and iss.

Every authorization response, success or error, carries iss (RFC 9207): the issuer you sent the request to, exactly as in its discovery document. Compare it with the issuer you started from, as an exact string match, before you redeem the code or act on an error. Reject a mismatch or a missing value. This prevents mix-up attacks when your application talks to more than one authorization server. Most current OAuth libraries do this automatically.

2. Token request. Exchange the code at the token endpoint. A confidential client authenticates with its secret (shown here). A public client sends no secret and relies on the code_verifier. A keyed client sends a client_assertion.

token request
POST /oauth2/token
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
&code=<code>
&redirect_uri=https://app.acme.example/login/oauth2/code/thoryn
&code_verifier=<verifier>

You receive an access_token, an id_token (when openid was requested) and a refresh_token (when offline_access was granted). Validate the JWTs against the tenant's jwks_uri. Refresh later with grant_type=refresh_token.

3. UserInfo. Call GET /userinfo with the access token as a Bearer token to read the signed-in user's claims. /userinfo accepts only the access token. It does not accept the ID token.

Machine-to-machine. Register the client with grantTypes: ["client_credentials"], no redirect URI and at least one scope. Then request tokens directly from /oauth2/token with grant_type=client_credentials.

Sign in against a sandbox environment

A sandbox environment is its own OIDC provider, with its own issuer, discovery document, JWKS and endpoints. Its issuer is the tenant issuer plus the environment slug:

sandbox
iss: https://{slug}.auth.<platformDomain>/{env-slug}

GET https://{slug}.auth.<platformDomain>/{env-slug}
    /.well-known/openid-configuration

Point your client's discovery at the environment's document and everything else follows. Every endpoint in it carries the /{env-slug} prefix, and the issuer matches the iss in every sandbox token, so a standard OIDC library validates it without extra configuration. Clients that build the metadata URL the RFC 8414 way (MCP clients do this) find the same environment at /.well-known/oauth-authorization-server/{env-slug} and /.well-known/openid-configuration/{env-slug}.

  • The document exists only for an environment that exists and is not suspended. Anything else returns 404.
  • Right after you create an environment, its signing key can take a moment. The sandbox JWKS then returns 503 with Retry-After.
  • Environments are isolated. A sandbox sign-in always asks for credentials, so a production session never carries over into a sandbox. Single sign-on works as usual within one environment.
  • Login branding is set per environment. A sandbox uses its own branding.
  • The same client_id can be registered in production and in a sandbox, each with its own secret, redirect URIs and scopes. Using a sandbox secret against production, or the other way round, returns invalid_client.

If your library rejects sandbox tokens with an issuer mismatch, you discovered at the tenant issuer. Point discovery at the environment issuer.

Session lifetime

Two settings decide how long a signed-in user can keep refreshing without signing in again:

  • Sliding window: refreshTokenTtlSeconds. Every refresh issues a new refresh token that lives this long. A session unused for that long ends.
  • Absolute lifetime: refreshTokenAbsoluteMaxTtlSeconds. With refreshTokenSlidingWindow: true, no refresh token outlives sign-in plus this value, however active the session is.

A refresh past either limit is refused with invalid_grant. The error_description says which limit ended the session: refresh_token_expired or session_lifetime_exceeded. Show the user a sign-in prompt in both cases. For example, an admin tool with a 1-hour idle window that ends after 8 hours:

session settings
{
  "refreshTokenTtlSeconds": 3600,
  "refreshTokenSlidingWindow": true,
  "refreshTokenAbsoluteMaxTtlSeconds": 28800
}
  • The absolute lifetime only works with the sliding window on (400 session_lifetime_requires_sliding_window).
  • The absolute lifetime must be at least the sliding window (400 session_lifetime_below_refresh_ttl).
  • The workspace's authentication policy can cap both. The stricter value always wins, and lowering the cap later also ends existing sessions at their next refresh.
  • A shorter lifetime takes effect immediately. Every change is in the audit trail.

Token lifetimes have platform maximums. A value outside them is refused with 400 token_ttl_out_of_range.

The full list of advanced OAuth settings and their limits is coming. During early access we share it on request: get in touch.

Token exchange (RFC 8693)

An application that signed a user in can exchange that user's access token for another token at the token endpoint. Common cases are downscoping a token for a downstream API and entering another workspace the user belongs to (pass the workspace in resource). Register the urn:ietf:params:oauth:grant-type:token-exchange grant and turn on allowTokenExchange, which is off by default:

request
{
  "displayName": "Acme Portal",
  "redirectUris": ["https://app.acme.example/login/oauth2/code/thoryn"],
  "grantTypes": ["authorization_code", "refresh_token",
                 "urn:ietf:params:oauth:grant-type:token-exchange"],
  "clientType": "confidential",
  "allowTokenExchange": true
}

Every exchange is checked: the subject token must be valid, the scope never grows beyond what the subject token and the application hold, and entering a workspace requires the user to be its founder or an active member. A sender-constrained token (DPoP or mTLS) can only be exchanged with a proof of the same key, and the new token stays bound to that key.

Because this setting lets an application obtain fresh tokens for a user across workspaces, it is an environment-level decision. An identity that manages only a single application, such as a repository's CI identity, cannot turn it on.

Rotate the client secret

Confidential clients rotate with a 24-hour overlap, so no request is dropped during a deploy:

request
POST /api/v1/applications/{clientId}/secret/rotate
Authorization: Bearer <token with tenant:applications.write>
  • The new secret is active immediately and returned once as newSecret.
  • The previous secret keeps working for 24 hours (oldSecretExpiresAt).
  • One rotation at a time. Starting a second one inside the window returns 409 rotation_in_flight.
  • GET /api/v1/applications/{clientId}/secrets/state shows the overlap and whether a new rotation may start (rotationAvailable).

When a secret leaks or gets lost

Two actions cover incidents where waiting 24 hours is not an option. Both must be done by a person who signed in with a passkey in the last five minutes. Otherwise the answer is 403 with a step-up challenge (RFC 9470): sign in again and retry. Both are audited.

The previous secret leaked. End it now:

request
POST /api/v1/applications/{clientId}/secret/revoke-previous
Content-Type: application/json

{ "revokeTokens": true }

After this, only the current secret works. With revokeTokens: true, all sessions of the application are also ended, so its refresh tokens stop working. JWT access tokens already issued stay valid until they expire, at most the application's access-token lifetime. If the current secret is the one that leaked, rotate first and then revoke the previous one.

You lost the new secret before storing it. Replace the rotation in progress:

request
POST /api/v1/applications/{clientId}/secret/rotate
Content-Type: application/json

{ "replaceInFlight": true }

A new secret is returned once and the lost one stops working immediately. The previous secret keeps its original expiry, so there are never three valid secrets.

Scopes you can grant

  • You can grant a client any scope you currently hold yourself. A scope you do not hold is refused with 403 scope_not_grantable, and the whole request fails. This is checked on the server, whatever the console shows.
  • Each scopes[] entry must be a single scope token. A blank entry or several scopes in one entry is refused with 400 invalid_scope. With the CLI, use one --scope flag per scope.
  • A client_credentials client needs at least one scope, because a client without scopes can never get a usable token (400 invalid_scope).
  • openid, profile, email, address, phone and offline_access can always be granted.
  • admin:* scopes can never be granted by a tenant admin.

The full list of grantable tenant:* scopes is in the API reference. To add permissions, org and org_roles to the ID token, see Claims in the token.

Redirect URI rules

Redirect URIs are validated when you save them and matched exactly at /oauth2/authorize:

  • https:// is always allowed. http:// only for localhost, 127.0.0.1 and [::1] (local development, RFC 8252 §7.3). Every other scheme is refused.
  • No user info in the URL (https://user:pass@host/...) and no fragment.
  • A host that resolves to a private, loopback, link-local or multicast address, or to the cloud metadata IP, is refused.

Management API

All paths are under /api/v1. The tenant comes from your token, never from the path. Responses use camelCase. Errors are RFC 9457 problem details (application/problem+json) with a stable errorCode.

endpoints
POST   /applications
GET    /applications
GET    /applications/{clientId}
PATCH  /applications/{clientId}
POST   /applications/{clientId}/secret/rotate
POST   /applications/{clientId}/secret/revoke-previous
GET    /applications/{clientId}/secrets/state

PATCH changes displayName, redirectUris, scopes, grantTypes and the advanced OAuth settings. clientId and clientType cannot be changed after creation.

Troubleshooting

A troubleshooting guide with every error code and its cause is coming. Stuck now? Get in touch and we help you directly.

Security notes

  • The secret is shown once and stored only as a bcrypt hash. A lost secret is rotated, never recovered.
  • Tenant isolation: access to another tenant's application returns 404, so nothing reveals that it exists.
  • Scope grants are limited to your own scopes and checked on the server.
  • Every change is audited. Each create, update, delete, rotation and revocation writes a tamper-evident row in the tenant audit trail.
  • Ending a secret early or replacing a rotation requires a person with a recent passkey sign-in. Ordinary rotation does not.