Contracts 1.5.0: OIDC client paths, client secret from the link, church.changed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -97,3 +97,20 @@ export const churchSchema = z
|
||||
export type Church = z.infer<typeof churchSchema>;
|
||||
export type Campus = z.infer<typeof campusSchema>;
|
||||
export type ServiceTime = z.infer<typeof serviceTimeSchema>;
|
||||
|
||||
/**
|
||||
* Where the church profile lives (contracts 1.5.0): **Accounts owns it** (docs/ACCOUNTS-1.0-PLAN.md
|
||||
* §7, decision 1) and serves it publicly at `profile`; products read it from there. When it
|
||||
* changes, Accounts sends `church.changed` (signed with the link's secret, `LINK_HEADERS`) to
|
||||
* each linked product at `changed`, which then fetches the profile again.
|
||||
*/
|
||||
export const CHURCH_PATHS = { profile: "/api/church/v1", changed: "/api/church/v1/changed" } as const;
|
||||
|
||||
/** The `church.changed` webhook: a hint to fetch `GET /api/church/v1` again. */
|
||||
export const churchChangedSchema = z.object({
|
||||
schema: z.literal(CHURCH_SCHEMA),
|
||||
type: z.literal("church.changed"),
|
||||
occurredAt: dateTimeSchema,
|
||||
updatedAt: dateTimeSchema,
|
||||
});
|
||||
export type ChurchChanged = z.infer<typeof churchChangedSchema>;
|
||||
|
||||
@@ -9,6 +9,7 @@ export * from "./church";
|
||||
export * from "./identity";
|
||||
export * from "./return-to";
|
||||
export * from "./link";
|
||||
export * from "./oidc";
|
||||
export * as hub from "./hub";
|
||||
export * as agent from "./agent";
|
||||
export * from "./church-export";
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Signing in through Accounts (contracts 1.5.0, docs/ACCOUNTS-1.0-PLAN.md §3–5).
|
||||
*
|
||||
* Every product is registered with its church's Accounts by **Connect** (`crosscode.link/1`): the
|
||||
* product's Hub install id is its `client_id`, its client secret is derived from the link's secret
|
||||
* (`oidcClientSecret` in `@crosscode/contracts/signing`), and its addresses are these fixed paths on
|
||||
* the product's own address, so nothing is typed in and only exact matches are accepted.
|
||||
*/
|
||||
|
||||
/** On the product's address. */
|
||||
export const OIDC_CLIENT_PATHS = {
|
||||
/** `redirect_uri`: the code comes back here, with the `state` the product sent. */
|
||||
callback: "/api/auth/callback",
|
||||
/** `post_logout_redirect_uri`: where signing out ends. */
|
||||
postLogout: "/",
|
||||
/** `backchannel_logout_uri`: Accounts tells the product a session ended (OIDC Back-Channel Logout). */
|
||||
backchannelLogout: "/api/auth/backchannel-logout",
|
||||
} as const;
|
||||
|
||||
/** On Accounts' address. */
|
||||
export const OIDC_PROVIDER_PATHS = {
|
||||
/** The issuer is `<accounts url>/api/oidc`; discovery is at `<issuer>/.well-known/openid-configuration`. */
|
||||
issuer: "/api/oidc",
|
||||
} as const;
|
||||
|
||||
/** Where a product takes Accounts' back-channel calls (`crosscode.identity/1`: user.updated, user.deleted, user.export). */
|
||||
export const ACCOUNTS_CALL_PATH = "/api/accounts/v1/events";
|
||||
|
||||
/** The scopes a product asks for. `crosscode` adds news consent, the 2FA method and the notice version. */
|
||||
export const OIDC_SCOPES = ["openid", "profile", "email", "phone", "crosscode"] as const;
|
||||
|
||||
/** `acr_values` a product sends to require 2FA on this sign-in (e.g. for its staff roles). */
|
||||
export const ACR_MFA = "mfa";
|
||||
|
||||
export interface OidcClientAddresses {
|
||||
redirectUri: string;
|
||||
postLogoutRedirectUri: string;
|
||||
backchannelLogoutUri: string;
|
||||
}
|
||||
|
||||
/** The exact addresses registered for a product at `productUrl` (its address as the Hub lists it). */
|
||||
export function oidcClientAddresses(productUrl: string): OidcClientAddresses {
|
||||
const base = productUrl.replace(/\/+$/, "");
|
||||
return {
|
||||
redirectUri: `${base}${OIDC_CLIENT_PATHS.callback}`,
|
||||
postLogoutRedirectUri: `${base}${OIDC_CLIENT_PATHS.postLogout}`,
|
||||
backchannelLogoutUri: `${base}${OIDC_CLIENT_PATHS.backchannelLogout}`,
|
||||
};
|
||||
}
|
||||
@@ -283,3 +283,12 @@ export function verifyLink(message: Record<string, unknown>, publicKeyPem: strin
|
||||
}
|
||||
return ed25519Verify(raw, jobSigningInput(message), message.signature) ? { ok: true } : { ok: false, code: "BAD_SIGNATURE" };
|
||||
}
|
||||
|
||||
/**
|
||||
* A product's OIDC client secret at its church's Accounts (contracts 1.5.0): derived from the
|
||||
* secret of the product's link with Accounts, so Connect sets up both and there's no second secret
|
||||
* to exchange or store. base64url of HMAC-SHA256(linkSecret, "crosscode.oidc-client/1").
|
||||
*/
|
||||
export function oidcClientSecret(linkSecret: string): string {
|
||||
return b64u(createHmac("sha256", linkSecret).update("crosscode.oidc-client/1").digest());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user