Skip to content
MSO CloudDocumentation

Connect a satellite app to MSO Cloud

On this page

You finish with an application of your own that registers as an OIDC client of the MSO issuer, signs a user in, reads the organization and brand the user launched from, calls one Platform API endpoint with the right scope, and verifies a signed webhook. Plan for about 90 minutes, longer if the platform operator has to add your client entry.

Before you start#

  • A running MSO Cloud stack with the issuer enabled, and its issuer URL (IDP_ISSUER, the platform origin, for example https://msocloud.example). Bring-up is operator work: docs/runbooks/idp-issuer-bringup.md. Local development does not start the issuer.
  • A test organization that has your app enabled in the admin catalog, and a user who is a member of it.
  • Node 26, and in your app jose, openid-client (v6 API) and the platform contract package (source packages/platform-contract, version 0.5.0, published to the GitHub package registry; pin an exact minor). Snippets import it as platform-contract: use the name field of its package.json. The conformance test apps/idp/src/__tests__/conformance.test.ts runs the same flow and is the reference for every call below.
  • Background: Connect a satellite app, Platform API and events.

Steps#

  1. Generate a signing key. The app authenticates with private_key_jwt, ES256 only. Publish the public JWK, keep the private key in your own secret store, never in a repository.

    import { exportJWK, generateKeyPair } from 'jose';
    
    const { privateKey, publicKey } = await generateKeyPair('ES256', { extractable: true });
    const publicJwk = {
      ...(await exportJWK(publicKey)),
      kid: 'my-app-key-1',
      use: 'sig',
      alg: 'ES256',
    };
    const privateJwk = { ...(await exportJWK(privateKey)), kid: 'my-app-key-1', alg: 'ES256' };
    
  2. Give the operator your client entry. The issuer reads a JSON array from IDP_CLIENTS_JSON or IDP_CLIENTS_FILE, validated by staticClientSchema in apps/idp/src/clients.ts. Redirect URIs are exact https literals (loopback http is allowed), at most 8, no wildcard, no fragment. jwks holds 1 to 4 public EC P-256 keys and rejects any d member. scope lists the OIDC scopes plus the platform scopes your app may request.

    [{
      "client_id": "my-app",
      "client_name": "My app",
      "redirect_uris": ["https://my-app.example/auth/callback"],
      "post_logout_redirect_uris": ["https://my-app.example/"],
      "backchannel_logout_uri": "https://my-app.example/auth/backchannel-logout",
      "jwks": { "keys": [ <publicJwk> ] },
      "grant_types": ["authorization_code", "refresh_token", "client_credentials"],
      "scope": "openid offline_access email profile platform:orgs.read platform:entitlements.read platform:events.write"
    }]
    

    The platform scope vocabulary is PLATFORM_SCOPES in packages/platform-contract/src/scopes.ts: platform:orgs.read, platform:entitlements.read, platform:social.read, platform:events.write. Marketplace and marketing data have no scope and no endpoint. For the launcher tile, a maintainer adds a satellite manifest with the same clientId, launchUrl and scopes in packages/plugin-host/src/registry.ts. Nothing checks that manifest and client entry agree; a mismatch surfaces as a refused token.

  3. Sign a user in. Authorization code flow with PKCE (required for every client) and private_key_jwt. Ask for the organization with the RFC 8707 resource parameter, https://msocloud.net/api/platform/orgs/<org_id>. That string is PLATFORM_AUDIENCE plus /orgs/ and is not your issuer URL.

    import * as oc from 'openid-client';
    import { importJWK } from 'jose';
    
    const issuer = new URL(process.env.MSO_ISSUER_URL!);
    const key = await importJWK(JSON.parse(process.env.MSO_CLIENT_PRIVATE_JWK!), 'ES256');
    const config = await oc.discovery(
      issuer,
      'my-app',
      undefined,
      oc.PrivateKeyJwt({ key, kid: 'my-app-key-1' }),
    );
    
    // 1. redirect the browser here; keep verifier, state and nonce in the user's session
    const verifier = oc.randomPKCECodeVerifier();
    const state = oc.randomState();
    const nonce = oc.randomNonce();
    const authUrl = oc.buildAuthorizationUrl(config, {
      redirect_uri: 'https://my-app.example/auth/callback',
      scope: 'openid offline_access email profile',
      resource: `https://msocloud.net/api/platform/orgs/${orgId}`,
      code_challenge: await oc.calculatePKCECodeChallenge(verifier),
      code_challenge_method: 'S256',
      state,
      nonce,
    });
    
    // 2. in the callback route
    const tokens = await oc.authorizationCodeGrant(config, new URL(callbackUrl), {
      pkceCodeVerifier: verifier,
      expectedState: state,
      expectedNonce: nonce,
      idTokenExpected: true,
    });
    

    Parse the verified ID-token claims with the contract schema instead of trusting them: idTokenClaimsSchema.parse(tokens.claims()). The MSO claims are namespaced under https://msocloud.net/claims/ (orgs, active_org, active_brand, super_admin); read them through ID_TOKEN_CLAIM_KEYS. The token carries at most 50 organizations; past that orgs_truncated is true and you call GET /me.

  4. Read the launch hint. When a user opens your tile, MSO Cloud redirects to your launchUrl with mso_org (always) and mso_brand (when a brand is active) as query parameters (apps/web/src/app/api/apps/launch/[app]/route.ts). They are navigation hints for an app that already holds a session and skips sign-in: the app may ignore them and must check access itself, here against the orgs claim.

    const url = new URL(request.url);
    const hintOrg = url.searchParams.get('mso_org');
    const hintBrand = url.searchParams.get('mso_brand');
    const claims = idTokenClaimsSchema.parse(tokens.claims());
    const member = claims[ID_TOKEN_CLAIM_KEYS.orgs].find((o) => o.id === hintOrg);
    if (!member) throw new Error('user is not a member of the launched organization');
    if (hintBrand && member.brand_ids !== null && !member.brand_ids.includes(hintBrand)) {
      throw new Error('brand not granted'); // brand_ids: null means every brand
    }
    
  5. Call a Platform API endpoint. Every route needs one scope and a path organization equal to the token organization. A token is one organization, 600 seconds at most. For an org-level job use client credentials; GET /me and /me/launcher need a user-delegated token instead. This example reads entitlements (platform:entitlements.read).

    import { entitlementsResponseSchema } from 'platform-contract';
    
    const res = await oc.clientCredentialsGrant(config, {
      scope: 'platform:entitlements.read',
      resource: `https://msocloud.net/api/platform/orgs/${orgId}`,
    });
    const r = await fetch(
      `${process.env.MSO_PLATFORM_ORIGIN}/api/platform/v1/orgs/${orgId}/entitlements`,
      {
        headers: { Authorization: `Bearer ${res.access_token}` },
      },
    );
    if (!r.ok) throw new Error(`platform api ${r.status} ${JSON.stringify(await r.json())}`);
    const { entitlements } = entitlementsResponseSchema.parse(await r.json());
    

    The same call in curl, with $TOKEN from the grant:

    curl -fsS -H "Authorization: Bearer $TOKEN" \
      "$MSO_PLATFORM_ORIGIN/api/platform/v1/orgs/$ORG_ID/entitlements"
    

    The body matches entitlementsResponseSchema: org_id and entitlements[] of app_id, plan, limits, valid_to, status (active, trial, suspended, expired). Errors are {error, error_description?}: 401 invalid_token, 403 insufficient_scope or org_mismatch. If PLATFORM_ISSUER or PLATFORM_JWKS_URL is unset on the platform, every route answers 404. To push an event, POST /api/platform/v1/events with scope platform:events.write and a content.published envelope (contentPublishedEventSchema; body at most 64 KiB; a repeated id answers 202 with duplicate: true).

  6. Receive and verify a webhook. MSO Cloud POSTs one envelope (id, type, org_id, occurred_at, data) with X-MSO-Signature: sha256=<hex> (HMAC-SHA256 over the raw body) and X-MSO-Event-Id. Verify before parsing, deduplicate on the event id, return 2xx quickly.

    import {
      platformEventSchema,
      verifyWebhookSignature,
      WEBHOOK_SIGNATURE_HEADER,
      WEBHOOK_EVENT_ID_HEADER,
    } from 'platform-contract';
    
    export async function POST(req: Request): Promise<Response> {
      const raw = await req.text(); // the exact bytes; never re-serialize
      if (
        !verifyWebhookSignature(
          raw,
          req.headers.get(WEBHOOK_SIGNATURE_HEADER),
          process.env.MSO_WEBHOOK_SECRET!,
        )
      ) {
        return new Response(null, { status: 401 });
      }
      const event = platformEventSchema.parse(JSON.parse(raw));
      if (await alreadySeen(req.headers.get(WEBHOOK_EVENT_ID_HEADER) ?? event.id)) {
        return new Response(null, { status: 200 });
      }
      await handle(event); // org.app.changed, membership.changed, user.disabled, trends.updated
      return new Response(null, { status: 200 });
    }
    

    Test the receiver without MSO Cloud by signing a body yourself. The openssl output equals signWebhookBody:

    BODY='{"id":"evt-1","type":"user.disabled","org_id":"'$ORG_ID'","occurred_at":"2026-11-28T10:00:00Z","data":{"user_id":"u-1"}}'
    SIG="sha256=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$MSO_WEBHOOK_SECRET" -hex | sed 's/^.* //')"
    curl -i -X POST https://my-app.example/webhooks/mso \
      -H "Content-Type: application/json" -H "X-MSO-Signature: $SIG" -H "X-MSO-Event-Id: evt-1" --data-raw "$BODY"
    

    Delivery is at-least-once and can arrive out of order: 408, 425, 429 and 5xx retry at 30 s x 2^(n-1) up to 6 h and 10 attempts, any other status is dead-lettered.

