@idp.global/interfaces 30.4.0 → 30.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 2026-11-13 - 30.6.0
4
+
5
+ ### Features
6
+
7
+ - an upstream flow's finish is bound to the browser that returned from the provider (request; AGL-1801)
8
+ - `IReq_FinishUpstreamSignIn` requires `returnProof`: the one-time value that only the provider callback's
9
+ redirect carries, in the URL fragment (`<login>/login?upstream=<id>#returnProof=<proof>`). The verifier binds
10
+ finish to the browser that started the flow, the return proof to the browser that returned from the provider.
11
+ A finish that lacks the right verifier or the right return proof is refused without a code and leaves the
12
+ flow unchanged.
13
+ - A caller written against 30.5.0 does not compile until it sends `returnProof`. No released server ever
14
+ answered this request.
15
+ - `IReq_ConfirmUpstreamIdentityLink` is unchanged: a flow answers `linkRequired` only to a finish that held
16
+ both values.
17
+
18
+ ## 2026-11-13 - 30.5.0
19
+
20
+ ### Features
21
+
22
+ - the purpose of an upstream flow and the authentication-change gate's refusal data (data, request; AGL-1801)
23
+ - `upstreamSignInPurposes` (`sign-in`, `link`) and `TUpstreamSignInPurpose`. `IReq_StartUpstreamSignIn` takes
24
+ `TStartUpstreamSignInRequest`: a start without `purpose` is a sign-in, and a link start that carries
25
+ `oidcTransactionId` does not compile. Callers written against 30.4.0 compile unchanged.
26
+ - The link flow replaces the account-page link path 30.4.0 described (start, provider round trip, confirm without
27
+ finish); a confirm on a flow that was not finished now fails. The account page sends the person to
28
+ `<login>/login?link=<provider>`, the provider returns to `<login>/login?upstream=<id>`, and
29
+ `finishUpstreamSignIn` on a link flow never mints a session, never creates an account and looks up no account
30
+ and no link. `confirmUpstreamIdentityLink` accepts only a flow whose finish answered `linkRequired`, after a
31
+ new sign-in and an explicit confirmation; a refused confirm leaves the flow open.
32
+ - The provider's email is always vouched for: `linkRequired` and every link carry an email the provider's signed
33
+ token marks as verified. Both flows refuse `provider_email_unverified` otherwise; a finish refused with a code
34
+ ends the flow, and only a wrong verifier leaves it usable.
35
+ - `authenticationChangeRefusalCodes` (`fresh_passkey_sign_in_required`, `fresh_sign_in_required`),
36
+ `TAuthenticationChangeRefusalCode` and `IAuthenticationChangeRefusal`: the `errorData` of a request the
37
+ authentication-change gate refuses when a new sign-in would satisfy it.
38
+
3
39
  ## 2026-11-13 - 30.4.0
4
40
 
5
41
  ### Features
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@idp.global/interfaces',
6
- version: '30.4.0',
6
+ version: '30.6.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the idp.global ecosystem.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLHVGQUF1RjtDQUNyRyxDQUFBIn0=
@@ -8,6 +8,22 @@ export interface ILoginSessionAuthenticationEvidence {
8
8
  mfaFactor: TLoginSessionMfaFactor | null;
9
9
  mfaAuthenticatedAt: number | null;
10
10
  }
