@venturekit/auth 0.0.50 → 0.0.52

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.
Files changed (118) hide show
  1. package/README.md +8 -7
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
  7. package/dist/server/api-keys.d.ts +10 -5
  8. package/dist/server/api-keys.d.ts.map +1 -1
  9. package/dist/server/api-keys.js +24 -8
  10. package/dist/server/api-keys.js.map +1 -1
  11. package/dist/server/config.d.ts +6 -0
  12. package/dist/server/config.d.ts.map +1 -1
  13. package/dist/server/config.js +2 -0
  14. package/dist/server/config.js.map +1 -1
  15. package/dist/server/cookies.d.ts +9 -5
  16. package/dist/server/cookies.d.ts.map +1 -1
  17. package/dist/server/cookies.js +19 -6
  18. package/dist/server/cookies.js.map +1 -1
  19. package/dist/server/errors.d.ts +18 -2
  20. package/dist/server/errors.d.ts.map +1 -1
  21. package/dist/server/errors.js +46 -3
  22. package/dist/server/errors.js.map +1 -1
  23. package/dist/server/federated/account-linking.d.ts +90 -0
  24. package/dist/server/federated/account-linking.d.ts.map +1 -0
  25. package/dist/server/federated/account-linking.js +78 -0
  26. package/dist/server/federated/account-linking.js.map +1 -0
  27. package/dist/server/federated/authorization.d.ts +81 -0
  28. package/dist/server/federated/authorization.d.ts.map +1 -0
  29. package/dist/server/federated/authorization.js +229 -0
  30. package/dist/server/federated/authorization.js.map +1 -0
  31. package/dist/server/federated/credentials.d.ts +22 -0
  32. package/dist/server/federated/credentials.d.ts.map +1 -0
  33. package/dist/server/federated/credentials.js +81 -0
  34. package/dist/server/federated/credentials.js.map +1 -0
  35. package/dist/server/federated/oauth-transaction.d.ts +54 -0
  36. package/dist/server/federated/oauth-transaction.d.ts.map +1 -0
  37. package/dist/server/federated/oauth-transaction.js +92 -0
  38. package/dist/server/federated/oauth-transaction.js.map +1 -0
  39. package/dist/server/federated/providers.d.ts +34 -0
  40. package/dist/server/federated/providers.d.ts.map +1 -0
  41. package/dist/server/federated/providers.js +65 -0
  42. package/dist/server/federated/providers.js.map +1 -0
  43. package/dist/server/federated/sign-in.d.ts +81 -0
  44. package/dist/server/federated/sign-in.d.ts.map +1 -0
  45. package/dist/server/federated/sign-in.js +180 -0
  46. package/dist/server/federated/sign-in.js.map +1 -0
  47. package/dist/server/federated/types.d.ts +36 -0
  48. package/dist/server/federated/types.d.ts.map +1 -0
  49. package/dist/server/federated/types.js +5 -0
  50. package/dist/server/federated/types.js.map +1 -0
  51. package/dist/server/federated-routes.d.ts +15 -7
  52. package/dist/server/federated-routes.d.ts.map +1 -1
  53. package/dist/server/federated-routes.js +27 -16
  54. package/dist/server/federated-routes.js.map +1 -1
  55. package/dist/server/federated.d.ts +25 -196
  56. package/dist/server/federated.d.ts.map +1 -1
  57. package/dist/server/federated.js +19 -521
  58. package/dist/server/federated.js.map +1 -1
  59. package/dist/server/forgot-password.d.ts +4 -3
  60. package/dist/server/forgot-password.d.ts.map +1 -1
  61. package/dist/server/forgot-password.js +3 -5
  62. package/dist/server/forgot-password.js.map +1 -1
  63. package/dist/server/handoff-routes.d.ts +16 -5
  64. package/dist/server/handoff-routes.d.ts.map +1 -1
  65. package/dist/server/handoff-routes.js +23 -11
  66. package/dist/server/handoff-routes.js.map +1 -1
  67. package/dist/server/impersonation.d.ts +6 -3
  68. package/dist/server/impersonation.d.ts.map +1 -1
  69. package/dist/server/impersonation.js +11 -5
  70. package/dist/server/impersonation.js.map +1 -1
  71. package/dist/server/index.d.ts +5 -2
  72. package/dist/server/index.d.ts.map +1 -1
  73. package/dist/server/index.js +2 -1
  74. package/dist/server/index.js.map +1 -1
  75. package/dist/server/invitations.d.ts +6 -2
  76. package/dist/server/invitations.d.ts.map +1 -1
  77. package/dist/server/invitations.js +6 -3
  78. package/dist/server/invitations.js.map +1 -1
  79. package/dist/server/local-cognito.d.ts +19 -0
  80. package/dist/server/local-cognito.d.ts.map +1 -0
  81. package/dist/server/local-cognito.js +19 -0
  82. package/dist/server/local-cognito.js.map +1 -0
  83. package/dist/server/refresh.d.ts +23 -12
  84. package/dist/server/refresh.d.ts.map +1 -1
  85. package/dist/server/refresh.js +35 -19
  86. package/dist/server/refresh.js.map +1 -1
  87. package/dist/server/resource-scope.d.ts +19 -0
  88. package/dist/server/resource-scope.d.ts.map +1 -0
  89. package/dist/server/resource-scope.js +2 -0
  90. package/dist/server/resource-scope.js.map +1 -0
  91. package/dist/server/route-rate-limit.d.ts +50 -0
  92. package/dist/server/route-rate-limit.d.ts.map +1 -0
  93. package/dist/server/route-rate-limit.js +39 -0
  94. package/dist/server/route-rate-limit.js.map +1 -0
  95. package/dist/server/session-routes.d.ts +9 -2
  96. package/dist/server/session-routes.d.ts.map +1 -1
  97. package/dist/server/session-routes.js +6 -4
  98. package/dist/server/session-routes.js.map +1 -1
  99. package/dist/server/sign-up.d.ts +32 -17
  100. package/dist/server/sign-up.d.ts.map +1 -1
  101. package/dist/server/sign-up.js +30 -12
  102. package/dist/server/sign-up.js.map +1 -1
  103. package/dist/server/store/postgres.d.ts.map +1 -1
  104. package/dist/server/store/postgres.js +43 -27
  105. package/dist/server/store/postgres.js.map +1 -1
  106. package/dist/server/verification.d.ts +76 -33
  107. package/dist/server/verification.d.ts.map +1 -1
  108. package/dist/server/verification.js +68 -67
  109. package/dist/server/verification.js.map +1 -1
  110. package/dist/server/verify.d.ts.map +1 -1
  111. package/dist/server/verify.js +8 -3
  112. package/dist/server/verify.js.map +1 -1
  113. package/dist/session/index.d.ts +11 -13
  114. package/dist/session/index.d.ts.map +1 -1
  115. package/dist/session/index.js +13 -14
  116. package/dist/session/index.js.map +1 -1
  117. package/package.json +6 -6
  118. package/src/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