What does not exist#

  • No webhook subscription write path. No screen or API creates platform_webhook_subscriptions rows (packages/schema/src/tables/platform-outbox.ts; one row per organization and app: url, encrypted secret, eventTypes). Until a path exists, MSO Cloud sends your app nothing, and wiring a receiver needs a reviewed schema and row-level-security change by the platform team. Supported alternative: reconcile by polling GET /orgs/{id}/members and /entitlements (cursor pagination, limit up to 200), and rely on the ID-token claims at each sign-in, because provisioning is token-first. Step 6 is still how you build and test the receiver.
  • No self-service client registration. Dynamic registration is off; a client change is an operator edit plus an issuer restart.
  • content.published has no consumer in apps/ or packages/; it is stored for lineage only.
  • Logout: disabling a user in MSO Cloud sends an OIDC back-channel logout_token to backchannel_logout_uri. Your endpoint revokes the local session by sid (logoutTokenClaimsSchema).

If it fails#

Symptom Cause
invalid_target at the token endpoint The app is not installed, enabled and entitled for that organization, or the user is not a member, or resource is not https://msocloud.net/api/platform/orgs/<org_id>.
invalid_client The key is not in jwks, kid differs, or the algorithm is not ES256.
Redirect refused redirect_uri is not an exact literal in the client entry.
403 insufficient_scope The grant did not include the route's scope, or the client entry's scope omits it.
403 org_mismatch The path organization differs from the token's org_id.