11
+ /**
12
+ * Why the authentication-change gate refused a request. The gate guards every change to how
13
+ * an account signs in and judges the session's authentication evidence. Wherever a new sign-in
14
+ * would satisfy it, a refused request throws a `TypedResponseError` whose `errorData` is
15
+ * `IAuthenticationChangeRefusal`; a refusal that no new sign-in can satisfy carries no code.
16
+ * The proof is always a new sign-in on the login origin: there is no in-session step-up
17
+ * request. The list is closed.
18
+ * - `fresh_passkey_sign_in_required`: sign in again with a passkey, then retry;
19
+ * - `fresh_sign_in_required`: sign in again, then retry.
20
+ */
21
+ export declare const authenticationChangeRefusalCodes: readonly ['fresh_passkey_sign_in_required', 'fresh_sign_in_required'];
22
+ export type TAuthenticationChangeRefusalCode = (typeof authenticationChangeRefusalCodes)[number];
23
+ /** The `errorData` of a request the authentication-change gate refused. */
24
+ export interface IAuthenticationChangeRefusal {
25
+ code: TAuthenticationChangeRefusalCode;
26
+ }
11
27
  export interface ILoginSession {
12
28
  id: string;
13
29
  data: {
@@ -7,4 +7,18 @@ export const loginSessionPrimaryAuthenticationMethods = [
7
7
  'saml',
8
8
  ...upstreamIdentityProviders,
9
9
  ];
10
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9naW5zZXNzaW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vdHMvZGF0YS9sb2dpbnNlc3Npb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFbEUscUZBQXFGO0FBQ3JGLE1BQU0sQ0FBQyxNQUFNLHdDQUF3QyxHQUFHO0lBQ3RELFlBQVk7SUFDWixTQUFTO0lBQ1QsVUFBVTtJQUNWLE1BQU07SUFDTixHQUFHLHlCQUF5QjtDQUNwQixDQUFDIn0=
10
+ /**
11
+ * Why the authentication-change gate refused a request. The gate guards every change to how
12
+ * an account signs in and judges the session's authentication evidence. Wherever a new sign-in
13
+ * would satisfy it, a refused request throws a `TypedResponseError` whose `errorData` is
14
+ * `IAuthenticationChangeRefusal`; a refusal that no new sign-in can satisfy carries no code.
15
+ * The proof is always a new sign-in on the login origin: there is no in-session step-up
16
+ * request. The list is closed.
17
+ * - `fresh_passkey_sign_in_required`: sign in again with a passkey, then retry;
18
+ * - `fresh_sign_in_required`: sign in again, then retry.
19
+ */
20
+ export const authenticationChangeRefusalCodes = [
21
+ 'fresh_passkey_sign_in_required',
22
+ 'fresh_sign_in_required',
23
+ ];
24
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9naW5zZXNzaW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vdHMvZGF0YS9sb2dpbnNlc3Npb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFbEUscUZBQXFGO0FBQ3JGLE1BQU0sQ0FBQyxNQUFNLHdDQUF3QyxHQUFHO0lBQ3RELFlBQVk7SUFDWixTQUFTO0lBQ1QsVUFBVTtJQUNWLE1BQU07SUFDTixHQUFHLHlCQUF5QjtDQUNwQixDQUFDO0FBY1g7Ozs7Ozs7OztHQVNHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sZ0NBQWdDLEdBQUc7SUFDOUMsZ0NBQWdDO0lBQ2hDLHdCQUF3QjtDQUNoQixDQUFDIn0=
@@ -5,15 +5,31 @@
5
5
  */
6
6
  export declare const upstreamIdentityProviders: readonly ['apple', 'google'];
7
7
  export type TUpstreamIdentityProvider = (typeof upstreamIdentityProviders)[number];
8
+ /**
9
+ * What an upstream flow is for. The server records it on the flow at start and never changes
10
+ * it, so a sign-in flow that answered `linkRequired` stays a sign-in flow. The list is closed.
11
+ * - `sign-in`: sign in to idp.global, or create an account, with the provider identity;
12
+ * - `link`: link the provider identity to an existing account. A link flow never mints a
13
+ * session and never creates an account.
14
+ */
15
+ export declare const upstreamSignInPurposes: readonly ['sign-in', 'link'];
16
+ export type TUpstreamSignInPurpose = (typeof upstreamSignInPurposes)[number];
8
17
  /**
9
18
  * Why an upstream sign-in, link or unlink was refused. A refused request throws a
10
- * `TypedResponseError` whose `errorData` is `IUpstreamIdentityRefusal`; any other failure
11
- * (an expired or spent flow, a wrong verifier, an unavailable provider) carries no code.
12
- * - `sso_domain_required`: the email is under a verified SSO domain; sign in through its
13
- * organization's single sign-on;
14
- * - `provider_email_unverified`: the provider did not vouch for the email of an identity that
15
- * is not linked yet. It is answered before any account lookup, so it never tells whether an
16
- * account has that email; nothing is created or linked;
19
+ * `TypedResponseError` whose `errorData` is `IUpstreamIdentityRefusal`. The authentication-change
20
+ * gate refuses with its own `IAuthenticationChangeRefusal`, whose codes differ from these; any
21
+ * other failure (an expired or spent flow, a wrong verifier or return proof, an unavailable
22
+ * provider) carries no code.
23
+ * - `sso_domain_required`: the email of the account concerned is under a verified SSO domain;
24
+ * sign in through its organization's single sign-on. At finish on a sign-in flow that is the
25
+ * vouched email of an identity not linked yet, or the account's email for a linked identity;
26
+ * at `confirmUpstreamIdentityLink` it is the signed-in account's email. The provider's email
27
+ * on a link flow is not judged;
28
+ * - `provider_email_unverified`: the provider did not vouch for an email: the signed token
29
+ * carries none, or does not say it is verified. A sign-in flow answers it for an identity
30
+ * that is not linked yet, before any account lookup; a link flow answers it for every
31
+ * identity, before any lookup. It never tells whether an account or a link exists; nothing
32
+ * is created or linked, and the flow is ended;
17
33
  * - `upstream_identity_linked_elsewhere`: this provider identity is linked to another account;
18
34
  * - `provider_already_linked`: the account already has a link to this provider;
19
35
  * - `last_sign_in_method`: after the unlink the account would have no password, no active
@@ -4,4 +4,12 @@
4
4
  * challenge, the email verification method and the activity vocabulary derive from it.
5
5
  */
6
6
  export const upstreamIdentityProviders = ['apple', 'google'];
7
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBzdHJlYW1pZGVudGl0eS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzL2RhdGEvdXBzdHJlYW1pZGVudGl0eS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7OztHQUlHO0FBQ0gsTUFBTSxDQUFDLE1BQU0seUJBQXlCLEdBQUcsQ0FBQyxPQUFPLEVBQUUsUUFBUSxDQUFVLENBQUMifQ==
7
+ /**
8
+ * What an upstream flow is for. The server records it on the flow at start and never changes
9
+ * it, so a sign-in flow that answered `linkRequired` stays a sign-in flow. The list is closed.
10
+ * - `sign-in`: sign in to idp.global, or create an account, with the provider identity;
11
+ * - `link`: link the provider identity to an existing account. A link flow never mints a
12
+ * session and never creates an account.
13
+ */
14
+ export const upstreamSignInPurposes = ['sign-in', 'link'];
15
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBzdHJlYW1pZGVudGl0eS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzL2RhdGEvdXBzdHJlYW1pZGVudGl0eS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7OztHQUlHO0FBQ0gsTUFBTSxDQUFDLE1BQU0seUJBQXlCLEdBQUcsQ0FBQyxPQUFPLEVBQUUsUUFBUSxDQUFVLENBQUM7QUFJdEU7Ozs7OztHQU1HO0FBQ0gsTUFBTSxDQUFDLE1BQU0sc0JBQXNCLEdBQUcsQ0FBQyxTQUFTLEVBQUUsTUFBTSxDQUFVLENBQUMifQ==
@@ -8,7 +8,7 @@ export interface IUpstreamIdentityDto {
8
8
  provider: TUpstreamIdentityProvider;
9
9
  /** epoch ms when the link was made */
10
10
  linkedAt: number;
11
- /** The email the provider asserted when the link was made; later provider emails never replace it. */
11
+ /** The email the provider vouched for when the link was made; later provider emails never replace it. */
12
12
  email: string;
13
13
  /** The provider signed that `email` is a private relay address (Apple's `is_private_email`). */
14
14
  isPrivateEmail: boolean;
@@ -3,24 +3,41 @@ import * as data from '../data/index.js';
3
3
  import * as dto from '../dto/index.js';
4
4
  import type { IReq_LoginWithEmailOrUsernameAndPassword } from './login.js';
5
5
  /**
6
- * Public: starts a sign-in with an upstream provider. The browser keeps a random verifier
7
- * (in sessionStorage) and sends only its S256 hash here. The server records the flow for
8
- * ten minutes; `id` names that record and is the OAuth `state` inside `authorizationUrl`.
9
- * The provider returns to the issuer's callback, which redirects the browser to
10
- * `<login>/login?upstream=<id>` (plus `&tx=<oidcTransactionId>` when one was given).
6
+ * The fields of `startUpstreamSignIn`. `purpose` defaults to `sign-in`; only a sign-in flow
7
+ * may carry an OIDC authorization transaction.
8
+ */
9
+ export type TStartUpstreamSignInRequest = {
10
+ provider: data.TUpstreamIdentityProvider;
11
+ /** base64url(SHA-256(verifier)) of the verifier the login page keeps */
12
+ verifierChallenge: string;
13
+ } & ({
14
+ purpose?: Extract<data.TUpstreamSignInPurpose, 'sign-in'>;
15
+ /**
16
+ * Optional opaque OIDC authorization transaction to resume through the existing
17
+ * prepare/complete requests once the sign-in is complete.
18
+ */
19
+ oidcTransactionId?: string;
20
+ } | {
21
+ purpose: Extract<data.TUpstreamSignInPurpose, 'link'>;
22
+ oidcTransactionId?: never;
23
+ });
24
+ /**
25
+ * Public: starts an upstream flow; no session is needed. The login page makes a random
26
+ * verifier, sends only its S256 hash here and keeps the verifier in the login origin's
27
+ * sessionStorage under the answered `id`. The server records the flow and its purpose for ten
28
+ * minutes; the purpose never changes. `id` names that record and is the OAuth `state` inside
29
+ * `authorizationUrl`. The provider returns to the issuer's callback, which always redirects the
30
+ * browser to `<login>/login?upstream=<id>` (plus `&tx=<oidcTransactionId>` when one was given).
31
+ * When the callback accepted the provider's answer, that redirect also carries a one-time return
32
+ * proof in its fragment: `<login>/login?upstream=<id>#returnProof=<proof>`.
33
+ *
34
+ * A sign-in flow starts on the login page, optionally with an OIDC authorization transaction.
35
+ * A link flow starts when the account UI's "Link" navigates to `<login>/login?link=<provider>`;
36
+ * that page starts it with `purpose: 'link'` and goes to the provider.
11
37
  */
12
38
  export interface IReq_StartUpstreamSignIn extends plugins.typedRequestInterfaces.implementsTR<plugins.typedRequestInterfaces.ITypedRequest, IReq_StartUpstreamSignIn> {
13
39
  method: 'startUpstreamSignIn';
14
- request: {
15
- provider: data.TUpstreamIdentityProvider;
16
- /** base64url(SHA-256(verifier)) of the verifier the browser keeps */
17
- verifierChallenge: string;
18
- /**
19
- * Optional opaque OIDC authorization transaction to resume through the existing
20
- * prepare/complete requests once the sign-in is complete.
21
- */
22
- oidcTransactionId?: string;
23
- };
40
+ request: TStartUpstreamSignInRequest;
24
41
  response: {
25
42
  id: string;
26
43
  /** The provider's authorization URL; the browser navigates to it. */
@@ -28,24 +45,41 @@ export interface IReq_StartUpstreamSignIn extends plugins.typedRequestInterfaces
28
45
  };
29
46
  }
30
47
  /**
31
- * The provider identity is not linked, and the email the provider vouched for names an
32
- * existing account. Never answered for an email the provider did not vouch for.
48
+ * The returned provider identity can be linked to an existing account. `finishUpstreamSignIn`
49
+ * answers it in two situations:
50
+ * - on a sign-in flow, when the provider identity is not linked and the email the provider
51
+ * vouched for names an existing account. A sign-in flow never answers it for an email the
52
+ * provider did not vouch for;
53
+ * - on a link flow, for every identity whose email the provider vouched for, without any
54
+ * account or link lookup.
55
+ *
56
+ * It mints nothing. The flow stays open until its ten-minute expiry for
57
+ * `confirmUpstreamIdentityLink`.
33
58
  */
34
59
  export interface IUpstreamSignInLinkRequired {
35
60
  provider: data.TUpstreamIdentityProvider;
36
- /** The email the provider asserted. */
61
+ /** The email the provider vouched for; the confirmation screen names it. */
37
62
  email: string;
38
63
  }
39
64
  /**
40
- * Public: finishes an upstream sign-in after the provider returned. It can be called once
41
- * per flow and answers like password sign-in: a refresh token, or an MFA challenge to answer
42
- * through `verifyMfaChallenge` or the passkey MFA requests. Either answer ends the flow.
43
- * `linkRequired` is the third outcome: it mints nothing and leaves the flow open until its
44
- * ten-minute expiry for exactly one `confirmUpstreamIdentityLink`, which the person sends
45
- * with the same `id` and `verifier` after signing in to that account normally in the same
46
- * browser.
47
- * Refusal codes (`data.IUpstreamIdentityRefusal`): `sso_domain_required`,
48
- * `provider_email_unverified`.
65
+ * Public: finishes an upstream flow after the provider returned. The page at
66
+ * `<login>/login?upstream=<id>` calls it when it holds both a verifier for that `id` and the
67
+ * return proof from its URL fragment, and calls nothing otherwise; it never needs to know the
68
+ * flow's purpose. The verifier binds finish to the browser that started the flow, the return
69
+ * proof to the browser that returned from the provider. It answers once per flow. A finish that
70
+ * lacks the right verifier or the right return proof is refused without a code and leaves the
71
+ * flow unchanged.
72
+ *
73
+ * On a sign-in flow it answers like password sign-in: a refresh token, or an MFA challenge to
74
+ * answer through `verifyMfaChallenge` or the passkey MFA requests. Either answer ends the flow.
75
+ * `linkRequired` is the third outcome. Refusal codes (`data.IUpstreamIdentityRefusal`), in
76
+ * this order: `provider_email_unverified`, then `sso_domain_required`. A refusal with a code
77
+ * ends the flow.
78
+ *
79
+ * On a link flow it never mints a session, never creates an account and looks up no account
80
+ * and no link: it answers `linkRequired` when the provider vouched for the email, whatever
81
+ * identity the provider returned. Refusal code: `provider_email_unverified`. A refusal with a
82
+ * code ends the flow.
49
83
  */
50
84
  export interface IReq_FinishUpstreamSignIn extends plugins.typedRequestInterfaces.implementsTR<plugins.typedRequestInterfaces.ITypedRequest, IReq_FinishUpstreamSignIn> {
51
85
  method: 'finishUpstreamSignIn';
@@ -53,21 +87,38 @@ export interface IReq_FinishUpstreamSignIn extends plugins.typedRequestInterface
53
87
  id: string;
54
88
  /** The verifier whose hash `startUpstreamSignIn` received. */
55
89
  verifier: string;
90
+ /**
91
+ * The one-time return proof that only the provider callback's redirect carries, in the URL
92
+ * fragment (`#returnProof=<proof>`). It binds finish to the browser that returned from the
93
+ * provider, as the verifier binds it to the browser that started the flow.
94
+ */
95
+ returnProof: string;
56
96
  };
57
97
  response: IReq_LoginWithEmailOrUsernameAndPassword['response'] & {
58
98
  linkRequired?: IUpstreamSignInLinkRequired;
59
99
  };
60
100
  }
61
101
  /**
62
- * Links the returned provider identity to the signed-in account. An authentication change:
63
- * it needs the account's strongest enrolled proof, fresh (a passkey step-up while the
64
- * account has an active passkey, otherwise a fresh primary sign-in).
102
+ * Links the provider identity of a flow whose `finishUpstreamSignIn` answered `linkRequired`;
103
+ * any other flow fails without a code. The link stores the provider's vouched email and
104
+ * private-relay flag as the flow recorded them. It links to the signed-in account and carries
105
+ * the flow's `id` and `verifier`; no return proof is needed, because a flow answers
106
+ * `linkRequired` only to a finish that held both the verifier and the return proof. One
107
+ * confirmation screen on the login origin serves sign-in and link flows alike. It always asks
108
+ * for a new sign-in to the account, whatever session the browser holds, then names the
109
+ * provider, the provider's email and the signed-in account; only the person's explicit
110
+ * confirmation sends this request, never a URL on its own.
111
+ *
112
+ * An authentication change: it needs the account's strongest enrolled proof, fresh (a fresh
113
+ * passkey sign-in while the account has an active passkey, otherwise a fresh primary sign-in);
114
+ * an administrator-recovery session does not count. The gate is checked at entry and again
115
+ * when the link is written, and can refuse with `data.IAuthenticationChangeRefusal`.
65
116
  *
66
- * The same requests link from the account UI: `startUpstreamSignIn` without
67
- * `oidcTransactionId`, the provider round trip, then this request with the returned `id`
68
- * and `verifier`, without `finishUpstreamSignIn`.
69
- * Refusal codes: `sso_domain_required`, `upstream_identity_linked_elsewhere`,
70
- * `provider_already_linked`.
117
+ * A refused confirm, the gate's refusal included, leaves the flow open until its ten-minute
118
+ * expiry; only the link write spends it.
119
+ * Refusal codes (`data.IUpstreamIdentityRefusal`): `sso_domain_required` (the signed-in
120
+ * account's email), `provider_already_linked`, `upstream_identity_linked_elsewhere`. Never
121
+ * `provider_email_unverified`: no flow reaches this request without a vouched email.
71
122
  */
72
123
  export interface IReq_ConfirmUpstreamIdentityLink extends plugins.typedRequestInterfaces.implementsTR<plugins.typedRequestInterfaces.ITypedRequest, IReq_ConfirmUpstreamIdentityLink> {
73
124
  method: 'confirmUpstreamIdentityLink';
@@ -94,7 +145,8 @@ export interface IReq_GetUpstreamIdentities extends plugins.typedRequestInterfac
94
145
  }
95
146
  /**
96
147
  * Removes the signed-in account's link to a provider. An authentication change, gated like
97
- * `confirmUpstreamIdentityLink`. Refusal code: `last_sign_in_method`.
148
+ * `confirmUpstreamIdentityLink`; the gate can refuse with `data.IAuthenticationChangeRefusal`.
149
+ * Refusal code (`data.IUpstreamIdentityRefusal`): `last_sign_in_method`.
98
150
  */
99
151
  export interface IReq_UnlinkUpstreamIdentity extends plugins.typedRequestInterfaces.implementsTR<plugins.typedRequestInterfaces.ITypedRequest, IReq_UnlinkUpstreamIdentity> {
100
152
  method: 'unlinkUpstreamIdentity';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idp.global/interfaces",
3
- "version": "30.4.0",
3
+ "version": "30.6.0",
4
4
  "private": false,
5
5
  "description": "Shared TypeScript interfaces and TypedRequest contracts for the idp.global ecosystem.",
6
6
  "exports": {
package/readme.md CHANGED
@@ -213,29 +213,69 @@ itself. The hint never skips a step of the sign-in, and a value that names no
213
213
  offered provider is ignored.
214
214
 
215
215
  Upstream sign-in (Apple, Google) binds the redirect flow to the browser that
216
- started it. `IReq_StartUpstreamSignIn` takes the provider, the S256 hash of a
217
- verifier the browser keeps, and optionally the opaque OIDC transaction; it
218
- returns the flow `id` (the OAuth `state`) and the provider's authorization URL.
219
- After the provider's callback, `IReq_FinishUpstreamSignIn` sends `{ id, verifier }`
220
- once per flow and answers like password sign-in (a refresh token or an MFA
221
- challenge, which end the flow), or with `linkRequired` (provider and asserted
222
- email) when the email the provider vouched for names an existing account that
223
- is not linked yet. `linkRequired` mints nothing and leaves the flow open until
224
- its ten-minute expiry for exactly one `IReq_ConfirmUpstreamIdentityLink`, which
225
- the person sends with the same `id` and verifier after signing in to that
226
- account normally in the same browser. An identity that is not linked and whose
227
- email the provider did not vouch for is refused with
228
- `provider_email_unverified` before any account lookup. A signed-in person links from the account UI with
229
- the same requests: start, the provider round trip, then confirm, without
230
- finish. `IReq_GetUpstreamIdentities` lists the account's links as
216
+ started it and to the browser that returned from the provider, and everything
217
+ runs on the login origin. `IReq_StartUpstreamSignIn`
218
+ takes the provider, the S256 hash of a verifier the login page keeps in its
219
+ sessionStorage, and a `purpose` (`data.upstreamSignInPurposes`: `sign-in`, the
220
+ default, or `link`); only a sign-in flow may carry the opaque OIDC transaction,
221
+ and `link` with `oidcTransactionId` does not compile
222
+ (`request.TStartUpstreamSignInRequest`). It needs no session and returns the
223
+ flow `id` (the OAuth `state`) and the provider's authorization URL. The server
224
+ records the purpose on the flow and never changes it, so a sign-in flow that
225
+ answered `linkRequired` stays a sign-in flow. The account UI's "Link"
226
+ navigates to `<login>/login?link=<provider>`, which starts a link flow. The
227
+ provider's callback always returns to `<login>/login?upstream=<id>` (plus `tx`
228
+ when one was given); when it accepted the provider's answer, that redirect also
229
+ carries a one-time return proof in its fragment
230
+ (`<login>/login?upstream=<id>#returnProof=<proof>`). That page sends
231
+ `IReq_FinishUpstreamSignIn` with `{ id, verifier, returnProof }` once when it
232
+ holds both a verifier for the id and the return proof, and nothing otherwise.
233
+ The verifier binds finish to the browser that started the flow, the return
234
+ proof to the browser that returned from the provider. On a sign-in flow finish
235
+ answers like password sign-in (a refresh token or an MFA challenge, which end
236
+ the flow), or with `linkRequired`
237
+ (provider and vouched email) when the email the provider vouched for names an
238
+ existing account that is not linked yet. On a link flow it never mints a
239
+ session, never creates an account and looks up no account and no link: it
240
+ answers `linkRequired` when the provider vouched for the email, whatever
241
+ identity the provider returned. The provider vouched for an email when its
242
+ signed token carries one and says it is verified; otherwise finish refuses with
243
+ `provider_email_unverified`, on a sign-in flow for an identity that is not
244
+ linked yet, before any account lookup, and on a link flow for every identity,
245
+ before any lookup. On a sign-in flow `sso_domain_required` follows; it judges
246
+ the vouched email of an identity not linked yet, or the account's email for a
247
+ linked identity. A finish refused with a code ends the flow; a finish that
248
+ lacks the right verifier or the right return proof is refused without a code
249
+ and leaves the flow unchanged. `linkRequired` mints nothing and leaves the flow
250
+ open until its ten-minute expiry for `IReq_ConfirmUpstreamIdentityLink` with
251
+ the same `id` and verifier, which the person sends after a new sign-in to the
252
+ account on the login origin and an explicit confirmation; confirm needs no
253
+ return proof, because a flow answers `linkRequired` only to a finish that held
254
+ both the verifier and the return proof. Confirm accepts only
255
+ a flow whose finish answered `linkRequired` (any other flow fails without a
256
+ code) and stores the provider's vouched email and private-relay flag as the
257
+ flow recorded them. It refuses with `sso_domain_required` (judging the
258
+ signed-in account's email), `provider_already_linked` or
259
+ `upstream_identity_linked_elsewhere`, never with `provider_email_unverified`;
260
+ the provider's email on a link flow is never judged for SSO. A refused confirm
261
+ leaves the flow open, and only the link write spends it.
262
+ `IReq_GetUpstreamIdentities` lists the account's links as
231
263
  `dto.IUpstreamIdentityDto` (provider, link time, the email at link time, and the
232
264
  private-relay flag; never the provider subject or a provider token), and
233
- `IReq_UnlinkUpstreamIdentity` removes the link to one provider. Confirming and
234
- unlinking are authentication changes. A refused request throws a
235
- `TypedResponseError` whose `errorData` is `data.IUpstreamIdentityRefusal`, a
236
- closed `code`: `sso_domain_required`, `provider_email_unverified`,
237
- `upstream_identity_linked_elsewhere`, `provider_already_linked` or
238
- `last_sign_in_method`.
265
+ `IReq_UnlinkUpstreamIdentity` removes the link to one provider. A refused
266
+ request throws a `TypedResponseError` whose `errorData` is
267
+ `data.IUpstreamIdentityRefusal`, a closed `code`: `sso_domain_required`,
268
+ `provider_email_unverified`, `upstream_identity_linked_elsewhere`,
269
+ `provider_already_linked` or `last_sign_in_method`.
270
+
271
+ Confirming and unlinking are authentication changes. The authentication-change
272
+ gate, which guards every change to how an account signs in, refuses with
273
+ `errorData` `data.IAuthenticationChangeRefusal` (`code`
274
+ `fresh_passkey_sign_in_required` or `fresh_sign_in_required`,
275
+ `data.authenticationChangeRefusalCodes`) wherever a new sign-in would satisfy
276
+ it; a refusal that no new sign-in can satisfy carries no code. The proof is
277
+ always a new sign-in on the login origin; there is no in-session step-up
278
+ request.
239
279
 
240
280
  OIDC app contracts expose only client configuration and safe credential
241
281
  metadata. Client-secret hashes, signing private keys, and persistence records
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@idp.global/interfaces',
6
- version: '30.4.0',
6
+ version: '30.6.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the idp.global ecosystem.'
8
8
  }
@@ -21,6 +21,28 @@ export interface ILoginSessionAuthenticationEvidence {
21
21
  mfaAuthenticatedAt: number | null;
22
22
  }
23
23
 
24
+ /**
25
+ * Why the authentication-change gate refused a request. The gate guards every change to how
26
+ * an account signs in and judges the session's authentication evidence. Wherever a new sign-in
27
+ * would satisfy it, a refused request throws a `TypedResponseError` whose `errorData` is
28
+ * `IAuthenticationChangeRefusal`; a refusal that no new sign-in can satisfy carries no code.
29
+ * The proof is always a new sign-in on the login origin: there is no in-session step-up
30
+ * request. The list is closed.
31
+ * - `fresh_passkey_sign_in_required`: sign in again with a passkey, then retry;
32
+ * - `fresh_sign_in_required`: sign in again, then retry.
33
+ */
34
+ export const authenticationChangeRefusalCodes = [
35
+ 'fresh_passkey_sign_in_required',
36
+ 'fresh_sign_in_required',
37
+ ] as const;
38
+
39
+ export type TAuthenticationChangeRefusalCode = (typeof authenticationChangeRefusalCodes)[number];
40
+
41
+ /** The `errorData` of a request the authentication-change gate refused. */
42
+ export interface IAuthenticationChangeRefusal {
43
+ code: TAuthenticationChangeRefusalCode;
44
+ }
45
+
24
46
  export interface ILoginSession {
25
47
  id: string;
26
48
  data: {
@@ -7,15 +7,33 @@ export const upstreamIdentityProviders = ['apple', 'google'] as const;
7
7
 
8
8
  export type TUpstreamIdentityProvider = (typeof upstreamIdentityProviders)[number];
9
9
 
10
+ /**
11
+ * What an upstream flow is for. The server records it on the flow at start and never changes
12
+ * it, so a sign-in flow that answered `linkRequired` stays a sign-in flow. The list is closed.
13
+ * - `sign-in`: sign in to idp.global, or create an account, with the provider identity;
14
+ * - `link`: link the provider identity to an existing account. A link flow never mints a
15
+ * session and never creates an account.
16
+ */
17
+ export const upstreamSignInPurposes = ['sign-in', 'link'] as const;
18
+
19
+ export type TUpstreamSignInPurpose = (typeof upstreamSignInPurposes)[number];
20
+
10
21
  /**
11
22
  * Why an upstream sign-in, link or unlink was refused. A refused request throws a
12
- * `TypedResponseError` whose `errorData` is `IUpstreamIdentityRefusal`; any other failure
13
- * (an expired or spent flow, a wrong verifier, an unavailable provider) carries no code.
14
- * - `sso_domain_required`: the email is under a verified SSO domain; sign in through its
15
- * organization's single sign-on;
16
- * - `provider_email_unverified`: the provider did not vouch for the email of an identity that
17
- * is not linked yet. It is answered before any account lookup, so it never tells whether an
18
- * account has that email; nothing is created or linked;
23
+ * `TypedResponseError` whose `errorData` is `IUpstreamIdentityRefusal`. The authentication-change
24
+ * gate refuses with its own `IAuthenticationChangeRefusal`, whose codes differ from these; any
25
+ * other failure (an expired or spent flow, a wrong verifier or return proof, an unavailable
26
+ * provider) carries no code.
27
+ * - `sso_domain_required`: the email of the account concerned is under a verified SSO domain;
28
+ * sign in through its organization's single sign-on. At finish on a sign-in flow that is the
29
+ * vouched email of an identity not linked yet, or the account's email for a linked identity;
30
+ * at `confirmUpstreamIdentityLink` it is the signed-in account's email. The provider's email
31
+ * on a link flow is not judged;
32
+ * - `provider_email_unverified`: the provider did not vouch for an email: the signed token
33
+ * carries none, or does not say it is verified. A sign-in flow answers it for an identity
34
+ * that is not linked yet, before any account lookup; a link flow answers it for every
35
+ * identity, before any lookup. It never tells whether an account or a link exists; nothing
36
+ * is created or linked, and the flow is ended;
19
37
  * - `upstream_identity_linked_elsewhere`: this provider identity is linked to another account;
20
38
  * - `provider_already_linked`: the account already has a link to this provider;
21
39
  * - `last_sign_in_method`: after the unlink the account would have no password, no active
@@ -9,7 +9,7 @@ export interface IUpstreamIdentityDto {
9
9
  provider: TUpstreamIdentityProvider;
10
10
  /** epoch ms when the link was made */
11
11
  linkedAt: number;
12
- /** The email the provider asserted when the link was made; later provider emails never replace it. */
12
+ /** The email the provider vouched for when the link was made; later provider emails never replace it. */
13
13
  email: string;
14
14
  /** The provider signed that `email` is a private relay address (Apple's `is_private_email`). */
15
15
  isPrivateEmail: boolean;
package/ts/readme.md CHANGED
@@ -57,7 +57,8 @@ The `data` export includes types for:
57
57
  - abuse windows
58
58
  - OIDC data structures
59
59
  - invitations
60
- - upstream identity providers (Apple, Google) and their refusal codes
60
+ - upstream identity providers (Apple, Google), flow purposes and refusal codes
61
+ - the authentication-change gate's refusal codes
61
62
 
62
63
  ### `request`
63
64
 
@@ -4,11 +4,41 @@ import * as dto from '../dto/index.js';
4
4
  import type { IReq_LoginWithEmailOrUsernameAndPassword } from './login.js';
5
5
 
6
6
  /**
7
- * Public: starts a sign-in with an upstream provider. The browser keeps a random verifier
8
- * (in sessionStorage) and sends only its S256 hash here. The server records the flow for
9
- * ten minutes; `id` names that record and is the OAuth `state` inside `authorizationUrl`.
10
- * The provider returns to the issuer's callback, which redirects the browser to
11
- * `<login>/login?upstream=<id>` (plus `&tx=<oidcTransactionId>` when one was given).
7
+ * The fields of `startUpstreamSignIn`. `purpose` defaults to `sign-in`; only a sign-in flow
8
+ * may carry an OIDC authorization transaction.
9
+ */
10
+ export type TStartUpstreamSignInRequest = {
11
+ provider: data.TUpstreamIdentityProvider;
12
+ /** base64url(SHA-256(verifier)) of the verifier the login page keeps */
13
+ verifierChallenge: string;
14
+ } & (
15
+ | {
16
+ purpose?: Extract<data.TUpstreamSignInPurpose, 'sign-in'>;
17
+ /**
18
+ * Optional opaque OIDC authorization transaction to resume through the existing
19
+ * prepare/complete requests once the sign-in is complete.
20
+ */
21
+ oidcTransactionId?: string;
22
+ }
23
+ | {
24
+ purpose: Extract<data.TUpstreamSignInPurpose, 'link'>;
25
+ oidcTransactionId?: never;
26
+ }
27
+ );
28
+
29
+ /**
30
+ * Public: starts an upstream flow; no session is needed. The login page makes a random
31
+ * verifier, sends only its S256 hash here and keeps the verifier in the login origin's
32
+ * sessionStorage under the answered `id`. The server records the flow and its purpose for ten
33
+ * minutes; the purpose never changes. `id` names that record and is the OAuth `state` inside
34
+ * `authorizationUrl`. The provider returns to the issuer's callback, which always redirects the
35
+ * browser to `<login>/login?upstream=<id>` (plus `&tx=<oidcTransactionId>` when one was given).
36
+ * When the callback accepted the provider's answer, that redirect also carries a one-time return
37
+ * proof in its fragment: `<login>/login?upstream=<id>#returnProof=<proof>`.
38
+ *
39
+ * A sign-in flow starts on the login page, optionally with an OIDC authorization transaction.
40
+ * A link flow starts when the account UI's "Link" navigates to `<login>/login?link=<provider>`;
41
+ * that page starts it with `purpose: 'link'` and goes to the provider.
12
42
  */
13
43
  export interface IReq_StartUpstreamSignIn
14
44
  extends plugins.typedRequestInterfaces.implementsTR<
@@ -16,16 +46,7 @@ export interface IReq_StartUpstreamSignIn
16
46
  IReq_StartUpstreamSignIn
17
47
  > {
18
48
  method: 'startUpstreamSignIn';
19
- request: {
20
- provider: data.TUpstreamIdentityProvider;
21
- /** base64url(SHA-256(verifier)) of the verifier the browser keeps */
22
- verifierChallenge: string;
23
- /**
24
- * Optional opaque OIDC authorization transaction to resume through the existing
25
- * prepare/complete requests once the sign-in is complete.
26
- */
27
- oidcTransactionId?: string;
28
- };
49
+ request: TStartUpstreamSignInRequest;
29
50
  response: {
30
51
  id: string;
31
52
  /** The provider's authorization URL; the browser navigates to it. */
@@ -34,25 +55,42 @@ export interface IReq_StartUpstreamSignIn
34
55
  }
35
56
 
36
57
  /**
37
- * The provider identity is not linked, and the email the provider vouched for names an
38
- * existing account. Never answered for an email the provider did not vouch for.
58
+ * The returned provider identity can be linked to an existing account. `finishUpstreamSignIn`
59
+ * answers it in two situations:
60
+ * - on a sign-in flow, when the provider identity is not linked and the email the provider
61
+ * vouched for names an existing account. A sign-in flow never answers it for an email the
62
+ * provider did not vouch for;
63
+ * - on a link flow, for every identity whose email the provider vouched for, without any
64
+ * account or link lookup.
65
+ *
66
+ * It mints nothing. The flow stays open until its ten-minute expiry for
67
+ * `confirmUpstreamIdentityLink`.
39
68
  */
40
69
  export interface IUpstreamSignInLinkRequired {
41
70
  provider: data.TUpstreamIdentityProvider;
42
- /** The email the provider asserted. */
71
+ /** The email the provider vouched for; the confirmation screen names it. */
43
72
  email: string;
44
73
  }
45
74
 
46
75
  /**
47
- * Public: finishes an upstream sign-in after the provider returned. It can be called once
48
- * per flow and answers like password sign-in: a refresh token, or an MFA challenge to answer
49
- * through `verifyMfaChallenge` or the passkey MFA requests. Either answer ends the flow.
50
- * `linkRequired` is the third outcome: it mints nothing and leaves the flow open until its
51
- * ten-minute expiry for exactly one `confirmUpstreamIdentityLink`, which the person sends
52
- * with the same `id` and `verifier` after signing in to that account normally in the same
53
- * browser.
54
- * Refusal codes (`data.IUpstreamIdentityRefusal`): `sso_domain_required`,
55
- * `provider_email_unverified`.
76
+ * Public: finishes an upstream flow after the provider returned. The page at
77
+ * `<login>/login?upstream=<id>` calls it when it holds both a verifier for that `id` and the
78
+ * return proof from its URL fragment, and calls nothing otherwise; it never needs to know the
79
+ * flow's purpose. The verifier binds finish to the browser that started the flow, the return
80
+ * proof to the browser that returned from the provider. It answers once per flow. A finish that
81
+ * lacks the right verifier or the right return proof is refused without a code and leaves the
82
+ * flow unchanged.
83
+ *
84
+ * On a sign-in flow it answers like password sign-in: a refresh token, or an MFA challenge to
85
+ * answer through `verifyMfaChallenge` or the passkey MFA requests. Either answer ends the flow.
86
+ * `linkRequired` is the third outcome. Refusal codes (`data.IUpstreamIdentityRefusal`), in
87
+ * this order: `provider_email_unverified`, then `sso_domain_required`. A refusal with a code
88
+ * ends the flow.
89
+ *
90
+ * On a link flow it never mints a session, never creates an account and looks up no account
91
+ * and no link: it answers `linkRequired` when the provider vouched for the email, whatever
92
+ * identity the provider returned. Refusal code: `provider_email_unverified`. A refusal with a
93
+ * code ends the flow.
56
94
  */
57
95
  export interface IReq_FinishUpstreamSignIn
58
96
  extends plugins.typedRequestInterfaces.implementsTR<
@@ -64,6 +102,12 @@ export interface IReq_FinishUpstreamSignIn
64
102
  id: string;
65
103
  /** The verifier whose hash `startUpstreamSignIn` received. */
66
104
  verifier: string;
105
+ /**
106
+ * The one-time return proof that only the provider callback's redirect carries, in the URL
107
+ * fragment (`#returnProof=<proof>`). It binds finish to the browser that returned from the
108
+ * provider, as the verifier binds it to the browser that started the flow.
109
+ */
110
+ returnProof: string;
67
111
  };
68
112
  response: IReq_LoginWithEmailOrUsernameAndPassword['response'] & {
69
113
  linkRequired?: IUpstreamSignInLinkRequired;
@@ -71,15 +115,26 @@ export interface IReq_FinishUpstreamSignIn
71
115
  }
72
116
 
73
117
  /**
74
- * Links the returned provider identity to the signed-in account. An authentication change:
75
- * it needs the account's strongest enrolled proof, fresh (a passkey step-up while the
76
- * account has an active passkey, otherwise a fresh primary sign-in).
118
+ * Links the provider identity of a flow whose `finishUpstreamSignIn` answered `linkRequired`;
119
+ * any other flow fails without a code. The link stores the provider's vouched email and
120
+ * private-relay flag as the flow recorded them. It links to the signed-in account and carries
121
+ * the flow's `id` and `verifier`; no return proof is needed, because a flow answers
122
+ * `linkRequired` only to a finish that held both the verifier and the return proof. One
123
+ * confirmation screen on the login origin serves sign-in and link flows alike. It always asks
124
+ * for a new sign-in to the account, whatever session the browser holds, then names the
125
+ * provider, the provider's email and the signed-in account; only the person's explicit
126
+ * confirmation sends this request, never a URL on its own.
127
+ *
128
+ * An authentication change: it needs the account's strongest enrolled proof, fresh (a fresh
129
+ * passkey sign-in while the account has an active passkey, otherwise a fresh primary sign-in);
130
+ * an administrator-recovery session does not count. The gate is checked at entry and again
131
+ * when the link is written, and can refuse with `data.IAuthenticationChangeRefusal`.
77
132
  *
78
- * The same requests link from the account UI: `startUpstreamSignIn` without
79
- * `oidcTransactionId`, the provider round trip, then this request with the returned `id`
80
- * and `verifier`, without `finishUpstreamSignIn`.
81
- * Refusal codes: `sso_domain_required`, `upstream_identity_linked_elsewhere`,
82
- * `provider_already_linked`.
133
+ * A refused confirm, the gate's refusal included, leaves the flow open until its ten-minute
134
+ * expiry; only the link write spends it.
135
+ * Refusal codes (`data.IUpstreamIdentityRefusal`): `sso_domain_required` (the signed-in
136
+ * account's email), `provider_already_linked`, `upstream_identity_linked_elsewhere`. Never
137
+ * `provider_email_unverified`: no flow reaches this request without a vouched email.
83
138
  */
84
139
  export interface IReq_ConfirmUpstreamIdentityLink
85
140
  extends plugins.typedRequestInterfaces.implementsTR<
@@ -116,7 +171,8 @@ export interface IReq_GetUpstreamIdentities
116
171
 
117
172
  /**
118
173
  * Removes the signed-in account's link to a provider. An authentication change, gated like
119
- * `confirmUpstreamIdentityLink`. Refusal code: `last_sign_in_method`.
174
+ * `confirmUpstreamIdentityLink`; the gate can refuse with `data.IAuthenticationChangeRefusal`.
175
+ * Refusal code (`data.IUpstreamIdentityRefusal`): `last_sign_in_method`.
120
176
  */
121
177
  export interface IReq_UnlinkUpstreamIdentity
122
178
  extends plugins.typedRequestInterfaces.implementsTR<