@venturekit/auth 0.0.50 → 0.0.51
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/README.md +8 -7
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
- package/dist/server/api-keys.d.ts +10 -5
- package/dist/server/api-keys.d.ts.map +1 -1
- package/dist/server/api-keys.js +24 -8
- package/dist/server/api-keys.js.map +1 -1
- package/dist/server/config.d.ts +6 -0
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/config.js +2 -0
- package/dist/server/config.js.map +1 -1
- package/dist/server/cookies.d.ts +9 -5
- package/dist/server/cookies.d.ts.map +1 -1
- package/dist/server/cookies.js +19 -6
- package/dist/server/cookies.js.map +1 -1
- package/dist/server/errors.d.ts +18 -2
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +46 -3
- package/dist/server/errors.js.map +1 -1
- package/dist/server/federated/account-linking.d.ts +90 -0
- package/dist/server/federated/account-linking.d.ts.map +1 -0
- package/dist/server/federated/account-linking.js +78 -0
- package/dist/server/federated/account-linking.js.map +1 -0
- package/dist/server/federated/authorization.d.ts +81 -0
- package/dist/server/federated/authorization.d.ts.map +1 -0
- package/dist/server/federated/authorization.js +229 -0
- package/dist/server/federated/authorization.js.map +1 -0
- package/dist/server/federated/credentials.d.ts +22 -0
- package/dist/server/federated/credentials.d.ts.map +1 -0
- package/dist/server/federated/credentials.js +81 -0
- package/dist/server/federated/credentials.js.map +1 -0
- package/dist/server/federated/oauth-transaction.d.ts +54 -0
- package/dist/server/federated/oauth-transaction.d.ts.map +1 -0
- package/dist/server/federated/oauth-transaction.js +92 -0
- package/dist/server/federated/oauth-transaction.js.map +1 -0
- package/dist/server/federated/providers.d.ts +34 -0
- package/dist/server/federated/providers.d.ts.map +1 -0
- package/dist/server/federated/providers.js +65 -0
- package/dist/server/federated/providers.js.map +1 -0
- package/dist/server/federated/sign-in.d.ts +81 -0
- package/dist/server/federated/sign-in.d.ts.map +1 -0
- package/dist/server/federated/sign-in.js +180 -0
- package/dist/server/federated/sign-in.js.map +1 -0
- package/dist/server/federated/types.d.ts +36 -0
- package/dist/server/federated/types.d.ts.map +1 -0
- package/dist/server/federated/types.js +5 -0
- package/dist/server/federated/types.js.map +1 -0
- package/dist/server/federated-routes.d.ts +15 -7
- package/dist/server/federated-routes.d.ts.map +1 -1
- package/dist/server/federated-routes.js +27 -16
- package/dist/server/federated-routes.js.map +1 -1
- package/dist/server/federated.d.ts +25 -196
- package/dist/server/federated.d.ts.map +1 -1
- package/dist/server/federated.js +19 -521
- package/dist/server/federated.js.map +1 -1
- package/dist/server/forgot-password.d.ts +4 -3
- package/dist/server/forgot-password.d.ts.map +1 -1
- package/dist/server/forgot-password.js +3 -5
- package/dist/server/forgot-password.js.map +1 -1
- package/dist/server/handoff-routes.d.ts +16 -5
- package/dist/server/handoff-routes.d.ts.map +1 -1
- package/dist/server/handoff-routes.js +23 -11
- package/dist/server/handoff-routes.js.map +1 -1
- package/dist/server/impersonation.d.ts +6 -3
- package/dist/server/impersonation.d.ts.map +1 -1
- package/dist/server/impersonation.js +11 -5
- package/dist/server/impersonation.js.map +1 -1
- package/dist/server/index.d.ts +5 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/invitations.d.ts +6 -2
- package/dist/server/invitations.d.ts.map +1 -1
- package/dist/server/invitations.js +6 -3
- package/dist/server/invitations.js.map +1 -1
- package/dist/server/local-cognito.d.ts +19 -0
- package/dist/server/local-cognito.d.ts.map +1 -0
- package/dist/server/local-cognito.js +19 -0
- package/dist/server/local-cognito.js.map +1 -0
- package/dist/server/refresh.d.ts +23 -12
- package/dist/server/refresh.d.ts.map +1 -1
- package/dist/server/refresh.js +35 -19
- package/dist/server/refresh.js.map +1 -1
- package/dist/server/resource-scope.d.ts +19 -0
- package/dist/server/resource-scope.d.ts.map +1 -0
- package/dist/server/resource-scope.js +2 -0
- package/dist/server/resource-scope.js.map +1 -0
- package/dist/server/route-rate-limit.d.ts +50 -0
- package/dist/server/route-rate-limit.d.ts.map +1 -0
- package/dist/server/route-rate-limit.js +39 -0
- package/dist/server/route-rate-limit.js.map +1 -0
- package/dist/server/session-routes.d.ts +9 -2
- package/dist/server/session-routes.d.ts.map +1 -1
- package/dist/server/session-routes.js +6 -4
- package/dist/server/session-routes.js.map +1 -1
- package/dist/server/sign-up.d.ts +32 -17
- package/dist/server/sign-up.d.ts.map +1 -1
- package/dist/server/sign-up.js +30 -12
- package/dist/server/sign-up.js.map +1 -1
- package/dist/server/store/postgres.d.ts.map +1 -1
- package/dist/server/store/postgres.js +43 -27
- package/dist/server/store/postgres.js.map +1 -1
- package/dist/server/verification.d.ts +76 -33
- package/dist/server/verification.d.ts.map +1 -1
- package/dist/server/verification.js +68 -67
- package/dist/server/verification.js.map +1 -1
- package/dist/server/verify.d.ts.map +1 -1
- package/dist/server/verify.js +8 -3
- package/dist/server/verify.js.map +1 -1
- package/dist/session/index.d.ts +11 -13
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +13 -14
- package/dist/session/index.js.map +1 -1
- package/package.json +6 -6
- package/src/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
package/dist/server/federated.js
CHANGED
|
@@ -6,537 +6,35 @@
|
|
|
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
|
|
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
|
-
*
|
|
14
|
-
*
|
|
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** —
|
|
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
|
-
* -
|
|
22
|
-
* -
|
|
23
|
-
* {@link exchangeAuthorizationCode}
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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
|
|
32
|
-
*
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
import { extractSignInTokens } from './tokens.js';
|
|
46
|
-
// ────────────────────────────────────────────────────────────────────
|
|
47
|
-
// Provider-credential resolution (Secrets Manager → cached)
|
|
48
|
-
// ────────────────────────────────────────────────────────────────────
|
|
49
|
-
const credentialsCache = new Map();
|
|
50
|
-
/**
|
|
51
|
-
* Read the OAuth client credentials for `provider`.
|
|
52
|
-
*
|
|
53
|
-
* Resolution order:
|
|
54
|
-
* 1. **Env var override** — `COGNITO_FEDERATED_<PROVIDER>_CLIENT_ID`
|
|
55
|
-
* and `COGNITO_FEDERATED_<PROVIDER>_CLIENT_SECRET`. Use this for
|
|
56
|
-
* local `vk dev` testing so you don't need Secrets Manager.
|
|
57
|
-
* 2. **Secrets Manager** — ARN from `COGNITO_FEDERATED_<PROVIDER>_SECRET_ARN`;
|
|
58
|
-
* the secret value is JSON `{"clientId":"…","clientSecret":"…"}`.
|
|
59
|
-
* This is the production path.
|
|
60
|
-
*
|
|
61
|
-
* Cached for the lifetime of the Lambda container.
|
|
62
|
-
*/
|
|
63
|
-
export async function loadFederatedProviderCredentials(provider, env = process.env) {
|
|
64
|
-
const cached = credentialsCache.get(provider);
|
|
65
|
-
if (cached)
|
|
66
|
-
return cached;
|
|
67
|
-
// Dev mode shortcut — read credentials directly from env vars so you
|
|
68
|
-
// don't need Secrets Manager for local `vk dev` testing.
|
|
69
|
-
const clientIdVar = `COGNITO_FEDERATED_${provider.toUpperCase()}_CLIENT_ID`;
|
|
70
|
-
const clientSecretVar = `COGNITO_FEDERATED_${provider.toUpperCase()}_CLIENT_SECRET`;
|
|
71
|
-
const devClientId = env[clientIdVar];
|
|
72
|
-
const devClientSecret = env[clientSecretVar];
|
|
73
|
-
if (devClientId && devClientSecret) {
|
|
74
|
-
const creds = {
|
|
75
|
-
clientId: devClientId,
|
|
76
|
-
clientSecret: devClientSecret,
|
|
77
|
-
};
|
|
78
|
-
credentialsCache.set(provider, creds);
|
|
79
|
-
return creds;
|
|
80
|
-
}
|
|
81
|
-
const envVar = `COGNITO_FEDERATED_${provider.toUpperCase()}_SECRET_ARN`;
|
|
82
|
-
const arn = env[envVar];
|
|
83
|
-
if (!arn) {
|
|
84
|
-
throw new AuthError('federated_provider_not_configured', `[${provider}] missing env var ${envVar} — declare ` +
|
|
85
|
-
`\`federated: ['${provider}']\` on the auth intent in vk.config.ts ` +
|
|
86
|
-
`so VentureKit provisions the Secrets Manager placeholder, then ` +
|
|
87
|
-
`populate it with the OAuth client credentials from the IdP console.`, 500);
|
|
88
|
-
}
|
|
89
|
-
const { SecretsManagerClient, GetSecretValueCommand } = await import('@aws-sdk/client-secrets-manager');
|
|
90
|
-
const client = new SecretsManagerClient({
|
|
91
|
-
region: env['AWS_REGION'] ?? env['COGNITO_REGION'],
|
|
92
|
-
});
|
|
93
|
-
const res = await client.send(new GetSecretValueCommand({ SecretId: arn }));
|
|
94
|
-
if (!res.SecretString) {
|
|
95
|
-
throw new AuthError('federated_provider_not_configured', `[${provider}] Secrets Manager entry ${arn} is empty`, 500);
|
|
96
|
-
}
|
|
97
|
-
let parsed;
|
|
98
|
-
try {
|
|
99
|
-
parsed = JSON.parse(res.SecretString);
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
throw new AuthError('federated_provider_not_configured', `[${provider}] Secrets Manager entry ${arn} is not valid JSON`, 500);
|
|
103
|
-
}
|
|
104
|
-
if (!parsed.clientId ||
|
|
105
|
-
!parsed.clientSecret ||
|
|
106
|
-
parsed.clientId === 'PLACEHOLDER' ||
|
|
107
|
-
parsed.clientSecret === 'PLACEHOLDER') {
|
|
108
|
-
throw new AuthError('federated_provider_not_configured', `[${provider}] Secrets Manager entry ${arn} still holds the ` +
|
|
109
|
-
`placeholder. Populate it with the OAuth client id + secret ` +
|
|
110
|
-
`from the IdP console: aws secretsmanager put-secret-value ` +
|
|
111
|
-
`--secret-id ${arn} --secret-string '{"clientId":"…","clientSecret":"…"}'`, 500);
|
|
112
|
-
}
|
|
113
|
-
const creds = {
|
|
114
|
-
clientId: parsed.clientId,
|
|
115
|
-
clientSecret: parsed.clientSecret,
|
|
116
|
-
};
|
|
117
|
-
credentialsCache.set(provider, creds);
|
|
118
|
-
return creds;
|
|
119
|
-
}
|
|
120
|
-
/** Test-only — drop the cached credentials between vitest runs. */
|
|
121
|
-
export function _resetFederatedCredentialsForTesting() {
|
|
122
|
-
credentialsCache.clear();
|
|
123
|
-
}
|
|
124
|
-
// ────────────────────────────────────────────────────────────────────
|
|
125
|
-
// CSRF state — random token, signed cookie
|
|
126
|
-
// ────────────────────────────────────────────────────────────────────
|
|
127
|
-
/**
|
|
128
|
-
* Generate a 32-byte URL-safe random string used as the OAuth `state`
|
|
129
|
-
* parameter. The same value is returned to the SPA (so it can be
|
|
130
|
-
* appended to `authorizeUrl`) and pinned to the user's browser via an
|
|
131
|
-
* HttpOnly cookie. {@link verifyOAuthState} performs a constant-time
|
|
132
|
-
* comparison on the callback.
|
|
133
|
-
*/
|
|
134
|
-
export function generateOAuthState() {
|
|
135
|
-
return randomBytes(32).toString('base64url');
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Constant-time equality check between the `state` echoed back by the
|
|
139
|
-
* IdP and the value that was set on the state cookie at `start` time.
|
|
140
|
-
* Returns `false` for any mismatch including length differences.
|
|
141
|
-
*/
|
|
142
|
-
export function verifyOAuthState(fromQuery, fromCookie) {
|
|
143
|
-
if (!fromQuery || !fromCookie)
|
|
144
|
-
return false;
|
|
145
|
-
const a = Buffer.from(fromQuery);
|
|
146
|
-
const b = Buffer.from(fromCookie);
|
|
147
|
-
if (a.length !== b.length)
|
|
148
|
-
return false;
|
|
149
|
-
return timingSafeEqual(a, b);
|
|
150
|
-
}
|
|
151
|
-
const PROVIDER_ENDPOINTS = {
|
|
152
|
-
google: {
|
|
153
|
-
authorize: 'https://accounts.google.com/o/oauth2/v2/auth',
|
|
154
|
-
token: 'https://oauth2.googleapis.com/token',
|
|
155
|
-
// `openid email profile` returns an `id_token` (JWT) we can decode
|
|
156
|
-
// for the verified profile without a second `/userinfo` call.
|
|
157
|
-
defaultScopes: ['openid', 'email', 'profile'],
|
|
158
|
-
},
|
|
159
|
-
facebook: {
|
|
160
|
-
authorize: 'https://www.facebook.com/v18.0/dialog/oauth',
|
|
161
|
-
token: 'https://graph.facebook.com/v18.0/oauth/access_token',
|
|
162
|
-
// `email` is required to read the address; `public_profile` is
|
|
163
|
-
// implicit but listing it makes the consent screen explicit.
|
|
164
|
-
defaultScopes: ['email', 'public_profile'],
|
|
165
|
-
},
|
|
166
|
-
apple: {
|
|
167
|
-
authorize: 'https://appleid.apple.com/auth/authorize',
|
|
168
|
-
token: 'https://appleid.apple.com/auth/token',
|
|
169
|
-
// Apple wants `name email`; `response_mode=form_post` is required
|
|
170
|
-
// when scopes include `name`/`email` — callers should set it.
|
|
171
|
-
defaultScopes: ['name', 'email'],
|
|
172
|
-
},
|
|
173
|
-
linkedin: {
|
|
174
|
-
// LinkedIn implements OpenID Connect since 2023 — use `openid`
|
|
175
|
-
// scopes to receive an id_token directly at the token endpoint
|
|
176
|
-
// (no follow-up `/userinfo` call needed). The discovery doc lives
|
|
177
|
-
// at `https://www.linkedin.com/oauth/.well-known/openid-configuration`.
|
|
178
|
-
authorize: 'https://www.linkedin.com/oauth/v2/authorization',
|
|
179
|
-
token: 'https://www.linkedin.com/oauth/v2/accessToken',
|
|
180
|
-
// `openid email profile` returns an `id_token` (JWT) carrying
|
|
181
|
-
// `sub` (member ID), `email`, `email_verified`, and `name`.
|
|
182
|
-
defaultScopes: ['openid', 'profile', 'email'],
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* Build the IdP authorize URL the SPA navigates to after `start`.
|
|
187
|
-
*
|
|
188
|
-
* Loads the OAuth `client_id` from Secrets Manager (cached). The
|
|
189
|
-
* `client_secret` is NOT used here — it's only needed at token
|
|
190
|
-
* exchange.
|
|
191
|
-
*/
|
|
192
|
-
export async function buildAuthorizeUrl(input, env = process.env) {
|
|
193
|
-
const { provider, redirectUri, state, scopes, extraParams } = input;
|
|
194
|
-
const { clientId } = await loadFederatedProviderCredentials(provider, env);
|
|
195
|
-
const endpoints = PROVIDER_ENDPOINTS[provider];
|
|
196
|
-
const url = new URL(endpoints.authorize);
|
|
197
|
-
url.searchParams.set('response_type', 'code');
|
|
198
|
-
url.searchParams.set('client_id', clientId);
|
|
199
|
-
url.searchParams.set('redirect_uri', redirectUri);
|
|
200
|
-
url.searchParams.set('scope', (scopes ?? endpoints.defaultScopes).join(' '));
|
|
201
|
-
url.searchParams.set('state', state);
|
|
202
|
-
for (const [k, v] of Object.entries(extraParams ?? {})) {
|
|
203
|
-
url.searchParams.set(k, v);
|
|
204
|
-
}
|
|
205
|
-
return url.toString();
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Exchange an OAuth `code` for tokens at the IdP, then resolve the
|
|
209
|
-
* verified `FederatedProfile`. Throws {@link AuthError}
|
|
210
|
-
* (`federated_token_invalid`, HTTP 401) on any IdP error.
|
|
211
|
-
*/
|
|
212
|
-
export async function exchangeAuthorizationCode(input, env = process.env) {
|
|
213
|
-
const { provider, code, redirectUri } = input;
|
|
214
|
-
const { clientId, clientSecret } = await loadFederatedProviderCredentials(provider, env);
|
|
215
|
-
switch (provider) {
|
|
216
|
-
case 'google':
|
|
217
|
-
return exchangeGoogle(code, redirectUri, clientId, clientSecret);
|
|
218
|
-
case 'facebook':
|
|
219
|
-
return exchangeFacebook(code, redirectUri, clientId, clientSecret);
|
|
220
|
-
case 'linkedin':
|
|
221
|
-
return exchangeLinkedIn(code, redirectUri, clientId, clientSecret);
|
|
222
|
-
case 'apple':
|
|
223
|
-
throw new AuthError('federated_provider_not_configured', 'Sign in with Apple requires a JWT-signed client_secret rotated ' +
|
|
224
|
-
'every 6 months — implement the Apple-specific exchange in your ' +
|
|
225
|
-
'application until VentureKit ships a built-in helper.', 500);
|
|
226
|
-
default: {
|
|
227
|
-
const _exhaustive = provider;
|
|
228
|
-
void _exhaustive;
|
|
229
|
-
throw new AuthError('federated_provider_not_configured', `Unknown federated provider: ${String(provider)}`, 500);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
async function exchangeGoogle(code, redirectUri, clientId, clientSecret) {
|
|
234
|
-
// Google's token endpoint accepts application/x-www-form-urlencoded
|
|
235
|
-
// and returns `{ access_token, id_token, expires_in, ... }`. We only
|
|
236
|
-
// need the id_token: it's a signed JWT carrying `sub`, `email`,
|
|
237
|
-
// `email_verified`, `name`. Signature verification is unnecessary
|
|
238
|
-
// because we just received it from Google's TLS endpoint over a
|
|
239
|
-
// back-channel call we initiated — there's no way for an attacker
|
|
240
|
-
// to substitute it. (Per Google's docs:
|
|
241
|
-
// https://developers.google.com/identity/openid-connect/openid-connect#validatinganidtoken)
|
|
242
|
-
const body = new URLSearchParams({
|
|
243
|
-
code,
|
|
244
|
-
client_id: clientId,
|
|
245
|
-
client_secret: clientSecret,
|
|
246
|
-
redirect_uri: redirectUri,
|
|
247
|
-
grant_type: 'authorization_code',
|
|
248
|
-
});
|
|
249
|
-
const tokenRes = await fetch(PROVIDER_ENDPOINTS.google.token, {
|
|
250
|
-
method: 'POST',
|
|
251
|
-
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
252
|
-
body,
|
|
253
|
-
});
|
|
254
|
-
if (!tokenRes.ok) {
|
|
255
|
-
throw new AuthError('federated_token_invalid', `Google token exchange failed (HTTP ${tokenRes.status}): ` +
|
|
256
|
-
(await tokenRes.text().catch(() => '')), 401);
|
|
257
|
-
}
|
|
258
|
-
const tokenJson = (await tokenRes.json());
|
|
259
|
-
if (!tokenJson.id_token) {
|
|
260
|
-
throw new AuthError('federated_token_invalid', 'Google token exchange returned no id_token', 401);
|
|
261
|
-
}
|
|
262
|
-
const claims = decodeJwtPayload(tokenJson.id_token);
|
|
263
|
-
const sub = typeof claims['sub'] === 'string' ? claims['sub'] : null;
|
|
264
|
-
const email = typeof claims['email'] === 'string'
|
|
265
|
-
? claims['email'].toLowerCase()
|
|
266
|
-
: null;
|
|
267
|
-
const emailVerified = claims['email_verified'] === true;
|
|
268
|
-
if (!sub || !email || !emailVerified) {
|
|
269
|
-
throw new AuthError('federated_token_invalid', 'Google id_token missing required verified email claim', 401);
|
|
270
|
-
}
|
|
271
|
-
const name = typeof claims['name'] === 'string' ? claims['name'] : undefined;
|
|
272
|
-
return { externalId: sub, email, name };
|
|
273
|
-
}
|
|
274
|
-
async function exchangeFacebook(code, redirectUri, clientId, clientSecret) {
|
|
275
|
-
// Facebook's token endpoint accepts the same params as a GET. The
|
|
276
|
-
// response is `{ access_token, token_type, expires_in }`. There's
|
|
277
|
-
// no id_token, so we follow up with a Graph `/me` call.
|
|
278
|
-
const tokenUrl = new URL(PROVIDER_ENDPOINTS.facebook.token);
|
|
279
|
-
tokenUrl.searchParams.set('code', code);
|
|
280
|
-
tokenUrl.searchParams.set('client_id', clientId);
|
|
281
|
-
tokenUrl.searchParams.set('client_secret', clientSecret);
|
|
282
|
-
tokenUrl.searchParams.set('redirect_uri', redirectUri);
|
|
283
|
-
const tokenRes = await fetch(tokenUrl);
|
|
284
|
-
if (!tokenRes.ok) {
|
|
285
|
-
throw new AuthError('federated_token_invalid', `Facebook token exchange failed (HTTP ${tokenRes.status}): ` +
|
|
286
|
-
(await tokenRes.text().catch(() => '')), 401);
|
|
287
|
-
}
|
|
288
|
-
const tokenJson = (await tokenRes.json());
|
|
289
|
-
if (!tokenJson.access_token) {
|
|
290
|
-
throw new AuthError('federated_token_invalid', 'Facebook token exchange returned no access_token', 401);
|
|
291
|
-
}
|
|
292
|
-
// appsecret_proof = HMAC_SHA256(access_token, app_secret) — Meta
|
|
293
|
-
// requires it for sensitive scopes and recommends it for everything.
|
|
294
|
-
const proof = createHmac('sha256', clientSecret)
|
|
295
|
-
.update(tokenJson.access_token)
|
|
296
|
-
.digest('hex');
|
|
297
|
-
const meUrl = new URL('https://graph.facebook.com/v18.0/me');
|
|
298
|
-
meUrl.searchParams.set('fields', 'id,email,name');
|
|
299
|
-
meUrl.searchParams.set('access_token', tokenJson.access_token);
|
|
300
|
-
meUrl.searchParams.set('appsecret_proof', proof);
|
|
301
|
-
const meRes = await fetch(meUrl);
|
|
302
|
-
if (!meRes.ok) {
|
|
303
|
-
throw new AuthError('federated_token_invalid', `Facebook /me failed (HTTP ${meRes.status})`, 401);
|
|
304
|
-
}
|
|
305
|
-
const me = (await meRes.json());
|
|
306
|
-
if (!me.id || !me.email) {
|
|
307
|
-
throw new AuthError('federated_token_invalid', 'Facebook profile missing id or email — request the `email` scope.', 401);
|
|
308
|
-
}
|
|
309
|
-
return {
|
|
310
|
-
externalId: me.id,
|
|
311
|
-
email: me.email.toLowerCase(),
|
|
312
|
-
name: me.name,
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
async function exchangeLinkedIn(code, redirectUri, clientId, clientSecret) {
|
|
316
|
-
// LinkedIn's token endpoint accepts application/x-www-form-urlencoded
|
|
317
|
-
// and returns `{ access_token, expires_in, scope, id_token }`. With
|
|
318
|
-
// `openid` in the requested scopes the id_token is a signed JWT
|
|
319
|
-
// carrying `sub` (the stable LinkedIn member ID, NOT the email),
|
|
320
|
-
// `email`, `email_verified`, and `name`. Same signature-verification
|
|
321
|
-
// reasoning as Google: the JWT just arrived over TLS from the IdP's
|
|
322
|
-
// own token endpoint via a back-channel call we initiated, so an
|
|
323
|
-
// attacker can't substitute it.
|
|
324
|
-
const body = new URLSearchParams({
|
|
325
|
-
code,
|
|
326
|
-
client_id: clientId,
|
|
327
|
-
client_secret: clientSecret,
|
|
328
|
-
redirect_uri: redirectUri,
|
|
329
|
-
grant_type: 'authorization_code',
|
|
330
|
-
});
|
|
331
|
-
const tokenRes = await fetch(PROVIDER_ENDPOINTS.linkedin.token, {
|
|
332
|
-
method: 'POST',
|
|
333
|
-
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
334
|
-
body,
|
|
335
|
-
});
|
|
336
|
-
if (!tokenRes.ok) {
|
|
337
|
-
throw new AuthError('federated_token_invalid', `LinkedIn token exchange failed (HTTP ${tokenRes.status}): ` +
|
|
338
|
-
(await tokenRes.text().catch(() => '')), 401);
|
|
339
|
-
}
|
|
340
|
-
const tokenJson = (await tokenRes.json());
|
|
341
|
-
if (!tokenJson.id_token) {
|
|
342
|
-
throw new AuthError('federated_token_invalid', 'LinkedIn token exchange returned no id_token — make sure the ' +
|
|
343
|
-
'`openid` scope is requested and the app has the "Sign In with ' +
|
|
344
|
-
'LinkedIn using OpenID Connect" product enabled.', 401);
|
|
345
|
-
}
|
|
346
|
-
const claims = decodeJwtPayload(tokenJson.id_token);
|
|
347
|
-
const sub = typeof claims['sub'] === 'string' ? claims['sub'] : null;
|
|
348
|
-
const email = typeof claims['email'] === 'string'
|
|
349
|
-
? claims['email'].toLowerCase()
|
|
350
|
-
: null;
|
|
351
|
-
// LinkedIn populates `email_verified` as either a boolean `true`
|
|
352
|
-
// or the string `"true"` depending on the token version.
|
|
353
|
-
const emailVerified = claims['email_verified'] === true || claims['email_verified'] === 'true';
|
|
354
|
-
if (!sub || !email || !emailVerified) {
|
|
355
|
-
throw new AuthError('federated_token_invalid', 'LinkedIn id_token missing required verified email claim — request ' +
|
|
356
|
-
'the `email` scope on the authorize URL.', 401);
|
|
357
|
-
}
|
|
358
|
-
const name = typeof claims['name'] === 'string' ? claims['name'] : undefined;
|
|
359
|
-
const profile = { externalId: sub, email, name };
|
|
360
|
-
return profile;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Decode a JWT payload **without** verifying the signature — safe here
|
|
364
|
-
* because the caller just fetched the token over TLS from the IdP's
|
|
365
|
-
* own token endpoint. Thin throwing wrapper over the shared
|
|
366
|
-
* `decodeJwtClaims` (token-utils.ts).
|
|
367
|
-
*/
|
|
368
|
-
function decodeJwtPayload(jwt) {
|
|
369
|
-
const claims = decodeJwtClaims(jwt);
|
|
370
|
-
if (!claims) {
|
|
371
|
-
throw new AuthError('federated_token_invalid', 'Malformed JWT', 401);
|
|
372
|
-
}
|
|
373
|
-
return claims;
|
|
374
|
-
}
|
|
375
|
-
/** `custom:federated_provider` — set on every account this module creates or links. */
|
|
376
|
-
const FEDERATED_PROVIDER_ATTRIBUTE = 'custom:federated_provider';
|
|
377
|
-
/**
|
|
378
|
-
* Sign a verified federated user in. Creates the Cognito user on
|
|
379
|
-
* first contact (idempotent), rotates the server-side password of
|
|
380
|
-
* federation-managed accounts, and mints session tokens via
|
|
381
|
-
* `ADMIN_USER_PASSWORD_AUTH`.
|
|
382
|
-
*
|
|
383
|
-
* Accounts are federation-managed when they carry
|
|
384
|
-
* `custom:federated_provider` — set on creation here, or when an existing
|
|
385
|
-
* password account is linked (see {@link ExistingPasswordAccountPolicy}).
|
|
386
|
-
* Nobody knows a federation-managed account's password (it is random and
|
|
387
|
-
* replaced on every sign-in), so rotating it costs the user nothing. A
|
|
388
|
-
* PASSWORD account is different: rotating destroys a credential the user
|
|
389
|
-
* chose, so that case is governed by `onExistingPasswordAccount`.
|
|
390
|
-
*
|
|
391
|
-
* Returns the {@link SignInResult} shape `signInWithPassword` returns
|
|
392
|
-
* (so cookie / session helpers stay identical) plus `accountLinked` /
|
|
393
|
-
* `created` flags.
|
|
394
|
-
*/
|
|
395
|
-
export async function signInAsFederatedUser(input, config = loadAuthServerConfig()) {
|
|
396
|
-
const client = getCognitoClient(config.region, config.endpoint);
|
|
397
|
-
const email = input.profile.email.toLowerCase();
|
|
398
|
-
const policy = input.onExistingPasswordAccount ?? 'link';
|
|
399
|
-
// Generate a strong server-side password every sign-in so even if
|
|
400
|
-
// the value were ever exfiltrated it'd already be replaced. The
|
|
401
|
-
// user never sees this password — federated sign-in never exposes
|
|
402
|
-
// it; password sign-in for the same account is still possible
|
|
403
|
-
// after a `forgot-password` flow.
|
|
404
|
-
const password = generateStrongPassword();
|
|
405
|
-
let userExists;
|
|
406
|
-
let federationManaged = false;
|
|
407
|
-
try {
|
|
408
|
-
const existing = await client.send(new AdminGetUserCommand({
|
|
409
|
-
UserPoolId: config.userPoolId,
|
|
410
|
-
Username: email,
|
|
411
|
-
}));
|
|
412
|
-
userExists = true;
|
|
413
|
-
federationManaged = (existing.UserAttributes ?? []).some((a) => a.Name === FEDERATED_PROVIDER_ATTRIBUTE && Boolean(a.Value));
|
|
414
|
-
}
|
|
415
|
-
catch (err) {
|
|
416
|
-
if (err.name === 'UserNotFoundException') {
|
|
417
|
-
userExists = false;
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
throw mapProviderError(err, 'federated_signin_failed');
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
const linkingPasswordAccount = userExists && !federationManaged;
|
|
424
|
-
if (linkingPasswordAccount && policy === 'reject') {
|
|
425
|
-
throw new AuthError('federated_account_exists', 'An account with this email already signs in with a password. Sign in with ' +
|
|
426
|
-
'your password and link the provider from your account settings.', 409);
|
|
427
|
-
}
|
|
428
|
-
if (!userExists) {
|
|
429
|
-
const attrs = [
|
|
430
|
-
{ Name: 'email', Value: email },
|
|
431
|
-
{ Name: 'email_verified', Value: 'true' },
|
|
432
|
-
];
|
|
433
|
-
if (input.profile.name) {
|
|
434
|
-
attrs.push({ Name: 'name', Value: input.profile.name });
|
|
435
|
-
}
|
|
436
|
-
for (const [k, v] of Object.entries(input.initialAttributes ?? {})) {
|
|
437
|
-
if (k === 'email' || k === 'email_verified' || k === 'name')
|
|
438
|
-
continue;
|
|
439
|
-
attrs.push({ Name: k, Value: v });
|
|
440
|
-
}
|
|
441
|
-
attrs.push({
|
|
442
|
-
Name: FEDERATED_PROVIDER_ATTRIBUTE,
|
|
443
|
-
Value: input.provider,
|
|
444
|
-
});
|
|
445
|
-
for (const [k, v] of Object.entries(input.initialCustomAttributes ?? {})) {
|
|
446
|
-
attrs.push({ Name: `custom:${k}`, Value: v });
|
|
447
|
-
}
|
|
448
|
-
try {
|
|
449
|
-
await client.send(new AdminCreateUserCommand({
|
|
450
|
-
UserPoolId: config.userPoolId,
|
|
451
|
-
Username: email,
|
|
452
|
-
UserAttributes: attrs,
|
|
453
|
-
// Suppress the welcome email — the user just authenticated
|
|
454
|
-
// through the IdP, they don't need a Cognito-generated one.
|
|
455
|
-
MessageAction: 'SUPPRESS',
|
|
456
|
-
TemporaryPassword: password,
|
|
457
|
-
}));
|
|
458
|
-
}
|
|
459
|
-
catch (err) {
|
|
460
|
-
// `UsernameExistsException` here is a race between two parallel
|
|
461
|
-
// federated sign-ins for the same email — fall through to the
|
|
462
|
-
// password reset + auth path; both will succeed.
|
|
463
|
-
if (err.name !== 'UsernameExistsException') {
|
|
464
|
-
throw mapProviderError(err, 'federated_signin_failed');
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
else {
|
|
469
|
-
// Existing user — make sure email is marked verified (older
|
|
470
|
-
// password-only signups may have `email_verified=false` if the
|
|
471
|
-
// confirmation email was never clicked) so `AdminInitiateAuth`
|
|
472
|
-
// doesn't raise a verification challenge. A password account being
|
|
473
|
-
// LINKED also gets the provider stamp, so from now on it is
|
|
474
|
-
// federation-managed and later sign-ins never hit this branch's
|
|
475
|
-
// policy check again.
|
|
476
|
-
try {
|
|
477
|
-
await client.send(new AdminUpdateUserAttributesCommand({
|
|
478
|
-
UserPoolId: config.userPoolId,
|
|
479
|
-
Username: email,
|
|
480
|
-
UserAttributes: [
|
|
481
|
-
{ Name: 'email', Value: email },
|
|
482
|
-
{ Name: 'email_verified', Value: 'true' },
|
|
483
|
-
...(linkingPasswordAccount
|
|
484
|
-
? [{ Name: FEDERATED_PROVIDER_ATTRIBUTE, Value: input.provider }]
|
|
485
|
-
: []),
|
|
486
|
-
],
|
|
487
|
-
}));
|
|
488
|
-
}
|
|
489
|
-
catch (err) {
|
|
490
|
-
throw mapProviderError(err, 'federated_signin_failed');
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
// Set a fresh permanent password whether the user is new (the
|
|
494
|
-
// temporary one above lands them in `FORCE_CHANGE_PASSWORD`),
|
|
495
|
-
// returning (federation-managed — nobody holds the old one), or a
|
|
496
|
-
// password account being linked under the `'link'` policy.
|
|
497
|
-
// `Permanent: true` skips the new-password challenge.
|
|
498
|
-
try {
|
|
499
|
-
await client.send(new AdminSetUserPasswordCommand({
|
|
500
|
-
UserPoolId: config.userPoolId,
|
|
501
|
-
Username: email,
|
|
502
|
-
Password: password,
|
|
503
|
-
Permanent: true,
|
|
504
|
-
}));
|
|
505
|
-
}
|
|
506
|
-
catch (err) {
|
|
507
|
-
throw mapProviderError(err, 'federated_signin_failed');
|
|
508
|
-
}
|
|
509
|
-
let res;
|
|
510
|
-
try {
|
|
511
|
-
res = await client.send(new AdminInitiateAuthCommand({
|
|
512
|
-
UserPoolId: config.userPoolId,
|
|
513
|
-
ClientId: config.appClientId,
|
|
514
|
-
AuthFlow: 'ADMIN_USER_PASSWORD_AUTH',
|
|
515
|
-
AuthParameters: { USERNAME: email, PASSWORD: password },
|
|
516
|
-
}));
|
|
517
|
-
}
|
|
518
|
-
catch (err) {
|
|
519
|
-
throw mapProviderError(err, 'federated_signin_failed');
|
|
520
|
-
}
|
|
521
|
-
if (res.ChallengeName) {
|
|
522
|
-
throw new AuthError('federated_signin_failed', `Cognito returned an unexpected challenge after federated sign-in: ${res.ChallengeName}`, 500);
|
|
523
|
-
}
|
|
524
|
-
return {
|
|
525
|
-
...extractSignInTokens(res.AuthenticationResult),
|
|
526
|
-
accountLinked: linkingPasswordAccount,
|
|
527
|
-
created: !userExists,
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Generate a 32-char password that satisfies the strongest password
|
|
532
|
-
* policy VentureKit ships (`passwordStrength: 'strong'` — 12+ chars,
|
|
533
|
-
* upper, lower, digit, symbol). Shared with the invitations flow.
|
|
534
|
-
*/
|
|
535
|
-
export function generateStrongPassword() {
|
|
536
|
-
const base = randomBytes(24)
|
|
537
|
-
.toString('base64')
|
|
538
|
-
.replace(/[^A-Za-z0-9]/g, '')
|
|
539
|
-
.slice(0, 28);
|
|
540
|
-
return `Aa1!${base}`;
|
|
541
|
-
}
|
|
34
|
+
export { loadFederatedProviderCredentials, _resetFederatedCredentialsForTesting } from './federated/credentials.js';
|
|
35
|
+
export { PROVIDERS as FEDERATED_PROVIDERS, providerDescriptor } from './federated/providers.js';
|
|
36
|
+
export { createOAuthTransaction, generateOAuthState, parseOAuthTransaction, pkceChallenge, serializeOAuthTransaction, verifyOAuthState, verifyOAuthTransaction, } from './federated/oauth-transaction.js';
|
|
37
|
+
export { buildAuthorizeUrl, exchangeAuthorizationCode, validateIdTokenClaims } from './federated/authorization.js';
|
|
38
|
+
export { decideFederatedSignIn, federatedSubjectAttribute } from './federated/account-linking.js';
|
|
39
|
+
export { generateStrongPassword, signInAsFederatedUser } from './federated/sign-in.js';
|
|
542
40
|
//# sourceMappingURL=federated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"federated.js","sourceRoot":"","sources":["../../src/server/federated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,2BAA2B,EAC3B,gCAAgC,GAGjC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAqB,MAAM,aAAa,CAAC;AAsBrE,uEAAuE;AACvE,4DAA4D;AA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AAO,OAAO,IAAI,EAAE,CAAC;AACvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"federated.js","sourceRoot":"","sources":["../../src/server/federated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAQH,OAAO,EAAE,gCAAgC,EAAE,oCAAoC,EAAE,MAAM,4BAA4B,CAAC;AACpH,OAAO,EAAE,SAAS,IAAI,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEhG,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAMnH,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAOlG,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -78,9 +78,10 @@ export interface ForgotPasswordResult {
|
|
|
78
78
|
codeDelivery?: CodeDeliveryDetails;
|
|
79
79
|
/**
|
|
80
80
|
* Plaintext confirmation code — only populated when running against
|
|
81
|
-
* cognito-local
|
|
82
|
-
*
|
|
83
|
-
* in
|
|
81
|
+
* cognito-local under `vk dev` (`isLocalCognito`: an endpoint AND
|
|
82
|
+
* `VENTURE_LOCAL=true`). Useful so the developer can complete the flow
|
|
83
|
+
* in a browser without checking server logs. Never populated on a
|
|
84
|
+
* deployed function, whatever endpoint it is configured with.
|
|
84
85
|
*/
|
|
85
86
|
devCode?: string;
|
|
86
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forgot-password.d.ts","sourceRoot":"","sources":["../../src/server/forgot-password.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AASH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"forgot-password.d.ts","sourceRoot":"","sources":["../../src/server/forgot-password.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AASH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAOpD,MAAM,WAAW,mBAAmB;IAClC,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;IACnC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAmBD,gFAAgF;AAChF,wBAAgB,kCAAkC,IAAI,IAAI,CAEzD;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,mBAAmB,EAC1B,MAAM,GAAE,gBAAyC,GAChD,OAAO,CAAC,oBAAoB,CAAC,CAqD/B;AAED,MAAM,WAAW,0BAA0B;IACzC,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,qFAAqF;IACrF,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,EACjC,MAAM,GAAE,gBAAyC,GAChD,OAAO,CAAC,IAAI,CAAC,CAqEf"}
|
|
@@ -37,15 +37,13 @@ import { AdminSetUserPasswordCommand, ConfirmForgotPasswordCommand, ForgotPasswo
|
|
|
37
37
|
import { loadAuthServerConfig } from './config.js';
|
|
38
38
|
import { getCognitoClient } from './cognito-client.js';
|
|
39
39
|
import { AuthError, mapProviderError } from './errors.js';
|
|
40
|
+
import { isLocalCognito } from './local-cognito.js';
|
|
40
41
|
import { generateVerificationCode, hashVerificationCode } from './verification.js';
|
|
41
42
|
// ── Dev-mode (cognito-local) helpers ────────────────────────────────
|
|
42
43
|
const DEV_CODE_TTL_MS = 10 * 60 * 1000; // 10 minutes
|
|
43
44
|
const DEV_CODE_MAX_ATTEMPTS = 5;
|
|
44
45
|
/** In-memory store for forgot-password codes when running against cognito-local. */
|
|
45
46
|
const devForgotCodeStore = new Map();
|
|
46
|
-
function isDevMode(config) {
|
|
47
|
-
return !!config.endpoint;
|
|
48
|
-
}
|
|
49
47
|
function maskEmail(email) {
|
|
50
48
|
const [local, domain] = email.split('@');
|
|
51
49
|
if (!local || !domain)
|
|
@@ -74,7 +72,7 @@ export function _resetDevForgotCodeStoreForTesting() {
|
|
|
74
72
|
*/
|
|
75
73
|
export async function forgotPassword(input, config = loadAuthServerConfig()) {
|
|
76
74
|
const email = input.email.toLowerCase();
|
|
77
|
-
if (
|
|
75
|
+
if (isLocalCognito(config)) {
|
|
78
76
|
// cognito-local does not deliver emails; generate and store a
|
|
79
77
|
// code ourselves so the dev can complete the flow.
|
|
80
78
|
const code = generateVerificationCode();
|
|
@@ -141,7 +139,7 @@ export async function forgotPassword(input, config = loadAuthServerConfig()) {
|
|
|
141
139
|
*/
|
|
142
140
|
export async function confirmForgotPassword(input, config = loadAuthServerConfig()) {
|
|
143
141
|
const email = input.email.toLowerCase();
|
|
144
|
-
if (
|
|
142
|
+
if (isLocalCognito(config)) {
|
|
145
143
|
// cognito-local path: verify our locally-stored code, then set
|
|
146
144
|
// the password directly via AdminSetUserPassword.
|
|
147
145
|
const record = devForgotCodeStore.get(email);
|