Skip to content
Scalekit Docs
Talk to an Engineer Dashboard

Organization-specific redirect URLs

Register one redirect URL pattern that Scalekit resolves to an organization-specific URL at runtime.

Multi-tenant applications often need a different callback URL for each customer. Instead of registering a separate redirect URL for every organization, you can register a single template that Scalekit expands per organization at runtime.

For example, https://{{slug}}/oauth/callback expands to https://auth.megasoft.com/oauth/callback for Megasoft and https://auth.betacorp.com/oauth/callback for Beta Corp, with no additional configuration needed.

VariableSourceExample value
{{slug}}Organization’s slug field. Can be a single DNS label (megasoft) or a full hostname (auth.megasoft.com).auth.megasoft.com
{{external_id}}Organization’s external ID from your system.megasoft-123
{{custom_domain}}Any key stored in the organization’s metadata.metadata.custom_domain = "auth.megasoft.com"

Add organization-specific URLs in Dashboard > Authentication > Redirects and type the URL pattern directly into the input field. These URLs are valid in all three redirect fields:

  • Allowed callback URLs: where Scalekit sends users after authentication
  • Post logout URL: where Scalekit sends users after logout
  • Initiate login URL: where Scalekit sends IdP-initiated login requests

Supported patterns for redirect URLs:

PatternExampleNotes
Subdomainhttps://{{slug}}.yourapp.com/callback{{slug}} is a single DNS label such as acme
Full hosthttps://{{slug}}/callback{{slug}} is a full hostname such as auth.megasoft.com
Custom domainhttps://{{custom_domain}}/callbackValue comes from org metadata
Path variablehttps://yourapp.com/{{slug}}/callbackVariable in the path component

At runtime, Scalekit substitutes each {{variable}} with its resolved value, validates the expanded URL against registered templates, and redirects the user. For logout, the organization is resolved from the active session; if the session has expired, template expansion is skipped and the redirect is rejected.

Set slug on an organization to expand {{slug}} templates. Store any key in organization metadata to use it as a custom variable like {{custom_domain}}. Setting just one is enough — use whichever fits your registered URL pattern.

Navigate to Organizations > Select an organization > Overview > Edit. Add the organization slug in the Slug field. Create Organization dialog showing the Slug field

npm install @scalekit-sdk/node

Create organization with slug and metadata
// Set slug, metadata, or both — each enables a different template variable.
const organization = await scalekit.organization.createOrganization(
'Megasoft',
{
slug: 'auth.megasoft.com',
metadata: { custom_domain: 'auth.megasoft.com' },
}
);

Pass organization_id and redirect URL in the authorization request

Section titled “Pass organization_id and redirect URL in the authorization request”

Pass the organization-specific redirect_uri and organization_id in the authorization request. Scalekit validates the redirect URL against the registered pattern using the organization’s slug or metadata. See set up login flow for the full auth call reference.

Authorization URL with organization_id
const redirectUri = 'https://auth.megasoft.com/oauth/callback';
const options = {
scopes: ['openid', 'profile', 'email'],
state: sessionStorage.oauthState,
organizationId: 'org_12345',
};
const authorizationUrl = scalekit.getAuthorizationUrl(redirectUri, options);
res.redirect(authorizationUrl);

If no organization is in scope, the template is not expanded and the request is rejected.

  1. Register the URL pattern

    In Dashboard > Authentication > Redirects > Allowed callback URLs, add the URL as https://{{slug}}/oauth/callback.

  2. Set the organization’s slug

    For Megasoft, set slug to auth.megasoft.com (see Set slug and metadata for an organization above).

  3. Pass the org-specific redirect URL and organization_id in the authorization request

    When a Megasoft user signs in, Scalekit validates the redirect_uri against the registered pattern using the organization’s slug:

    https://<SCALEKIT_ENV_URL>/oauth/authorize?client_id=...&redirect_uri=https://auth.megasoft.com/oauth/callback&organization_id=org_megasoft_123&...
  4. Scalekit validates and redirects

    Scalekit matches https://auth.megasoft.com/oauth/callback against the registered pattern https://{{slug}}/oauth/callback using Megasoft’s slug and redirects the user.