@idp.global/interfaces 30.3.0 → 30.5.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 +46 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/activity.d.ts +5 -3
- package/dist_ts/data/activity.js +8 -2
- package/dist_ts/data/index.d.ts +1 -0
- package/dist_ts/data/index.js +2 -1
- package/dist_ts/data/loginsession.d.ts +19 -1
- package/dist_ts/data/loginsession.js +24 -2
- package/dist_ts/data/mfa.d.ts +4 -1
- package/dist_ts/data/mfa.js +8 -2
- package/dist_ts/data/oidc.d.ts +8 -0
- package/dist_ts/data/upstreamidentity.d.ts +42 -0
- package/dist_ts/data/upstreamidentity.js +15 -0
- package/dist_ts/data/user.d.ts +4 -2
- package/dist_ts/data/user.js +6 -2
- package/dist_ts/dto/activity.d.ts +6 -1
- package/dist_ts/dto/index.d.ts +1 -0
- package/dist_ts/dto/index.js +2 -1
- package/dist_ts/dto/upstreamidentity.d.ts +15 -0
- package/dist_ts/dto/upstreamidentity.js +2 -0
- package/dist_ts/request/authorization.d.ts +3 -1
- package/dist_ts/request/authorization.js +1 -1
- package/dist_ts/request/index.d.ts +1 -0
- package/dist_ts/request/index.js +2 -1
- package/dist_ts/request/upstreamidentity.d.ts +146 -0
- package/dist_ts/request/upstreamidentity.js +4 -0
- package/package.json +1 -1
- package/readme.md +77 -2
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/activity.ts +15 -3
- package/ts/data/index.ts +1 -0
- package/ts/data/loginsession.ts +34 -4
- package/ts/data/mfa.ts +12 -1
- package/ts/data/oidc.ts +9 -0
- package/ts/data/upstreamidentity.ts +52 -0
- package/ts/data/user.ts +5 -1
- package/ts/dto/activity.ts +12 -1
- package/ts/dto/index.ts +1 -0
- package/ts/dto/upstreamidentity.ts +16 -0
- package/ts/readme.md +4 -1
- package/ts/request/authorization.ts +7 -1
- package/ts/request/index.ts +1 -0
- package/ts/request/upstreamidentity.ts +176 -0
package/readme.md
CHANGED
|
@@ -137,6 +137,19 @@ The target hash is derived server-side from the canonical, authorized
|
|
|
137
137
|
data. Opaque tokens and the transfer target remain limited to the request and
|
|
138
138
|
response contracts that transport them.
|
|
139
139
|
|
|
140
|
+
`data.upstreamIdentityProviders` (`'apple'`, `'google'`) is the one closed list
|
|
141
|
+
of upstream identity providers, typed as `data.TUpstreamIdentityProvider`.
|
|
142
|
+
Every list that names a provider derives from it and is exported for runtime
|
|
143
|
+
validation: `loginSessionPrimaryAuthenticationMethods` (a session's
|
|
144
|
+
`authentication.primaryMethod`), `mfaChallengePrimaryAuthMethods`
|
|
145
|
+
(`IMfaChallenge.data.primaryAuthMethod`), `userEmailVerificationMethods` (an
|
|
146
|
+
account created from a provider's verified email records that provider) and
|
|
147
|
+
`activityAuthenticationMethods` (the `login` event's `authenticationMethod`).
|
|
148
|
+
Linking and unlinking are the `upstream_identity_linked` and
|
|
149
|
+
`upstream_identity_unlinked` activity actions, target type
|
|
150
|
+
`upstream_identity`, with the provider as their only fact; an upstream sign-in
|
|
151
|
+
is an ordinary `login` event.
|
|
152
|
+
|
|
140
153
|
## TypedRequest Contracts
|
|
141
154
|
|
|
142
155
|
Use `request` when registering handlers or creating typed clients with `@api.global/typedrequest` or `@api.global/typedsocket`.
|
|
@@ -179,7 +192,7 @@ and when a transfer token is consumed. The server authorizes and canonicalizes
|
|
|
179
192
|
the target before binding its server-derived hash to the outstanding transfer
|
|
180
193
|
token.
|
|
181
194
|
|
|
182
|
-
Request groups cover login, registration, JWT refresh, user/session queries, organization membership, invitations, apps, billing, admin actions, alerts, passport device flows, password reset, device IDs, and OIDC authorization.
|
|
195
|
+
Request groups cover login, upstream sign-in and identity links, registration, JWT refresh, user/session queries, organization membership, invitations, apps, billing, admin actions, alerts, passport device flows, password reset, device IDs, and OIDC authorization.
|
|
183
196
|
|
|
184
197
|
The OIDC V2 authorization contracts
|
|
185
198
|
`IReq_InspectOidcAuthorizationV2`, `IReq_PrepareOidcAuthorizationV2`,
|
|
@@ -193,6 +206,68 @@ or email-code proof and registration completion return the authoritative stored
|
|
|
193
206
|
value. Implementations should keep it out of registration email links and use
|
|
194
207
|
the existing authenticated OIDC prepare/complete requests for final binding.
|
|
195
208
|
|
|
209
|
+
An authorization request may carry `provider_hint`
|
|
210
|
+
(`data.IAuthorizationRequest`); `IReq_InspectOidcAuthorizationV2` returns it to
|
|
211
|
+
the login UI as `providerHint`, and the login UI starts that provider's sign-in
|
|
212
|
+
itself. The hint never skips a step of the sign-in, and a value that names no
|
|
213
|
+
offered provider is ignored.
|
|
214
|
+
|
|
215
|
+
Upstream sign-in (Apple, Google) binds the redirect flow to the browser that
|
|
216
|
+
started it, and everything runs on the login origin. `IReq_StartUpstreamSignIn`
|
|
217
|
+
takes the provider, the S256 hash of a verifier the login page keeps in its
|
|
218
|
+
sessionStorage, and a `purpose` (`data.upstreamSignInPurposes`: `sign-in`, the
|
|
219
|
+
default, or `link`); only a sign-in flow may carry the opaque OIDC transaction,
|
|
220
|
+
and `link` with `oidcTransactionId` does not compile
|
|
221
|
+
(`request.TStartUpstreamSignInRequest`). It needs no session and returns the
|
|
222
|
+
flow `id` (the OAuth `state`) and the provider's authorization URL. The server
|
|
223
|
+
records the purpose on the flow and never changes it, so a sign-in flow that
|
|
224
|
+
answered `linkRequired` stays a sign-in flow. The account UI's "Link"
|
|
225
|
+
navigates to `<login>/login?link=<provider>`, which starts a link flow. The
|
|
226
|
+
provider's callback always returns to `<login>/login?upstream=<id>` (plus `tx`
|
|
227
|
+
when one was given); that page sends `IReq_FinishUpstreamSignIn` with
|
|
228
|
+
`{ id, verifier }` once when it holds a verifier for the id, and nothing
|
|
229
|
+
otherwise. On a sign-in flow finish answers like password sign-in (a refresh
|
|
230
|
+
token or an MFA challenge, which end the flow), or with `linkRequired`
|
|
231
|
+
(provider and vouched email) when the email the provider vouched for names an
|
|
232
|
+
existing account that is not linked yet. On a link flow it never mints a
|
|
233
|
+
session, never creates an account and looks up no account and no link: it
|
|
234
|
+
answers `linkRequired` when the provider vouched for the email, whatever
|
|
235
|
+
identity the provider returned. The provider vouched for an email when its
|
|
236
|
+
signed token carries one and says it is verified; otherwise finish refuses with
|
|
237
|
+
`provider_email_unverified`, on a sign-in flow for an identity that is not
|
|
238
|
+
linked yet, before any account lookup, and on a link flow for every identity,
|
|
239
|
+
before any lookup. On a sign-in flow `sso_domain_required` follows; it judges
|
|
240
|
+
the vouched email of an identity not linked yet, or the account's email for a
|
|
241
|
+
linked identity. A finish refused with a code ends the flow; only a wrong
|
|
242
|
+
verifier leaves it usable. `linkRequired` mints nothing and leaves the flow
|
|
243
|
+
open until its ten-minute expiry for `IReq_ConfirmUpstreamIdentityLink` with
|
|
244
|
+
the same `id` and verifier, which the person sends after a new sign-in to the
|
|
245
|
+
account on the login origin and an explicit confirmation. Confirm accepts only
|
|
246
|
+
a flow whose finish answered `linkRequired` (any other flow fails without a
|
|
247
|
+
code) and stores the provider's vouched email and private-relay flag as the
|
|
248
|
+
flow recorded them. It refuses with `sso_domain_required` (judging the
|
|
249
|
+
signed-in account's email), `provider_already_linked` or
|
|
250
|
+
`upstream_identity_linked_elsewhere`, never with `provider_email_unverified`;
|
|
251
|
+
the provider's email on a link flow is never judged for SSO. A refused confirm
|
|
252
|
+
leaves the flow open, and only the link write spends it.
|
|
253
|
+
`IReq_GetUpstreamIdentities` lists the account's links as
|
|
254
|
+
`dto.IUpstreamIdentityDto` (provider, link time, the email at link time, and the
|
|
255
|
+
private-relay flag; never the provider subject or a provider token), and
|
|
256
|
+
`IReq_UnlinkUpstreamIdentity` removes the link to one provider. A refused
|
|
257
|
+
request throws a `TypedResponseError` whose `errorData` is
|
|
258
|
+
`data.IUpstreamIdentityRefusal`, a closed `code`: `sso_domain_required`,
|
|
259
|
+
`provider_email_unverified`, `upstream_identity_linked_elsewhere`,
|
|
260
|
+
`provider_already_linked` or `last_sign_in_method`.
|
|
261
|
+
|
|
262
|
+
Confirming and unlinking are authentication changes. The authentication-change
|
|
263
|
+
gate, which guards every change to how an account signs in, refuses with
|
|
264
|
+
`errorData` `data.IAuthenticationChangeRefusal` (`code`
|
|
265
|
+
`fresh_passkey_sign_in_required` or `fresh_sign_in_required`,
|
|
266
|
+
`data.authenticationChangeRefusalCodes`) wherever a new sign-in would satisfy
|
|
267
|
+
it; a refusal that no new sign-in can satisfy carries no code. The proof is
|
|
268
|
+
always a new sign-in on the login origin; there is no in-session step-up
|
|
269
|
+
request.
|
|
270
|
+
|
|
196
271
|
OIDC app contracts expose only client configuration and safe credential
|
|
197
272
|
metadata. Client-secret hashes, signing private keys, and persistence records
|
|
198
273
|
for authorization codes, access tokens, refresh tokens, and token families
|
|
@@ -200,7 +275,7 @@ remain backend-internal; protocol request and response values remain public.
|
|
|
200
275
|
|
|
201
276
|
## DTO Contracts
|
|
202
277
|
|
|
203
|
-
Use `dto` for normalized transfer objects grouped by activity, alerts, apps, billing, invitations, MFA, organizations, passport, and users. `dto.TActivityEventDto` is a discriminated structured event: it exposes only a finite action, timestamp, outcome, optional reason code, fixed target type, and allowlisted action-specific facts. It never carries event, actor, or target identifiers; free text; network data; integrity material; or delivery state. Public OIDC support includes `data.IOidcSettings` and redacted `data.IJwtVerificationKey` records.
|
|
278
|
+
Use `dto` for normalized transfer objects grouped by activity, alerts, apps, billing, invitations, MFA, organizations, passport, upstream identity links, and users. `dto.TActivityEventDto` is a discriminated structured event: it exposes only a finite action, timestamp, outcome, optional reason code, fixed target type, and allowlisted action-specific facts. It never carries event, actor, or target identifiers; free text; network data; integrity material; or delivery state. Public OIDC support includes `data.IOidcSettings` and redacted `data.IJwtVerificationKey` records.
|
|
204
279
|
|
|
205
280
|
```ts
|
|
206
281
|
const activity: dto.TActivityEventDto = {
|
package/ts/00_commitinfo_data.ts
CHANGED
package/ts/data/activity.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { upstreamIdentityProviders } from './upstreamidentity.js';
|
|
2
|
+
|
|
1
3
|
export type TActivityAction =
|
|
2
4
|
| 'login'
|
|
3
5
|
| 'logout'
|
|
@@ -67,7 +69,9 @@ export type TActivityAction =
|
|
|
67
69
|
| 'oidc_signing_key_rotated'
|
|
68
70
|
| 'oidc_lifecycle_revoked'
|
|
69
71
|
| 'org_suspended'
|
|
70
|
-
| 'org_unsuspended'
|
|
72
|
+
| 'org_unsuspended'
|
|
73
|
+
| 'upstream_identity_linked'
|
|
74
|
+
| 'upstream_identity_unlinked';
|
|
71
75
|
|
|
72
76
|
export type TActivityOutcome = 'attempted' | 'succeeded' | 'denied' | 'failed';
|
|
73
77
|
|
|
@@ -114,9 +118,17 @@ export type TActivityTargetType =
|
|
|
114
118
|
| 'scim_user'
|
|
115
119
|
| 'session'
|
|
116
120
|
| 'sso_connection'
|
|
117
|
-
| 'sso_domain'
|
|
121
|
+
| 'sso_domain'
|
|
122
|
+
| 'upstream_identity';
|
|
123
|
+
|
|
124
|
+
/** The first factor of a `login` event; an upstream provider names itself. */
|
|
125
|
+
export const activityAuthenticationMethods = [
|
|
126
|
+
'magic_link',
|
|
127
|
+
'password',
|
|
128
|
+
...upstreamIdentityProviders,
|
|
129
|
+
] as const;
|
|
118
130
|
|
|
119
|
-
export type TActivityAuthenticationMethod =
|
|
131
|
+
export type TActivityAuthenticationMethod = (typeof activityAuthenticationMethods)[number];
|
|
120
132
|
export type TActivitySessionKind = 'browser' | 'oidc';
|
|
121
133
|
export type TActivityRevocationScope =
|
|
122
134
|
| 'account'
|
package/ts/data/index.ts
CHANGED
package/ts/data/loginsession.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { upstreamIdentityProviders } from './upstreamidentity.js';
|
|
2
|
+
|
|
3
|
+
/** How a session's person first authenticated; an upstream provider names itself. */
|
|
4
|
+
export const loginSessionPrimaryAuthenticationMethods = [
|
|
5
|
+
'magic_link',
|
|
6
|
+
'passkey',
|
|
7
|
+
'password',
|
|
8
|
+
'saml',
|
|
9
|
+
...upstreamIdentityProviders,
|
|
10
|
+
] as const;
|
|
11
|
+
|
|
1
12
|
export type TLoginSessionPrimaryAuthenticationMethod =
|
|
2
|
-
|
|
3
|
-
| 'passkey'
|
|
4
|
-
| 'password'
|
|
5
|
-
| 'saml';
|
|
13
|
+
(typeof loginSessionPrimaryAuthenticationMethods)[number];
|
|
6
14
|
|
|
7
15
|
export type TLoginSessionMfaFactor = 'backup_code' | 'passkey' | 'totp';
|
|
8
16
|
|
|
@@ -13,6 +21,28 @@ export interface ILoginSessionAuthenticationEvidence {
|
|
|
13
21
|
mfaAuthenticatedAt: number | null;
|
|
14
22
|
}
|
|
15
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
|
+
|
|
16
46
|
export interface ILoginSession {
|
|
17
47
|
id: string;
|
|
18
48
|
data: {
|
package/ts/data/mfa.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import { upstreamIdentityProviders } from './upstreamidentity.js';
|
|
2
|
+
|
|
1
3
|
export type TMfaMethod = 'totp' | 'backupCode' | 'passkey';
|
|
2
4
|
|
|
3
5
|
export type TMfaChallengeStatus = 'pending' | 'completed' | 'expired';
|
|
4
6
|
|
|
7
|
+
/** The first factor an MFA challenge follows; an upstream provider names itself. */
|
|
8
|
+
export const mfaChallengePrimaryAuthMethods = [
|
|
9
|
+
'password',
|
|
10
|
+
'email',
|
|
11
|
+
...upstreamIdentityProviders,
|
|
12
|
+
] as const;
|
|
13
|
+
|
|
14
|
+
export type TMfaChallengePrimaryAuthMethod = (typeof mfaChallengePrimaryAuthMethods)[number];
|
|
15
|
+
|
|
5
16
|
export type TTotpCredentialStatus = 'pending' | 'active' | 'disabled';
|
|
6
17
|
|
|
7
18
|
export interface ITotpBackupCode {
|
|
@@ -37,7 +48,7 @@ export interface IMfaChallenge {
|
|
|
37
48
|
tokenHash: string;
|
|
38
49
|
status: TMfaChallengeStatus;
|
|
39
50
|
availableMethods: TMfaMethod[];
|
|
40
|
-
primaryAuthMethod:
|
|
51
|
+
primaryAuthMethod: TMfaChallengePrimaryAuthMethod;
|
|
41
52
|
createdAt: number;
|
|
42
53
|
expiresAt: number;
|
|
43
54
|
completedAt?: number | null;
|
package/ts/data/oidc.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* OIDC (OpenID Connect) data interfaces for third-party client support
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import type { TUpstreamIdentityProvider } from './upstreamidentity.js';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Supported OIDC scopes
|
|
7
9
|
*/
|
|
@@ -221,6 +223,13 @@ export interface IAuthorizationRequest {
|
|
|
221
223
|
* `type` with `invalid_authorization_details` (RFC 9396 section 5) and never ignores it.
|
|
222
224
|
*/
|
|
223
225
|
authorization_details?: string;
|
|
226
|
+
/**
|
|
227
|
+
* The idp.global `provider_hint` parameter: the relying app's own "Sign in with …" button asks
|
|
228
|
+
* the login UI to start that provider's sign-in at once instead of showing the sign-in choice.
|
|
229
|
+
* It is a hint only; it never skips MFA or any other step of the sign-in. A value that names
|
|
230
|
+
* no provider this installation offers is ignored: the login UI shows the sign-in choice.
|
|
231
|
+
*/
|
|
232
|
+
provider_hint?: TUpstreamIdentityProvider;
|
|
224
233
|
}
|
|
225
234
|
|
|
226
235
|
/**
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The identity providers a person can sign in to idp.global with. The list is closed and is
|
|
3
|
+
* the one source of every provider value in these contracts: login-session evidence, the MFA
|
|
4
|
+
* challenge, the email verification method and the activity vocabulary derive from it.
|
|
5
|
+
*/
|
|
6
|
+
export const upstreamIdentityProviders = ['apple', 'google'] as const;
|
|
7
|
+
|
|
8
|
+
export type TUpstreamIdentityProvider = (typeof upstreamIdentityProviders)[number];
|
|
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
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Why an upstream sign-in, link or unlink was refused. A refused request throws a
|
|
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, an unavailable provider) carries
|
|
26
|
+
* 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;
|
|
37
|
+
* - `upstream_identity_linked_elsewhere`: this provider identity is linked to another account;
|
|
38
|
+
* - `provider_already_linked`: the account already has a link to this provider;
|
|
39
|
+
* - `last_sign_in_method`: after the unlink the account would have no password, no active
|
|
40
|
+
* passkey and no other link while its email is this link's private-relay address.
|
|
41
|
+
*/
|
|
42
|
+
export type TUpstreamIdentityRefusalCode =
|
|
43
|
+
| 'sso_domain_required'
|
|
44
|
+
| 'provider_email_unverified'
|
|
45
|
+
| 'upstream_identity_linked_elsewhere'
|
|
46
|
+
| 'provider_already_linked'
|
|
47
|
+
| 'last_sign_in_method';
|
|
48
|
+
|
|
49
|
+
/** The `errorData` of a refused upstream identity request. */
|
|
50
|
+
export interface IUpstreamIdentityRefusal {
|
|
51
|
+
code: TUpstreamIdentityRefusalCode;
|
|
52
|
+
}
|
package/ts/data/user.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
TBreakGlassEligibleGlobalCapability,
|
|
5
5
|
TDelegableGlobalCapability,
|
|
6
6
|
} from './authorization.js';
|
|
7
|
+
import { upstreamIdentityProviders } from './upstreamidentity.js';
|
|
7
8
|
|
|
8
9
|
export type TBreakGlassJustificationCode =
|
|
9
10
|
| 'access_recovery'
|
|
@@ -78,7 +79,9 @@ export type TAdministratorRecovery = IAdministratorRecoveryBase & (
|
|
|
78
79
|
* - `magic-link`: an emailed sign-in link was followed;
|
|
79
80
|
* - `password-reset`: an emailed password-reset link was completed;
|
|
80
81
|
* - `fixture`: a local development fixture (development IdP persona, seed data); nobody
|
|
81
|
-
* proved control of the address
|
|
82
|
+
* proved control of the address;
|
|
83
|
+
* - an upstream provider (`apple`, `google`): the account was created from that provider's
|
|
84
|
+
* signed assertion that the address is verified.
|
|
82
85
|
*/
|
|
83
86
|
export const userEmailVerificationMethods = [
|
|
84
87
|
'registration',
|
|
@@ -86,6 +89,7 @@ export const userEmailVerificationMethods = [
|
|
|
86
89
|
'magic-link',
|
|
87
90
|
'password-reset',
|
|
88
91
|
'fixture',
|
|
92
|
+
...upstreamIdentityProviders,
|
|
89
93
|
] as const;
|
|
90
94
|
|
|
91
95
|
export type TUserEmailVerificationMethod = (typeof userEmailVerificationMethods)[number];
|
package/ts/dto/activity.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
TActivityTargetType,
|
|
13
13
|
} from '../data/activity.js';
|
|
14
14
|
import type { TOAuthClientType } from '../data/app.js';
|
|
15
|
+
import type { TUpstreamIdentityProvider } from '../data/upstreamidentity.js';
|
|
15
16
|
|
|
16
17
|
type TActivityEventFor<
|
|
17
18
|
TAction extends TActivityAction,
|
|
@@ -171,7 +172,17 @@ export type TActivityEventDto =
|
|
|
171
172
|
{ revocationScope: TActivityRevocationScope }
|
|
172
173
|
>
|
|
173
174
|
| TActivityEventFor<'org_suspended', 'organization', null>
|
|
174
|
-
| TActivityEventFor<'org_unsuspended', 'organization', null
|
|
175
|
+
| TActivityEventFor<'org_unsuspended', 'organization', null>
|
|
176
|
+
| TActivityEventFor<
|
|
177
|
+
'upstream_identity_linked',
|
|
178
|
+
'upstream_identity',
|
|
179
|
+
{ provider: TUpstreamIdentityProvider }
|
|
180
|
+
>
|
|
181
|
+
| TActivityEventFor<
|
|
182
|
+
'upstream_identity_unlinked',
|
|
183
|
+
'upstream_identity',
|
|
184
|
+
{ provider: TUpstreamIdentityProvider }
|
|
185
|
+
>;
|
|
175
186
|
|
|
176
187
|
type TAssertNoMissingActivityActions<TValue extends never> = TValue;
|
|
177
188
|
type TActivityEventDtoHasEveryAction = TAssertNoMissingActivityActions<
|
package/ts/dto/index.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TUpstreamIdentityProvider } from '../data/upstreamidentity.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A link between the account and an upstream provider identity, as the account UI shows it.
|
|
5
|
+
* An account has at most one link per provider, so the provider names the link. The provider's
|
|
6
|
+
* subject and every provider token stay server-side.
|
|
7
|
+
*/
|
|
8
|
+
export interface IUpstreamIdentityDto {
|
|
9
|
+
provider: TUpstreamIdentityProvider;
|
|
10
|
+
/** epoch ms when the link was made */
|
|
11
|
+
linkedAt: number;
|
|
12
|
+
/** The email the provider vouched for when the link was made; later provider emails never replace it. */
|
|
13
|
+
email: string;
|
|
14
|
+
/** The provider signed that `email` is a private relay address (Apple's `is_private_email`). */
|
|
15
|
+
isPrivateEmail: boolean;
|
|
16
|
+
}
|
package/ts/readme.md
CHANGED
|
@@ -57,6 +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), flow purposes and refusal codes
|
|
61
|
+
- the authentication-change gate's refusal codes
|
|
60
62
|
|
|
61
63
|
### `request`
|
|
62
64
|
|
|
@@ -71,10 +73,11 @@ The `request` export includes typed request contracts for:
|
|
|
71
73
|
- billing and JWT validation-keyset support
|
|
72
74
|
- alert and passport approval flows
|
|
73
75
|
- OIDC authorization preparation and completion
|
|
76
|
+
- upstream sign-in (Apple, Google) and identity links
|
|
74
77
|
|
|
75
78
|
### `dto`
|
|
76
79
|
|
|
77
|
-
The `dto` export includes normalized transfer objects for activity, alerts, apps, billing, invitations, MFA, organizations, passport, and users. Activity responses use the discriminated `TActivityEventDto` union, which contains only finite classifications and allowlisted per-action facts. Persistence identities, actor and target identities, free text, network data, integrity fields, and sink delivery state are backend-private.
|
|
80
|
+
The `dto` export includes normalized transfer objects for activity, alerts, apps, billing, invitations, MFA, organizations, passport, upstream identity links, and users. Activity responses use the discriminated `TActivityEventDto` union, which contains only finite classifications and allowlisted per-action facts. Persistence identities, actor and target identities, free text, network data, integrity fields, and sink delivery state are backend-private.
|
|
78
81
|
|
|
79
82
|
### `tags`
|
|
80
83
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type IOidcAppConnectionView,
|
|
4
|
+
type TOidcScope,
|
|
5
|
+
type TUpstreamIdentityProvider,
|
|
6
|
+
} from '../data/index.js';
|
|
3
7
|
|
|
4
8
|
export interface IReq_CompleteOidcAuthorization
|
|
5
9
|
extends plugins.typedRequestInterfaces.implementsTR<
|
|
@@ -70,6 +74,8 @@ export interface IReq_InspectOidcAuthorizationV2
|
|
|
70
74
|
prompt: 'none' | 'login' | 'consent' | null;
|
|
71
75
|
/** The transaction asks for an app connection: the sign-in must use a passkey. Nothing more before the sign-in. */
|
|
72
76
|
appConnection?: { requiresPasskey: true };
|
|
77
|
+
/** The authorize request's `provider_hint`: the login UI starts this provider's sign-in itself. */
|
|
78
|
+
providerHint?: TUpstreamIdentityProvider;
|
|
73
79
|
};
|
|
74
80
|
}
|
|
75
81
|
|
package/ts/request/index.ts
CHANGED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
import * as data from '../data/index.js';
|
|
3
|
+
import * as dto from '../dto/index.js';
|
|
4
|
+
import type { IReq_LoginWithEmailOrUsernameAndPassword } from './login.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
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
|
+
*
|
|
37
|
+
* A sign-in flow starts on the login page, optionally with an OIDC authorization transaction.
|
|
38
|
+
* A link flow starts when the account UI's "Link" navigates to `<login>/login?link=<provider>`;
|
|
39
|
+
* that page starts it with `purpose: 'link'` and goes to the provider.
|
|
40
|
+
*/
|
|
41
|
+
export interface IReq_StartUpstreamSignIn
|
|
42
|
+
extends plugins.typedRequestInterfaces.implementsTR<
|
|
43
|
+
plugins.typedRequestInterfaces.ITypedRequest,
|
|
44
|
+
IReq_StartUpstreamSignIn
|
|
45
|
+
> {
|
|
46
|
+
method: 'startUpstreamSignIn';
|
|
47
|
+
request: TStartUpstreamSignInRequest;
|
|
48
|
+
response: {
|
|
49
|
+
id: string;
|
|
50
|
+
/** The provider's authorization URL; the browser navigates to it. */
|
|
51
|
+
authorizationUrl: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The returned provider identity can be linked to an existing account. `finishUpstreamSignIn`
|
|
57
|
+
* answers it in two situations:
|
|
58
|
+
* - on a sign-in flow, when the provider identity is not linked and the email the provider
|
|
59
|
+
* vouched for names an existing account. A sign-in flow never answers it for an email the
|
|
60
|
+
* provider did not vouch for;
|
|
61
|
+
* - on a link flow, for every identity whose email the provider vouched for, without any
|
|
62
|
+
* account or link lookup.
|
|
63
|
+
*
|
|
64
|
+
* It mints nothing. The flow stays open until its ten-minute expiry for
|
|
65
|
+
* `confirmUpstreamIdentityLink`.
|
|
66
|
+
*/
|
|
67
|
+
export interface IUpstreamSignInLinkRequired {
|
|
68
|
+
provider: data.TUpstreamIdentityProvider;
|
|
69
|
+
/** The email the provider vouched for; the confirmation screen names it. */
|
|
70
|
+
email: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Public: finishes an upstream flow after the provider returned. The page at
|
|
75
|
+
* `<login>/login?upstream=<id>` calls it when it holds a verifier for that `id`, and calls
|
|
76
|
+
* nothing otherwise; it never needs to know the flow's purpose. It answers once per flow.
|
|
77
|
+
*
|
|
78
|
+
* On a sign-in flow it answers like password sign-in: a refresh token, or an MFA challenge to
|
|
79
|
+
* answer through `verifyMfaChallenge` or the passkey MFA requests. Either answer ends the flow.
|
|
80
|
+
* `linkRequired` is the third outcome. Refusal codes (`data.IUpstreamIdentityRefusal`), in
|
|
81
|
+
* this order: `provider_email_unverified`, then `sso_domain_required`. A refusal with a code
|
|
82
|
+
* ends the flow; only a wrong verifier leaves the flow usable.
|
|
83
|
+
*
|
|
84
|
+
* On a link flow it never mints a session, never creates an account and looks up no account
|
|
85
|
+
* and no link: it answers `linkRequired` when the provider vouched for the email, whatever
|
|
86
|
+
* identity the provider returned. Refusal code: `provider_email_unverified`. A refusal with a
|
|
87
|
+
* code ends the flow.
|
|
88
|
+
*/
|
|
89
|
+
export interface IReq_FinishUpstreamSignIn
|
|
90
|
+
extends plugins.typedRequestInterfaces.implementsTR<
|
|
91
|
+
plugins.typedRequestInterfaces.ITypedRequest,
|
|
92
|
+
IReq_FinishUpstreamSignIn
|
|
93
|
+
> {
|
|
94
|
+
method: 'finishUpstreamSignIn';
|
|
95
|
+
request: {
|
|
96
|
+
id: string;
|
|
97
|
+
/** The verifier whose hash `startUpstreamSignIn` received. */
|
|
98
|
+
verifier: string;
|
|
99
|
+
};
|
|
100
|
+
response: IReq_LoginWithEmailOrUsernameAndPassword['response'] & {
|
|
101
|
+
linkRequired?: IUpstreamSignInLinkRequired;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Links the provider identity of a flow whose `finishUpstreamSignIn` answered `linkRequired`;
|
|
107
|
+
* any other flow fails without a code. The link stores the provider's vouched email and
|
|
108
|
+
* private-relay flag as the flow recorded them. It links to the signed-in account and carries
|
|
109
|
+
* the flow's `id` and `verifier`. One confirmation screen on the login origin serves sign-in
|
|
110
|
+
* and link flows alike. It always asks for a new sign-in to the account, whatever session the
|
|
111
|
+
* browser holds, then names the provider, the provider's email and the signed-in account; only
|
|
112
|
+
* the person's explicit confirmation sends this request, never a URL on its own.
|
|
113
|
+
*
|
|
114
|
+
* An authentication change: it needs the account's strongest enrolled proof, fresh (a fresh
|
|
115
|
+
* passkey sign-in while the account has an active passkey, otherwise a fresh primary sign-in);
|
|
116
|
+
* an administrator-recovery session does not count. The gate is checked at entry and again
|
|
117
|
+
* when the link is written, and can refuse with `data.IAuthenticationChangeRefusal`.
|
|
118
|
+
*
|
|
119
|
+
* A refused confirm, the gate's refusal included, leaves the flow open until its ten-minute
|
|
120
|
+
* expiry; only the link write spends it.
|
|
121
|
+
* Refusal codes (`data.IUpstreamIdentityRefusal`): `sso_domain_required` (the signed-in
|
|
122
|
+
* account's email), `provider_already_linked`, `upstream_identity_linked_elsewhere`. Never
|
|
123
|
+
* `provider_email_unverified`: no flow reaches this request without a vouched email.
|
|
124
|
+
*/
|
|
125
|
+
export interface IReq_ConfirmUpstreamIdentityLink
|
|
126
|
+
extends plugins.typedRequestInterfaces.implementsTR<
|
|
127
|
+
plugins.typedRequestInterfaces.ITypedRequest,
|
|
128
|
+
IReq_ConfirmUpstreamIdentityLink
|
|
129
|
+
> {
|
|
130
|
+
method: 'confirmUpstreamIdentityLink';
|
|
131
|
+
request: {
|
|
132
|
+
jwt: string;
|
|
133
|
+
id: string;
|
|
134
|
+
verifier: string;
|
|
135
|
+
};
|
|
136
|
+
response: {
|
|
137
|
+
upstreamIdentity: dto.IUpstreamIdentityDto;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Lists the signed-in account's upstream identity links.
|
|
143
|
+
*/
|
|
144
|
+
export interface IReq_GetUpstreamIdentities
|
|
145
|
+
extends plugins.typedRequestInterfaces.implementsTR<
|
|
146
|
+
plugins.typedRequestInterfaces.ITypedRequest,
|
|
147
|
+
IReq_GetUpstreamIdentities
|
|
148
|
+
> {
|
|
149
|
+
method: 'getUpstreamIdentities';
|
|
150
|
+
request: {
|
|
151
|
+
jwt: string;
|
|
152
|
+
};
|
|
153
|
+
response: {
|
|
154
|
+
upstreamIdentities: dto.IUpstreamIdentityDto[];
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Removes the signed-in account's link to a provider. An authentication change, gated like
|
|
160
|
+
* `confirmUpstreamIdentityLink`; the gate can refuse with `data.IAuthenticationChangeRefusal`.
|
|
161
|
+
* Refusal code (`data.IUpstreamIdentityRefusal`): `last_sign_in_method`.
|
|
162
|
+
*/
|
|
163
|
+
export interface IReq_UnlinkUpstreamIdentity
|
|
164
|
+
extends plugins.typedRequestInterfaces.implementsTR<
|
|
165
|
+
plugins.typedRequestInterfaces.ITypedRequest,
|
|
166
|
+
IReq_UnlinkUpstreamIdentity
|
|
167
|
+
> {
|
|
168
|
+
method: 'unlinkUpstreamIdentity';
|
|
169
|
+
request: {
|
|
170
|
+
jwt: string;
|
|
171
|
+
provider: data.TUpstreamIdentityProvider;
|
|
172
|
+
};
|
|
173
|
+
response: {
|
|
174
|
+
success: boolean;
|
|
175
|
+
};
|
|
176
|
+
}
|