Skip to content
Developer guide

Ship enterprise SSO and SCIM without replacing auth.

RegionAuth sits between the customer identity provider and your application. You keep user records, sessions, authorization, and business logic in your existing stack.

Quickstart

  1. Create a RegionAuth workspace and select a default region: Singapore, Mumbai, or Frankfurt.
  2. Create an organization, add its verified domain, and copy your server-side API key.
  3. Install the adapter for your auth stack and add the RegionAuth callback route.
  4. Send the customer the generated setup link. Their IT admin supplies SAML metadata and, optionally, enables SCIM.
  5. Use a test user before enforcing SSO for the domain.

API keys and webhook secrets are server-only credentials. Never expose them in NEXT_PUBLIC_* variables or browser bundles.

@regionauth/better-auth

Use the Better Auth plugin when Better Auth owns your sessions and user model. The adapter initiates SAML login, validates the callback, and links the enterprise identity to your existing user.

1. Install and configure

pnpm add @regionauth/better-auth

# .env.local
REGIONAUTH_API_KEY=ra_live_...
REGIONAUTH_WEBHOOK_SECRET=whsec_...

2. Register the plugin

import { betterAuth } from "better-auth";
import { regionAuth } from "@regionauth/better-auth";

export const auth = betterAuth({
  database,
  plugins: [
    regionAuth({
      apiKey: process.env.REGIONAUTH_API_KEY!,
      region: "ap-southeast-1",
    }),
  ],
});

3. Start enterprise sign-in

Send the user to your Better Auth sign-in endpoint with their email or organization slug. The plugin performs home-realm discovery, redirects to the configured IdP, and returns to your existing session flow.

await authClient.signIn.sso({
  email: "sam@customer.example",
  callbackURL: "/dashboard",
});

@regionauth/nextjs

Use the framework adapter when you own authentication directly or need to connect RegionAuth to Supabase or another user store. The catch-all route handles discovery, authorization redirects, and signed callbacks.

1. Install

pnpm add @regionauth/nextjs

# .env.local
REGIONAUTH_API_KEY=ra_live_...
REGIONAUTH_WEBHOOK_SECRET=whsec_...

2. Add the App Router handler

// app/api/regionauth/[...regionauth]/route.ts
import { regionAuthHandler } from "@regionauth/nextjs";

export const { GET, POST } = regionAuthHandler({
  apiKey: process.env.REGIONAUTH_API_KEY!,
  webhookSecret: process.env.REGIONAUTH_WEBHOOK_SECRET!,
  onSignIn: async ({ profile, organization }) => {
    // Resolve or create the user in your own database.
    return { userId: await upsertUser(profile, organization) };
  },
});

3. Configure callback URLs

Add https://your-app.example/api/regionauth/callback in the RegionAuth dashboard. Use HTTPS in production. For local development, add the exact localhost origin you use.

Supabase mapping

In onSignIn, resolve the SAML subject against a server-side mapping table, then use the Supabase Admin client to create or update the user. Do not put a service-role key in client code. Store the RegionAuth organization ID and immutable SAML subject so email changes do not create duplicate users.

SCIM webhook guide

RegionAuth exposes SCIM 2.0 to the customer directory and sends normalized, signed events to your app. Your database remains the source of truth for application access.

Endpoint

// app/api/regionauth/scim/route.ts
import { verifyRegionAuthWebhook } from "@regionauth/nextjs";

export async function POST(request: Request) {
  const payload = await request.text();
  const event = await verifyRegionAuthWebhook({
    payload,
    signature: request.headers.get("regionauth-signature") ?? "",
    secret: process.env.REGIONAUTH_WEBHOOK_SECRET!,
  });

  switch (event.type) {
    case "scim.user.created":
    case "scim.user.updated":
      await upsertUser(event.data.user);
      break;
    case "scim.user.deactivated":
      await deactivateUser(event.data.user.id);
      break;
    case "scim.group.updated":
      await syncGroup(event.data.group);
      break;
  }

  return new Response(null, { status: 204 });
}

Delivery requirements

  • Verify the signature against the raw request body before parsing JSON.
  • Return a 2xx response quickly; process expensive work asynchronously.
  • Deduplicate by event ID. Deliveries are at least once and may arrive more than once.
  • Apply events in order per user and ignore an event older than the user's stored version.
  • Deactivation should revoke active sessions and remove organization access, not erase audit history.

Supported event families

scim.user.created / updated
scim.user.deactivated
scim.group.created / updated
scim.group.deleted

Production checklist

  • Use separate API keys and connections for development, staging, and production.
  • Select the customer's contracted data region before importing directory profiles.
  • Rotate API keys and webhook secrets through your secret manager.
  • Keep a break-glass account outside enforced SSO and test it regularly.
  • Monitor webhook failures and SAML certificate expiry.
  • Document retention, deletion, and data-subject request procedures.

Need regional controls?

Review our isolation and encryption model.

Compliance