@@ -28,6 +28,7 @@ import { type RequestContext } from '@venturekit/runtime';
28
28
  import { type CookieOptions } from './cookies.js';
29
29
  import { type AuthServerConfig } from './config.js';
30
30
  import { type ExistingPasswordAccountPolicy, type FederatedProfile, type FederatedProvider } from './federated.js';
31
+ import { type AuthRouteRateLimitOption } from './route-rate-limit.js';
31
32
  /**
32
33
  * Body shape for the `start` route.
33
34
  */
@@ -62,8 +63,9 @@ export interface FederatedOnSignInArgs {
62
63
  */
63
64
  ctx: RequestContext;
64
65
  /**
65
- * `true` when this sign-in converted an existing PASSWORD account into
66
- * a federation-managed one — the user's own password was replaced (see
66
+ * `true` when this sign-in linked the provider identity to an existing
67
+ * account it was not bound to — the account's password was replaced and
68
+ * its other sessions were signed out (see
67
69
  * {@link FederatedAuthRoutesOptions.onExistingPasswordAccount}). Notify
68
70
  * the user from this hook.
69
71
  */
@@ -97,11 +99,12 @@ export interface FederatedAuthRoutesOptions {
97
99
  */
98
100
  transactional?: boolean;
99
101
  /**
100
- * What to do when the IdP-verified email belongs to an existing
101
- * PASSWORD account: `'link'` (default) replaces that password and
102
- * signs the user in — `onSignIn` receives `accountLinked: true` so the
103
- * app can tell them; `'reject'` answers 409 `federated_account_exists`
104
- * and leaves the account untouched. See `signInAsFederatedUser`.
102
+ * What to do when the provider's address belongs to an existing account
103
+ * the provider is not bound to: `'link-verified'` (default) links it
104
+ * when both the provider and the account proved the address — `onSignIn`
105
+ * receives `accountLinked: true` so the app can tell the user — and
106
+ * answers 409 `federated_link_unverified` otherwise; `'reject'` always
107
+ * answers 409 `federated_account_exists`. See `account-linking.ts`.
105
108
  */
106
109
  onExistingPasswordAccount?: ExistingPasswordAccountPolicy;
107
110
  /**
@@ -110,6 +113,11 @@ export interface FederatedAuthRoutesOptions {
110
113
  * `ctx.tenant` is populated before `onSignIn` runs.
111
114
  */
112
115
  middleware?: import('@venturekit/runtime').Middleware<RequestContext>[];
116
+ /**
117
+ * Per-client-IP limits: start / callback 30/min, logout 60/min by
118
+ * default. Tune them, or `false` to disable.
119
+ */
120
+ rateLimit?: AuthRouteRateLimitOption;
113
121
  /**
114
122
  * Auth-server config override. Defaults to `loadAuthServerConfig()`
115
123
  * which reads from env. Pass an explicit config in tests.
@@ -1 +1 @@
1
- {"version":3,"file":"federated-routes.d.ts","sourceRoot":"","sources":["../../src/server/federated-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,OAAO,IAAI,aAAa,EAC9B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,cAAc,EAMpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,KAAK,aAAa,EASnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,KAAK,6BAA6B,EAClC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAMvB,MAAM,gBAAgB,CAAC;AAIxB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,OAAO,EAAE,gBAAgB,CAAC;IAC1B,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,GAAG,EAAE,cAAc,CAAC;IACpB;;;;;OAKG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB,gEAAgE;IAChE,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAE9C,MAAM,WAAW,0BAA0B;IACzC,uCAAuC;IACvC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,CACT,IAAI,EAAE,qBAAqB,KACxB,OAAO,CAAC,uBAAuB,CAAC,GAAG,uBAAuB,CAAC;IAChE;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,yBAAyB,CAAC,EAAE,6BAA6B,CAAC;IAC1D;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,qBAAqB,EAAE,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;IACxE;;;OAGG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,aAAa,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,aAAa,CAAC,CAAC;CAC1E;AAED,MAAM,WAAW,uBAAuB,CAAC,GAAG,GAAG,OAAO;IACpD,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,gEAAgE;IAChE,GAAG,CAAC,EAAE,GAAG,CAAC;CACX;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,CACL,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,QAAQ,EAAE,CACR,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,MAAM,EAAE,CACN,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACvC;AAwCD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAoJrB"}
1
+ {"version":3,"file":"federated-routes.d.ts","sourceRoot":"","sources":["../../src/server/federated-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;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MG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,yBAAyB,CAAC,EAAE,6BAA6B,CAAC;IAC1D;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,qBAAqB,EAAE,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;IACxE;;;OAGG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,aAAa,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,aAAa,CAAC,CAAC;CAC1E;AAED,MAAM,WAAW,uBAAuB,CAAC,GAAG,GAAG,OAAO;IACpD,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,gEAAgE;IAChE,GAAG,CAAC,EAAE,GAAG,CAAC;CACX;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,CACL,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,QAAQ,EAAE,CACR,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,MAAM,EAAE,CACN,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACvC;AAwCD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAmKrB"}
@@ -1,9 +1,10 @@
1
1
  import { BadRequestError, InternalError, UnauthorizedError, handler, setCookie, } from '@venturekit/runtime';
2
- import { buildOAuthStateCookie, buildClearSessionCookies, buildSessionCookies, clearOAuthStateCookie, oauthStateCookieName, readCookieFromEvent, REFRESH_TOKEN_COOKIE, } from './cookies.js';
2
+ import { buildOAuthStateCookie, buildClearSessionCookies, buildSessionCookies, clearOAuthStateCookie, oauthStateCookieName, readCookieFromEvent, resolveSessionCookieNames, } from './cookies.js';
3
3
  import { loadAuthServerConfig } from './config.js';
4
- import { buildAuthorizeUrl, exchangeAuthorizationCode, generateOAuthState, signInAsFederatedUser, verifyOAuthState, } from './federated.js';
4
+ import { buildAuthorizeUrl, createOAuthTransaction, exchangeAuthorizationCode, serializeOAuthTransaction, signInAsFederatedUser, verifyOAuthTransaction, } from './federated.js';
5
5
  import { revokeRefreshToken } from './revoke.js';
6
6
  import { verifyAndDecode } from './verify.js';
7
+ import { AUTH_ROUTE_RATE_LIMITS, authRouteRateLimit } from './route-rate-limit.js';
7
8
  /**
8
9
  * Build the start / callback / logout Lambda handlers for a given
9
10
  * federated provider.
@@ -43,6 +44,10 @@ function toStateCookieOptions(co) {
43
44
  export function createFederatedAuthRoutes(options) {
44
45
  const { provider, transactional = true } = options;
45
46
  const extraMiddleware = options.middleware ?? [];
47
+ const limited = (route, defaults) => [
48
+ ...authRouteRateLimit(`federated:${provider}:${route}`, options.rateLimit, defaults),
49
+ ...extraMiddleware,
50
+ ];
46
51
  // Resolved per request: the right Domain attribute can differ by
47
52
  // request host (white-label tenants), so a function option is
48
53
  // re-evaluated on every call. Start and callback are separate
@@ -53,23 +58,22 @@ export function createFederatedAuthRoutes(options) {
53
58
  ? options.cookieOptions(ctx)
54
59
  : options.cookieOptions;
55
60
  // ─── start ──────────────────────────────────────────────
56
- // The handler body owns the `state` so it can both stash the
57
- // CSRF cookie and embed the value in the authorize URL. A
58
- // middleware-only design would force generating `state` twice or
59
- // smuggling it through `ctx` — neither is worth the indirection.
61
+ // The handler body owns the OAuth transaction (state, PKCE verifier,
62
+ // nonce) so it can both stash it in the cookie and embed its public
63
+ // half in the authorize URL.
60
64
  const start = handler(async (body, ctx) => {
61
65
  if (!body?.redirectUri || typeof body.redirectUri !== 'string') {
62
66
  throw new BadRequestError('redirectUri is required');
63
67
  }
64
- const state = generateOAuthState();
68
+ const transaction = createOAuthTransaction(provider);
65
69
  const authorizeUrl = await buildAuthorizeUrl({
66
70
  provider,
67
71
  redirectUri: body.redirectUri,
68
- state,
72
+ transaction,
69
73
  });
70
- setCookie(ctx, buildOAuthStateCookie(provider, state, toStateCookieOptions(cookieOptionsFor(ctx))));
74
+ setCookie(ctx, buildOAuthStateCookie(provider, serializeOAuthTransaction(transaction), toStateCookieOptions(cookieOptionsFor(ctx))));
71
75
  return { authorizeUrl };
72
- }, { status: 200, middleware: extraMiddleware });
76
+ }, { status: 200, middleware: limited('start', AUTH_ROUTE_RATE_LIMITS.federatedStart) });
73
77
  // ─── callback ───────────────────────────────────────────
74
78
  const callback = handler(async (body, ctx) => {
75
79
  if (!body?.code || !body?.state || !body?.redirectUri) {
@@ -79,14 +83,15 @@ export function createFederatedAuthRoutes(options) {
79
83
  // location) — reading only `headers.cookie` returns nothing under
80
84
  // the default HTTP API deploy, which surfaced as a spurious
81
85
  // "Invalid OAuth state" on every federated callback.
82
- const cookieState = readCookieFromEvent(ctx.rawEvent, oauthStateCookieName(provider));
83
- if (!verifyOAuthState(body.state, cookieState ?? undefined)) {
86
+ const transaction = verifyOAuthTransaction(provider, body.state, readCookieFromEvent(ctx.rawEvent, oauthStateCookieName(provider)));
87
+ if (!transaction) {
84
88
  throw new UnauthorizedError('Invalid OAuth state');
85
89
  }
86
90
  const profile = await exchangeAuthorizationCode({
87
91
  provider,
88
92
  code: body.code,
89
93
  redirectUri: body.redirectUri,
94
+ transaction,
90
95
  });
91
96
  const tokens = await signInAsFederatedUser({
92
97
  provider,
@@ -134,22 +139,28 @@ export function createFederatedAuthRoutes(options) {
134
139
  }, {
135
140
  status: 200,
136
141
  transactional,
137
- middleware: extraMiddleware,
142
+ middleware: limited('callback', AUTH_ROUTE_RATE_LIMITS.federatedCallback),
138
143
  });
139
144
  // ─── logout ─────────────────────────────────────────────
140
145
  const logout = handler(async (_body, ctx) => {
141
- const refreshToken = readCookieFromEvent(ctx.rawEvent, REFRESH_TOKEN_COOKIE);
146
+ const cookieOptions = cookieOptionsFor(ctx);
147
+ // The refresh cookie under the name THIS session uses — an app with
148
+ // its own cookie names would otherwise never get its token revoked.
149
+ const refreshToken = readCookieFromEvent(ctx.rawEvent, resolveSessionCookieNames(cookieOptions).refresh);
142
150
  if (refreshToken) {
143
151
  await revokeRefreshToken(refreshToken, options.config);
144
152
  }
145
153
  // Clears must carry the same Domain/Path attributes as the set
146
154
  // cookies, or the browser keeps the originals — hence the same
147
155
  // per-request options resolution.
148
- for (const cookie of buildClearSessionCookies(cookieOptionsFor(ctx))) {
156
+ for (const cookie of buildClearSessionCookies(cookieOptions)) {
149
157
  setCookie(ctx, cookie);
150
158
  }
151
159
  return { ok: true };
152
- }, { status: 200 });
160
+ }, {
161
+ status: 200,
162
+ middleware: authRouteRateLimit('logout', options.rateLimit, AUTH_ROUTE_RATE_LIMITS.logout),
163
+ });
153
164
  return { start, callback, logout };
154
165
  }
155
166
  //# sourceMappingURL=federated-routes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"federated-routes.js","sourceRoot":"","sources":["../../src/server/federated-routes.ts"],"names":[],"mappings":"AA+BA,OAAO,EAEL,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,SAAS,GACV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAGL,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAyB,MAAM,aAAa,CAAC;AAC1E,OAAO,EAIL,iBAAiB,EACjB,yBAAyB,EACzB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC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AC;AACrC,CAAC"}
@@ -6,212 +6,41 @@
6
6
  *
7
7
  * 1. **SPA** — user clicks "Sign in with Google".
8
8
  * 2. **SPA → API** — `POST /auth/federated/google/start { redirectUri }`.
9
- * The `redirectUri` is a page on the SPA itself (e.g.
10
- * `https://app.example.com/auth/google/callback`) and must be
9
+ * The `redirectUri` is a page on the SPA itself and must be
11
10
  * registered with the IdP as an allowed redirect.
12
- * 3. **API → SPA** — `{ authorizeUrl }` plus an HttpOnly cookie
13
- * holding a CSRF `state`. The API computes the URL with
14
- * {@link buildAuthorizeUrl}.
11
+ * 3. **API → SPA** — `{ authorizeUrl }` plus an HttpOnly cookie holding
12
+ * the OAuth transaction ({@link createOAuthTransaction}: CSRF
13
+ * `state`, PKCE verifier, OIDC nonce — whichever the provider uses).
15
14
  * 4. **SPA** navigates to `authorizeUrl`.
16
- * 5. **IdP → SPA** — after authentication, the IdP 302s to
17
- * `redirectUri?code=…&state=…`. The SPA reads the query, then
18
- * calls the API again.
15
+ * 5. **IdP → SPA** — `redirectUri?code=…&state=…`; the SPA calls the API.
19
16
  * 6. **SPA → API** — `POST /auth/federated/google/complete
20
17
  * { code, state, redirectUri }`. The API:
21
- * - re-checks `state` against the cookie ({@link verifyOAuthState});
22
- * - exchanges the code for tokens at the IdP via
23
- * {@link exchangeAuthorizationCode} (the
24
- * `client_secret` lives in Secrets Manager, never in the SPA);
25
- * - resolves the user's verified profile;
26
- * - calls {@link signInAsFederatedUser} which mints a Cognito
27
- * session for the same email (creating the user on first
28
- * contact).
18
+ * - checks `state` against the cookie ({@link verifyOAuthTransaction});
19
+ * - redeems the code with the PKCE verifier and validates the
20
+ * `id_token` claims ({@link exchangeAuthorizationCode});
21
+ * - enters the account bound to that identity, creating or linking
22
+ * it under the rules of `account-linking.ts`
23
+ * ({@link signInAsFederatedUser}).
29
24
  * 7. **API → SPA** — Set-Cookie session + JSON envelope.
30
25
  *
31
- * The SPA never sees the `client_secret`, the IdP `access_token`, or
32
- * the OAuth `code` after step 6. Cookies stay HttpOnly + SameSite=Lax.
26
+ * The SPA never sees the `client_secret`, the IdP tokens, or the PKCE
27
+ * verifier. `createFederatedAuthRoutes` packages steps 2–7.
33
28
  *
34
29
  * The OAuth `client_id` / `client_secret` per provider live in the
35
30
  * Secrets Manager placeholder VentureKit provisions when
36
31
  * `AuthIntent.federated` is set; the ARN is exposed as
37
32
  * `COGNITO_FEDERATED_<PROVIDER>_SECRET_ARN` on every Lambda.
38
33
  */
39
- import type { AuthServerConfig } from './config.js';
40
- import { type SignInResult } from './tokens.js';
41
- export type FederatedProvider = 'google' | 'facebook' | 'apple' | 'linkedin';
42
- /**
43
- * Verified federated profile — the shape every IdP normalizes to
44
- * after `exchangeAuthorizationCode` runs.
45
- */
46
- export interface FederatedProfile {
47
- /** Stable identifier from the IdP. Google `sub`, Facebook `id`. */
48
- externalId: string;
49
- /** Verified email. Required — Cognito uses email as the username. */
50
- email: string;
51
- /** Optional display name, passed through to Cognito's `name` attr. */
52
- name?: string;
53
- }
54
- export interface FederatedProviderCredentials {
55
- clientId: string;
56
- clientSecret: string;
57
- }
58
- /**
59
- * Read the OAuth client credentials for `provider`.
60
- *
61
- * Resolution order:
62
- * 1. **Env var override** — `COGNITO_FEDERATED_<PROVIDER>_CLIENT_ID`
63
- * and `COGNITO_FEDERATED_<PROVIDER>_CLIENT_SECRET`. Use this for
64
- * local `vk dev` testing so you don't need Secrets Manager.
65
- * 2. **Secrets Manager** — ARN from `COGNITO_FEDERATED_<PROVIDER>_SECRET_ARN`;
66
- * the secret value is JSON `{"clientId":"…","clientSecret":"…"}`.
67
- * This is the production path.
68
- *
69
- * Cached for the lifetime of the Lambda container.
70
- */
71
- export declare function loadFederatedProviderCredentials(provider: FederatedProvider, env?: NodeJS.ProcessEnv | Record<string, string | undefined>): Promise<FederatedProviderCredentials>;
72
- /** Test-only — drop the cached credentials between vitest runs. */
73
- export declare function _resetFederatedCredentialsForTesting(): void;
74
- /**
75
- * Generate a 32-byte URL-safe random string used as the OAuth `state`
76
- * parameter. The same value is returned to the SPA (so it can be
77
- * appended to `authorizeUrl`) and pinned to the user's browser via an
78
- * HttpOnly cookie. {@link verifyOAuthState} performs a constant-time
79
- * comparison on the callback.
80
- */
81
- export declare function generateOAuthState(): string;
82
- /**
83
- * Constant-time equality check between the `state` echoed back by the
84
- * IdP and the value that was set on the state cookie at `start` time.
85
- * Returns `false` for any mismatch including length differences.
86
- */
87
- export declare function verifyOAuthState(fromQuery: string | undefined, fromCookie: string | undefined): boolean;
88
- export interface BuildAuthorizeUrlInput {
89
- provider: FederatedProvider;
90
- /**
91
- * Where the IdP should redirect after auth. Must be a page on your
92
- * SPA and must be registered as an allowed redirect URI in the IdP
93
- * console — Google / Facebook reject mismatches.
94
- */
95
- redirectUri: string;
96
- /** Output of {@link generateOAuthState}. */
97
- state: string;
98
- /** Override default scopes if you need extra IdP permissions. */
99
- scopes?: string[];
100
- /**
101
- * Extra query parameters appended verbatim. Useful for
102
- * `prompt=select_account` (Google) or `auth_type=rerequest`
103
- * (Facebook re-consent).
104
- */
105
- extraParams?: Record<string, string>;
106
- }
107
- /**
108
- * Build the IdP authorize URL the SPA navigates to after `start`.
109
- *
110
- * Loads the OAuth `client_id` from Secrets Manager (cached). The
111
- * `client_secret` is NOT used here — it's only needed at token
112
- * exchange.
113
- */
114
- export declare function buildAuthorizeUrl(input: BuildAuthorizeUrlInput, env?: NodeJS.ProcessEnv | Record<string, string | undefined>): Promise<string>;
115
- export interface ExchangeAuthorizationCodeInput {
116
- provider: FederatedProvider;
117
- /** The `code` query param the IdP appended to `redirectUri`. */
118
- code: string;
119
- /**
120
- * Must match the `redirectUri` used in `buildAuthorizeUrl`. Both
121
- * Google and Facebook compare these byte-for-byte and 400 on a
122
- * mismatch.
123
- */
124
- redirectUri: string;
125
- }
126
- /**
127
- * Exchange an OAuth `code` for tokens at the IdP, then resolve the
128
- * verified `FederatedProfile`. Throws {@link AuthError}
129
- * (`federated_token_invalid`, HTTP 401) on any IdP error.
130
- */
131
- export declare function exchangeAuthorizationCode(input: ExchangeAuthorizationCodeInput, env?: NodeJS.ProcessEnv | Record<string, string | undefined>): Promise<FederatedProfile>;
132
- /**
133
- * What to do when the IdP-verified email already belongs to a Cognito
134
- * user that was NOT created by a federated sign-in — i.e. someone who
135
- * registered with a password.
136
- *
137
- * Minting a session for that account requires `ADMIN_USER_PASSWORD_AUTH`,
138
- * and Cognito offers no admin API to authenticate a user without knowing
139
- * a password, so the only way in is to SET one — which silently replaces
140
- * the password the user chose. That is the trade-off this option makes
141
- * explicit:
142
- *
143
- * - `'link'` — replace the password, stamp `custom:federated_provider`
144
- * and sign in. The account is now federation-managed; the old
145
- * password no longer works (the user can `forgot-password` to set a
146
- * new one). The result carries `accountLinked: true` so the app can
147
- * tell the user what just happened (send a "your account is now
148
- * linked to Google" email — do not skip this).
149
- * - `'reject'` — throw `AuthError('federated_account_exists', …, 409)`
150
- * and leave the account untouched. The app then asks the user to
151
- * sign in with their password and link the provider from a
152
- * settings page. The safer default for products where a password
153
- * account is the primary identity.
154
- */
155
- export type ExistingPasswordAccountPolicy = 'link' | 'reject';
156
- export interface SignInAsFederatedUserInput {
157
- /** Verified profile from {@link exchangeAuthorizationCode}. */
158
- profile: FederatedProfile;
159
- /** Provider name — recorded as `custom:federated_provider`. */
160
- provider: FederatedProvider;
161
- /**
162
- * Standard Cognito attributes to set on first creation only — e.g.
163
- * `{ phone_number: '+212…' }`. Ignored for existing users.
164
- */
165
- initialAttributes?: Record<string, string>;
166
- /**
167
- * Custom attributes to set on first creation only — keyed without
168
- * the `custom:` prefix (the helper prepends it).
169
- */
170
- initialCustomAttributes?: Record<string, string>;
171
- /**
172
- * Policy for an existing PASSWORD account with this email — see
173
- * {@link ExistingPasswordAccountPolicy}. Default `'link'` (the
174
- * historical behaviour); pass `'reject'` to never rotate a
175
- * user-chosen password from a federated sign-in.
176
- */
177
- onExistingPasswordAccount?: ExistingPasswordAccountPolicy;
178
- }
179
- /**
180
- * {@link SignInResult} plus what the sign-in did to the account.
181
- */
182
- export interface FederatedSignInResult extends SignInResult {
183
- /**
184
- * `true` when this call converted an existing PASSWORD account into a
185
- * federation-managed one (`onExistingPasswordAccount: 'link'`): the
186
- * user's own password was replaced. Tell them.
187
- */
188
- accountLinked: boolean;
189
- /** `true` when the Cognito user was created by this call. */
190
- created: boolean;
191
- }
192
- /**
193
- * Sign a verified federated user in. Creates the Cognito user on
194
- * first contact (idempotent), rotates the server-side password of
195
- * federation-managed accounts, and mints session tokens via
196
- * `ADMIN_USER_PASSWORD_AUTH`.
197
- *
198
- * Accounts are federation-managed when they carry
199
- * `custom:federated_provider` — set on creation here, or when an existing
200
- * password account is linked (see {@link ExistingPasswordAccountPolicy}).
201
- * Nobody knows a federation-managed account's password (it is random and
202
- * replaced on every sign-in), so rotating it costs the user nothing. A
203
- * PASSWORD account is different: rotating destroys a credential the user
204
- * chose, so that case is governed by `onExistingPasswordAccount`.
205
- *
206
- * Returns the {@link SignInResult} shape `signInWithPassword` returns
207
- * (so cookie / session helpers stay identical) plus `accountLinked` /
208
- * `created` flags.
209
- */
210
- export declare function signInAsFederatedUser(input: SignInAsFederatedUserInput, config?: AuthServerConfig): Promise<FederatedSignInResult>;
211
- /**
212
- * Generate a 32-char password that satisfies the strongest password
213
- * policy VentureKit ships (`passwordStrength: 'strong'` — 12+ chars,
214
- * upper, lower, digit, symbol). Shared with the invitations flow.
215
- */
216
- export declare function generateStrongPassword(): string;
34
+ export type { FederatedEnv, FederatedProfile, FederatedProvider, FederatedProviderCredentials, } from './federated/types.js';
35
+ export { loadFederatedProviderCredentials, _resetFederatedCredentialsForTesting } from './federated/credentials.js';
36
+ export { PROVIDERS as FEDERATED_PROVIDERS, providerDescriptor } from './federated/providers.js';
37
+ export type { ProviderDescriptor } from './federated/providers.js';
38
+ export { createOAuthTransaction, generateOAuthState, parseOAuthTransaction, pkceChallenge, serializeOAuthTransaction, verifyOAuthState, verifyOAuthTransaction, } from './federated/oauth-transaction.js';
39
+ export type { OAuthTransaction } from './federated/oauth-transaction.js';
40
+ export { buildAuthorizeUrl, exchangeAuthorizationCode, validateIdTokenClaims } from './federated/authorization.js';
41
+ export type { BuildAuthorizeUrlInput, ExchangeAuthorizationCodeInput, IdTokenExpectations, } from './federated/authorization.js';
42
+ export { decideFederatedSignIn, federatedSubjectAttribute } from './federated/account-linking.js';
43
+ export type { ExistingFederatedAccount, ExistingPasswordAccountPolicy, FederatedRejectionCode, FederatedSignInDecision, } from './federated/account-linking.js';
44
+ export { generateStrongPassword, signInAsFederatedUser } from './federated/sign-in.js';
45
+ export type { FederatedSignInResult, SignInAsFederatedUserInput } from './federated/sign-in.js';
217
46
  //# sourceMappingURL=federated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"federated.d.ts","sourceRoot":"","sources":["../../src/server/federated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAYH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKpD,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAE7E;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAsB,gCAAgC,CACpD,QAAQ,EAAE,iBAAiB,EAC3B,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACxE,OAAO,CAAC,4BA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