@venturekit/auth 0.0.0-dev.20260429204013 → 0.0.0-dev.20260430161503
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/dist/server/cognito-client.d.ts +6 -5
- package/dist/server/cognito-client.d.ts.map +1 -1
- package/dist/server/cognito-client.js +19 -8
- package/dist/server/cognito-client.js.map +1 -1
- package/dist/server/config.d.ts +17 -3
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/config.js +13 -5
- package/dist/server/config.js.map +1 -1
- package/dist/server/middleware.d.ts.map +1 -1
- package/dist/server/middleware.js +1 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/refresh.d.ts.map +1 -1
- package/dist/server/refresh.js +6 -3
- package/dist/server/refresh.js.map +1 -1
- package/dist/server/revoke.js +1 -1
- package/dist/server/revoke.js.map +1 -1
- package/dist/server/sign-in.d.ts.map +1 -1
- package/dist/server/sign-in.js +32 -4
- package/dist/server/sign-in.js.map +1 -1
- package/dist/server/token-utils.d.ts +27 -0
- package/dist/server/token-utils.d.ts.map +1 -0
- package/dist/server/token-utils.js +63 -0
- package/dist/server/token-utils.js.map +1 -0
- package/dist/server/verify.d.ts +41 -4
- package/dist/server/verify.d.ts.map +1 -1
- package/dist/server/verify.js +116 -8
- package/dist/server/verify.js.map +1 -1
- package/package.json +4 -4
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The server flows in this directory all hit the same Cognito User Pool
|
|
5
5
|
* within a Lambda invocation, so we cache one
|
|
6
|
-
* `CognitoIdentityProviderClient` per region
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* `CognitoIdentityProviderClient` per `(region, endpoint)` tuple. In
|
|
7
|
+
* production both stay constant per Lambda, so the cache stays at size 1.
|
|
8
|
+
* In `vk dev` the `endpoint` differs (it points at cognito-local), so we
|
|
9
|
+
* key on it as well to avoid serving prod-config requests through a
|
|
10
|
+
* dev-config client when both happen to live in the same process.
|
|
10
11
|
*
|
|
11
12
|
* This module is **not** part of the public API surface; consumers go
|
|
12
13
|
* through `sign-in.ts`, `refresh.ts`, `revoke.ts`.
|
|
13
14
|
*/
|
|
14
15
|
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
|
|
15
|
-
export declare function getCognitoClient(region: string): CognitoIdentityProviderClient;
|
|
16
|
+
export declare function getCognitoClient(region: string, endpoint?: string): CognitoIdentityProviderClient;
|
|
16
17
|
/** Test-only — clear the cached clients between vitest runs. */
|
|
17
18
|
export declare function _resetCognitoClientCacheForTesting(): void;
|
|
18
19
|
//# sourceMappingURL=cognito-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cognito-client.d.ts","sourceRoot":"","sources":["../../src/server/cognito-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cognito-client.d.ts","sourceRoot":"","sources":["../../src/server/cognito-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2CAA2C,CAAC;AAQ1F,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAChB,6BAA6B,CAa/B;AAED,gEAAgE;AAChE,wBAAgB,kCAAkC,IAAI,IAAI,CAEzD"}
|
|
@@ -3,22 +3,33 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The server flows in this directory all hit the same Cognito User Pool
|
|
5
5
|
* within a Lambda invocation, so we cache one
|
|
6
|
-
* `CognitoIdentityProviderClient` per region
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* `CognitoIdentityProviderClient` per `(region, endpoint)` tuple. In
|
|
7
|
+
* production both stay constant per Lambda, so the cache stays at size 1.
|
|
8
|
+
* In `vk dev` the `endpoint` differs (it points at cognito-local), so we
|
|
9
|
+
* key on it as well to avoid serving prod-config requests through a
|
|
10
|
+
* dev-config client when both happen to live in the same process.
|
|
10
11
|
*
|
|
11
12
|
* This module is **not** part of the public API surface; consumers go
|
|
12
13
|
* through `sign-in.ts`, `refresh.ts`, `revoke.ts`.
|
|
13
14
|
*/
|
|
14
15
|
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
|
|
15
16
|
const cache = new Map();
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
function key(region, endpoint) {
|
|
18
|
+
return `${region}|${endpoint ?? ''}`;
|
|
19
|
+
}
|
|
20
|
+
export function getCognitoClient(region, endpoint) {
|
|
21
|
+
const k = key(region, endpoint);
|
|
22
|
+
const existing = cache.get(k);
|
|
18
23
|
if (existing)
|
|
19
24
|
return existing;
|
|
20
|
-
const client = new CognitoIdentityProviderClient({
|
|
21
|
-
|
|
25
|
+
const client = new CognitoIdentityProviderClient({
|
|
26
|
+
region,
|
|
27
|
+
// When `endpoint` is set the SDK skips its usual host construction
|
|
28
|
+
// (`https://cognito-idp.<region>.amazonaws.com`) and POSTs to this URL
|
|
29
|
+
// instead — exactly what we want for cognito-local in dev.
|
|
30
|
+
...(endpoint ? { endpoint } : {}),
|
|
31
|
+
});
|
|
32
|
+
cache.set(k, client);
|
|
22
33
|
return client;
|
|
23
34
|
}
|
|
24
35
|
/** Test-only — clear the cached clients between vitest runs. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cognito-client.js","sourceRoot":"","sources":["../../src/server/cognito-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cognito-client.js","sourceRoot":"","sources":["../../src/server/cognito-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2CAA2C,CAAC;AAE1F,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyC,CAAC;AAE/D,SAAS,GAAG,CAAC,MAAc,EAAE,QAA4B;IACvD,OAAO,GAAG,MAAM,IAAI,QAAQ,IAAI,EAAE,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,QAAiB;IAEjB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,MAAM,MAAM,GAAG,IAAI,6BAA6B,CAAC;QAC/C,MAAM;QACN,mEAAmE;QACnE,uEAAuE;QACvE,2DAA2D;QAC3D,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClC,CAAC,CAAC;IACH,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,kCAAkC;IAChD,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
|
package/dist/server/config.d.ts
CHANGED
|
@@ -7,12 +7,17 @@
|
|
|
7
7
|
* - `region` — AWS region the user pool lives in
|
|
8
8
|
* - `userPoolId` — Cognito User Pool id
|
|
9
9
|
* - `appClientId` — Cognito User Pool app client id
|
|
10
|
+
* - `endpoint` — optional override for the Cognito API endpoint
|
|
11
|
+
* (used by `vk dev` to point at the in-docker
|
|
12
|
+
* cognito-local service; never set in deployed
|
|
13
|
+
* Lambdas)
|
|
10
14
|
*
|
|
11
15
|
* Most consumers will call {@link loadAuthServerConfig} which reads these
|
|
12
16
|
* from environment variables (`COGNITO_REGION`/`AWS_REGION`,
|
|
13
|
-
* `COGNITO_USER_POOL_ID`, `COGNITO_APP_CLIENT_ID
|
|
14
|
-
* deploy pipeline injects
|
|
15
|
-
*
|
|
17
|
+
* `COGNITO_USER_POOL_ID`, `COGNITO_APP_CLIENT_ID`, optional
|
|
18
|
+
* `COGNITO_ENDPOINT`). The VentureKit deploy pipeline injects the first
|
|
19
|
+
* three into the Lambda environment automatically when an `auth` intent
|
|
20
|
+
* is declared in `vk.config.ts`.
|
|
16
21
|
*
|
|
17
22
|
* Tests / scripts can pass a `config` argument explicitly to every flow
|
|
18
23
|
* and skip env-var loading entirely.
|
|
@@ -21,6 +26,15 @@ export interface AuthServerConfig {
|
|
|
21
26
|
region: string;
|
|
22
27
|
userPoolId: string;
|
|
23
28
|
appClientId: string;
|
|
29
|
+
/**
|
|
30
|
+
* Cognito API endpoint override. When set, all SDK calls
|
|
31
|
+
* (`signInWithPassword`, `refreshSession`, `revokeRefreshToken`) target
|
|
32
|
+
* this URL instead of the public AWS endpoint, and JWT verification
|
|
33
|
+
* uses the generic OIDC verifier with `<endpoint>/<userPoolId>` as the
|
|
34
|
+
* issuer. `vk dev` populates this with `http://localhost:9229` (the
|
|
35
|
+
* cognito-local Docker service); deployed Lambdas leave it unset.
|
|
36
|
+
*/
|
|
37
|
+
endpoint?: string;
|
|
24
38
|
}
|
|
25
39
|
/**
|
|
26
40
|
* Read server-side auth configuration from environment variables.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACxE,gBAAgB,CAwBlB"}
|
package/dist/server/config.js
CHANGED
|
@@ -7,12 +7,17 @@
|
|
|
7
7
|
* - `region` — AWS region the user pool lives in
|
|
8
8
|
* - `userPoolId` — Cognito User Pool id
|
|
9
9
|
* - `appClientId` — Cognito User Pool app client id
|
|
10
|
+
* - `endpoint` — optional override for the Cognito API endpoint
|
|
11
|
+
* (used by `vk dev` to point at the in-docker
|
|
12
|
+
* cognito-local service; never set in deployed
|
|
13
|
+
* Lambdas)
|
|
10
14
|
*
|
|
11
15
|
* Most consumers will call {@link loadAuthServerConfig} which reads these
|
|
12
16
|
* from environment variables (`COGNITO_REGION`/`AWS_REGION`,
|
|
13
|
-
* `COGNITO_USER_POOL_ID`, `COGNITO_APP_CLIENT_ID
|
|
14
|
-
* deploy pipeline injects
|
|
15
|
-
*
|
|
17
|
+
* `COGNITO_USER_POOL_ID`, `COGNITO_APP_CLIENT_ID`, optional
|
|
18
|
+
* `COGNITO_ENDPOINT`). The VentureKit deploy pipeline injects the first
|
|
19
|
+
* three into the Lambda environment automatically when an `auth` intent
|
|
20
|
+
* is declared in `vk.config.ts`.
|
|
16
21
|
*
|
|
17
22
|
* Tests / scripts can pass a `config` argument explicitly to every flow
|
|
18
23
|
* and skip env-var loading entirely.
|
|
@@ -30,6 +35,7 @@ export function loadAuthServerConfig(env = process.env) {
|
|
|
30
35
|
const region = env['COGNITO_REGION'] ?? env['AWS_REGION'];
|
|
31
36
|
const userPoolId = env['COGNITO_USER_POOL_ID'];
|
|
32
37
|
const appClientId = env['COGNITO_APP_CLIENT_ID'];
|
|
38
|
+
const endpoint = env['COGNITO_ENDPOINT'];
|
|
33
39
|
const missing = [];
|
|
34
40
|
if (!region)
|
|
35
41
|
missing.push('COGNITO_REGION (or AWS_REGION)');
|
|
@@ -40,13 +46,15 @@ export function loadAuthServerConfig(env = process.env) {
|
|
|
40
46
|
if (missing.length > 0) {
|
|
41
47
|
throw new Error(`[@venturekit/auth/server] missing env var(s): ${missing.join(', ')} — ` +
|
|
42
48
|
`VentureKit's auth intent in vk.config.ts injects these into the Lambda ` +
|
|
43
|
-
`environment from the deployed user pool.
|
|
44
|
-
`
|
|
49
|
+
`environment from the deployed user pool. For local dev, run \`vk dev\` ` +
|
|
50
|
+
`which auto-provisions a cognito-local user pool and writes the IDs ` +
|
|
51
|
+
`into the dev server's env (or set them manually in .env.local).`);
|
|
45
52
|
}
|
|
46
53
|
return {
|
|
47
54
|
region: region,
|
|
48
55
|
userPoolId: userPoolId,
|
|
49
56
|
appClientId: appClientId,
|
|
57
|
+
...(endpoint ? { endpoint } : {}),
|
|
50
58
|
};
|
|
51
59
|
}
|
|
52
60
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAiBH;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAA8D,OAAO,CAAC,GAAG;IAEzE,MAAM,MAAM,GAAG,GAAG,CAAC,gBAAgB,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACzC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;IAC5D,IAAI,CAAC,UAAU;QAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACtD,IAAI,CAAC,WAAW;QAAE,OAAO,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACxD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,iDAAiD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;YACtE,yEAAyE;YACzE,yEAAyE;YACzE,qEAAqE;YACrE,iEAAiE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,EAAE,MAAO;QACf,UAAU,EAAE,UAAW;QACvB,WAAW,EAAE,WAAY;QACzB,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAKzD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC;IAC3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,UAAU,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CA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MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE/C,CAAC;IACd,OAAO,oBAAoB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,mBAAmB,CAC1B,MAA+B;IAE/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9B,sEAAsE;IACtE,oEAAoE;IACpE,mEAAmE;IACnE,0CAA0C;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,MAAM,MAAM,GACV,OAAO,UAAU,KAAK,QAAQ;QAC5B,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;QACvC,CAAC,CAAC,EAAE,CAAC;IACT,OAAO;QACL,EAAE,EAAE,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QACtC,KAAK,EAAE,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;QACpD,MAAM;QACN,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../src/server/refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../src/server/refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMpD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,EACpB,MAAM,GAAE,gBAAyC,GAChD,OAAO,CAAC,aAAa,CAAC,CA8BxB"}
|
package/dist/server/refresh.js
CHANGED
|
@@ -11,6 +11,7 @@ import { InitiateAuthCommand } from '@aws-sdk/client-cognito-identity-provider';
|
|
|
11
11
|
import { loadAuthServerConfig } from './config.js';
|
|
12
12
|
import { getCognitoClient } from './cognito-client.js';
|
|
13
13
|
import { AuthError, mapProviderError } from './errors.js';
|
|
14
|
+
import { deriveExpiresInFromJwt } from './token-utils.js';
|
|
14
15
|
/**
|
|
15
16
|
* Exchange a refresh token for fresh id + access tokens.
|
|
16
17
|
*
|
|
@@ -19,7 +20,7 @@ import { AuthError, mapProviderError } from './errors.js';
|
|
|
19
20
|
* failures so the user is redirected straight to sign-in.
|
|
20
21
|
*/
|
|
21
22
|
export async function refreshSession(refreshToken, config = loadAuthServerConfig()) {
|
|
22
|
-
const client = getCognitoClient(config.region);
|
|
23
|
+
const client = getCognitoClient(config.region, config.endpoint);
|
|
23
24
|
let res;
|
|
24
25
|
try {
|
|
25
26
|
res = await client.send(new InitiateAuthCommand({
|
|
@@ -32,14 +33,16 @@ export async function refreshSession(refreshToken, config = loadAuthServerConfig
|
|
|
32
33
|
throw mapProviderError(err, 'refresh_failed');
|
|
33
34
|
}
|
|
34
35
|
const result = res.AuthenticationResult;
|
|
35
|
-
|
|
36
|
+
// Tokens MUST be present; `ExpiresIn` is derived from the access
|
|
37
|
+
// token's `exp` claim when the provider omits it (see `sign-in.ts`).
|
|
38
|
+
if (!result?.IdToken || !result.AccessToken) {
|
|
36
39
|
throw new AuthError('incomplete_auth_result', 'Identity provider returned an incomplete refresh result', 500);
|
|
37
40
|
}
|
|
38
41
|
return {
|
|
39
42
|
idToken: result.IdToken,
|
|
40
43
|
accessToken: result.AccessToken,
|
|
41
44
|
refreshToken: '',
|
|
42
|
-
expiresIn: result.ExpiresIn,
|
|
45
|
+
expiresIn: result.ExpiresIn ?? deriveExpiresInFromJwt(result.AccessToken),
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
//# sourceMappingURL=refresh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.js","sourceRoot":"","sources":["../../src/server/refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAEhF,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;AAe1D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,YAAoB,EACpB,SAA2B,oBAAoB,EAAE;IAEjD,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"refresh.js","sourceRoot":"","sources":["../../src/server/refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAEhF,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,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAe1D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,YAAoB,EACpB,SAA2B,oBAAoB,EAAE;IAEjD,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChE,IAAI,GAAG,CAAC;IACR,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CACrB,IAAI,mBAAmB,CAAC;YACtB,QAAQ,EAAE,MAAM,CAAC,WAAW;YAC5B,QAAQ,EAAE,oBAAoB;YAC9B,cAAc,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE;SAChD,CAAC,CACH,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,CAAC,oBAAoB,CAAC;IACxC,iEAAiE;IACjE,qEAAqE;IACrE,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,IAAI,SAAS,CACjB,wBAAwB,EACxB,yDAAyD,EACzD,GAAG,CACJ,CAAC;IACJ,CAAC;IACD,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,EAAE;QAChB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,sBAAsB,CAAC,MAAM,CAAC,WAAW,CAAC;KAC1E,CAAC;AACJ,CAAC"}
|
package/dist/server/revoke.js
CHANGED
|
@@ -17,7 +17,7 @@ import { getCognitoClient } from './cognito-client.js';
|
|
|
17
17
|
* the function never throws.
|
|
18
18
|
*/
|
|
19
19
|
export async function revokeRefreshToken(refreshToken, config = loadAuthServerConfig()) {
|
|
20
|
-
const client = getCognitoClient(config.region);
|
|
20
|
+
const client = getCognitoClient(config.region, config.endpoint);
|
|
21
21
|
try {
|
|
22
22
|
await client.send(new RevokeTokenCommand({
|
|
23
23
|
ClientId: config.appClientId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revoke.js","sourceRoot":"","sources":["../../src/server/revoke.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,YAAoB,EACpB,SAA2B,oBAAoB,EAAE;IAEjD,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"revoke.js","sourceRoot":"","sources":["../../src/server/revoke.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,YAAoB,EACpB,SAA2B,oBAAoB,EAAE;IAEjD,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChE,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,IAAI,CACf,IAAI,kBAAkB,CAAC;YACrB,QAAQ,EAAE,MAAM,CAAC,WAAW;YAC5B,KAAK,EAAE,YAAY;SACpB,CAAC,CACH,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,kEAAkE,EAAE,GAAG,CAAC,CAAC;IACxF,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-in.d.ts","sourceRoot":"","sources":["../../src/server/sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"sign-in.d.ts","sourceRoot":"","sources":["../../src/server/sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAOH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMpD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,iBAAiB,EAC9B,MAAM,GAAE,gBAAyC,GAChD,OAAO,CAAC,YAAY,CAAC,CAsCvB"}
|
package/dist/server/sign-in.js
CHANGED
|
@@ -20,6 +20,7 @@ import { InitiateAuthCommand, } from '@aws-sdk/client-cognito-identity-provider'
|
|
|
20
20
|
import { loadAuthServerConfig } from './config.js';
|
|
21
21
|
import { getCognitoClient } from './cognito-client.js';
|
|
22
22
|
import { AuthError, mapProviderError } from './errors.js';
|
|
23
|
+
import { deriveExpiresInFromJwt } from './token-utils.js';
|
|
23
24
|
/**
|
|
24
25
|
* Authenticate a user with email + password and return freshly-minted
|
|
25
26
|
* id, access, and refresh tokens.
|
|
@@ -29,7 +30,7 @@ import { AuthError, mapProviderError } from './errors.js';
|
|
|
29
30
|
* {@link loadAuthServerConfig}.
|
|
30
31
|
*/
|
|
31
32
|
export async function signInWithPassword(credentials, config = loadAuthServerConfig()) {
|
|
32
|
-
const client = getCognitoClient(config.region);
|
|
33
|
+
const client = getCognitoClient(config.region, config.endpoint);
|
|
33
34
|
let res;
|
|
34
35
|
try {
|
|
35
36
|
res = await client.send(new InitiateAuthCommand({
|
|
@@ -44,20 +45,47 @@ export async function signInWithPassword(credentials, config = loadAuthServerCon
|
|
|
44
45
|
catch (err) {
|
|
45
46
|
throw mapProviderError(err, 'auth_failed');
|
|
46
47
|
}
|
|
48
|
+
// Cognito returns one of three shapes:
|
|
49
|
+
// 1. `AuthenticationResult` — success, tokens are present
|
|
50
|
+
// 2. `ChallengeName` + `Session` — credentials OK but additional step
|
|
51
|
+
// needed (NEW_PASSWORD_REQUIRED, MFA_SETUP, SMS_MFA, …)
|
|
52
|
+
// 3. neither — only happens with broken/misconfigured providers
|
|
53
|
+
//
|
|
54
|
+
// We don't auto-resolve challenges — surfacing the challenge name lets
|
|
55
|
+
// callers implement the right flow. The most common one in dev is
|
|
56
|
+
// NEW_PASSWORD_REQUIRED, which fires when a user was created with
|
|
57
|
+
// `admin-create-user --temporary-password` but never had
|
|
58
|
+
// `admin-set-user-password --permanent` run against them.
|
|
59
|
+
if (res.ChallengeName) {
|
|
60
|
+
throw new AuthError('auth_challenge_required', challengeMessage(res.ChallengeName), 400);
|
|
61
|
+
}
|
|
47
62
|
return extractSignInTokens(res.AuthenticationResult);
|
|
48
63
|
}
|
|
64
|
+
function challengeMessage(challengeName) {
|
|
65
|
+
const base = `Identity provider requires challenge: ${challengeName}.`;
|
|
66
|
+
if (challengeName === 'NEW_PASSWORD_REQUIRED') {
|
|
67
|
+
return (base +
|
|
68
|
+
' User is in FORCE_CHANGE_PASSWORD state — set a permanent password' +
|
|
69
|
+
' (local dev: `aws cognito-idp admin-set-user-password --permanent`;' +
|
|
70
|
+
' prod: complete the new-password flow client-side).');
|
|
71
|
+
}
|
|
72
|
+
return base;
|
|
73
|
+
}
|
|
49
74
|
function extractSignInTokens(result) {
|
|
75
|
+
// Tokens themselves MUST be present. `ExpiresIn` is derived from the
|
|
76
|
+
// access-token's `exp` claim when the response omits it — real AWS
|
|
77
|
+
// always sends it, but some OSS compatibles (cognito-local) don't,
|
|
78
|
+
// and the tokens are usable regardless.
|
|
50
79
|
if (!result?.IdToken ||
|
|
51
80
|
!result.AccessToken ||
|
|
52
|
-
!result.RefreshToken
|
|
53
|
-
!result.ExpiresIn) {
|
|
81
|
+
!result.RefreshToken) {
|
|
54
82
|
throw new AuthError('incomplete_auth_result', 'Identity provider returned an incomplete authentication result', 500);
|
|
55
83
|
}
|
|
56
84
|
return {
|
|
57
85
|
idToken: result.IdToken,
|
|
58
86
|
accessToken: result.AccessToken,
|
|
59
87
|
refreshToken: result.RefreshToken,
|
|
60
|
-
expiresIn: result.ExpiresIn,
|
|
88
|
+
expiresIn: result.ExpiresIn ?? deriveExpiresInFromJwt(result.AccessToken),
|
|
61
89
|
};
|
|
62
90
|
}
|
|
63
91
|
//# sourceMappingURL=sign-in.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-in.js","sourceRoot":"","sources":["../../src/server/sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"sign-in.js","sourceRoot":"","sources":["../../src/server/sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,mBAAmB,GAGpB,MAAM,2CAA2C,CAAC;AAEnD,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,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAe1D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,WAA8B,EAC9B,SAA2B,oBAAoB,EAAE;IAEjD,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChE,IAAI,GAA8B,CA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,YAAY,EACpB,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,wBAAwB,EACxB,gEAAgE,EAChE,GAAG,CACJ,CAAC;IACJ,CAAC;IACD,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,sBAAsB,CAAC,MAAM,CAAC,WAAW,CAAC;KAC1E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal token-introspection helpers.
|
|
3
|
+
*
|
|
4
|
+
* The Cognito SDK returns `ExpiresIn` alongside every successful
|
|
5
|
+
* `InitiateAuthCommand`, but some OSS Cognito compatibles
|
|
6
|
+
* (notably `cognito-local`) omit that top-level field even when the
|
|
7
|
+
* tokens themselves carry a perfectly valid `exp` claim. Rather than
|
|
8
|
+
* treat those responses as fatal, we derive the remaining lifetime
|
|
9
|
+
* from the access token itself.
|
|
10
|
+
*
|
|
11
|
+
* This file intentionally has no `@venturekit/auth/server` surface
|
|
12
|
+
* exposure — it's consumed by `sign-in.ts` and `refresh.ts` only.
|
|
13
|
+
*/
|
|
14
|
+
/** Cognito's default access-token lifetime (1 hour). */
|
|
15
|
+
export declare const DEFAULT_ACCESS_TOKEN_TTL_SECONDS = 3600;
|
|
16
|
+
/**
|
|
17
|
+
* Compute seconds-until-expiry from a JWT's `exp` claim, preferring
|
|
18
|
+
* `exp - now` (the actual remaining validity) and falling back to
|
|
19
|
+
* `exp - iat` if the system clock is off. Returns the Cognito default
|
|
20
|
+
* when the token is malformed or lacks a usable `exp`.
|
|
21
|
+
*
|
|
22
|
+
* This function does NOT verify the token's signature — the caller is
|
|
23
|
+
* expected to trust the minting provider (a fresh response from
|
|
24
|
+
* `InitiateAuthCommand`). Use `verifyAndDecode` for untrusted input.
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveExpiresInFromJwt(jwt: string, nowSeconds?: number): number;
|
|
27
|
+
//# sourceMappingURL=token-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-utils.d.ts","sourceRoot":"","sources":["../../src/server/token-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,wDAAwD;AACxD,eAAO,MAAM,gCAAgC,OAAO,CAAC;AAErD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,MAAsC,GACjD,MAAM,CAgBR"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal token-introspection helpers.
|
|
3
|
+
*
|
|
4
|
+
* The Cognito SDK returns `ExpiresIn` alongside every successful
|
|
5
|
+
* `InitiateAuthCommand`, but some OSS Cognito compatibles
|
|
6
|
+
* (notably `cognito-local`) omit that top-level field even when the
|
|
7
|
+
* tokens themselves carry a perfectly valid `exp` claim. Rather than
|
|
8
|
+
* treat those responses as fatal, we derive the remaining lifetime
|
|
9
|
+
* from the access token itself.
|
|
10
|
+
*
|
|
11
|
+
* This file intentionally has no `@venturekit/auth/server` surface
|
|
12
|
+
* exposure — it's consumed by `sign-in.ts` and `refresh.ts` only.
|
|
13
|
+
*/
|
|
14
|
+
/** Cognito's default access-token lifetime (1 hour). */
|
|
15
|
+
export const DEFAULT_ACCESS_TOKEN_TTL_SECONDS = 3600;
|
|
16
|
+
/**
|
|
17
|
+
* Compute seconds-until-expiry from a JWT's `exp` claim, preferring
|
|
18
|
+
* `exp - now` (the actual remaining validity) and falling back to
|
|
19
|
+
* `exp - iat` if the system clock is off. Returns the Cognito default
|
|
20
|
+
* when the token is malformed or lacks a usable `exp`.
|
|
21
|
+
*
|
|
22
|
+
* This function does NOT verify the token's signature — the caller is
|
|
23
|
+
* expected to trust the minting provider (a fresh response from
|
|
24
|
+
* `InitiateAuthCommand`). Use `verifyAndDecode` for untrusted input.
|
|
25
|
+
*/
|
|
26
|
+
export function deriveExpiresInFromJwt(jwt, nowSeconds = Math.floor(Date.now() / 1000)) {
|
|
27
|
+
const payload = decodeJwtPayload(jwt);
|
|
28
|
+
if (!payload)
|
|
29
|
+
return DEFAULT_ACCESS_TOKEN_TTL_SECONDS;
|
|
30
|
+
const exp = typeof payload.exp === 'number' ? payload.exp : undefined;
|
|
31
|
+
const iat = typeof payload.iat === 'number' ? payload.iat : undefined;
|
|
32
|
+
if (exp === undefined)
|
|
33
|
+
return DEFAULT_ACCESS_TOKEN_TTL_SECONDS;
|
|
34
|
+
const remaining = exp - nowSeconds;
|
|
35
|
+
if (remaining > 0)
|
|
36
|
+
return remaining;
|
|
37
|
+
// Clock skew fallback — prefer minted lifetime over a negative remaining.
|
|
38
|
+
if (iat !== undefined && exp > iat)
|
|
39
|
+
return exp - iat;
|
|
40
|
+
return DEFAULT_ACCESS_TOKEN_TTL_SECONDS;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Base64url-decode and JSON.parse a JWT payload. Returns `null` on any
|
|
44
|
+
* failure — callers fall back to a default.
|
|
45
|
+
*/
|
|
46
|
+
function decodeJwtPayload(jwt) {
|
|
47
|
+
if (typeof jwt !== 'string' || jwt.length === 0)
|
|
48
|
+
return null;
|
|
49
|
+
const parts = jwt.split('.');
|
|
50
|
+
if (parts.length < 2)
|
|
51
|
+
return null;
|
|
52
|
+
try {
|
|
53
|
+
const decoded = Buffer.from(parts[1], 'base64url').toString('utf8');
|
|
54
|
+
const obj = JSON.parse(decoded);
|
|
55
|
+
if (obj && typeof obj === 'object')
|
|
56
|
+
return obj;
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=token-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-utils.js","sourceRoot":"","sources":["../../src/server/token-ut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AG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAY,CAAC;QAC3C,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAA8B,CAAC;QAC1E,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/server/verify.d.ts
CHANGED
|
@@ -1,21 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JWT verification against a Cognito User Pool's JWKS.
|
|
3
3
|
*
|
|
4
|
-
* Wraps `aws-jwt-verify`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Wraps `aws-jwt-verify` so consumers don't take a direct dependency on
|
|
5
|
+
* it. Two code paths:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Production** — `CognitoJwtVerifier` builds the issuer + JWKS URL
|
|
8
|
+
* from the user-pool id (`https://cognito-idp.<region>.amazonaws.com/<userPoolId>`).
|
|
9
|
+
* 2. **`vk dev` (cognito-local)** — when `endpoint` is set we fall
|
|
10
|
+
* through to the generic `JwtVerifier` with an explicit issuer
|
|
11
|
+
* (`<endpoint>/<userPoolId>`) and `jwksUri`
|
|
12
|
+
* (`<endpoint>/<userPoolId>/.well-known/jwks.json`). The
|
|
13
|
+
* Cognito-specific `token_use` + `client_id` checks are reapplied
|
|
14
|
+
* via `validateCognitoJwtFields`.
|
|
15
|
+
*
|
|
16
|
+
* The verifier is cached per `(userPoolId, tokenUse, clientId, endpoint)`
|
|
17
|
+
* tuple so the JWKS is fetched once per cold start.
|
|
8
18
|
*
|
|
9
19
|
* Use this when API Gateway is NOT fronting your Lambda with a Cognito
|
|
10
20
|
* Authorizer — for example, cookie-based sessions where the Lambda
|
|
11
21
|
* itself reads the cookie and verifies the token.
|
|
12
22
|
*/
|
|
23
|
+
import { type JsonFetcher } from 'aws-jwt-verify/https';
|
|
24
|
+
import type { Json } from 'aws-jwt-verify/safe-json-parse';
|
|
13
25
|
export interface VerifyOptions {
|
|
14
26
|
userPoolId: string;
|
|
15
27
|
/** App client id(s) the token must have been issued to. */
|
|
16
28
|
clientId?: string | string[];
|
|
17
29
|
/** Defaults to `'access'`. Use `'id'` for id tokens. */
|
|
18
30
|
tokenUse?: 'access' | 'id';
|
|
31
|
+
/**
|
|
32
|
+
* Cognito API endpoint override. When set, JWTs are validated as
|
|
33
|
+
* generic OIDC tokens with `<endpoint>/<userPoolId>` as the expected
|
|
34
|
+
* issuer (Cognito-specific fields are still checked via
|
|
35
|
+
* `validateCognitoJwtFields`). Used by `vk dev` to verify tokens
|
|
36
|
+
* minted by cognito-local; deployed Lambdas leave it undefined.
|
|
37
|
+
*/
|
|
38
|
+
endpoint?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `JsonFetcher` that transparently handles `http://` URIs by routing
|
|
42
|
+
* them through Node's `http` module. The library's stock
|
|
43
|
+
* `SimpleJsonFetcher` is hardcoded to `https`-only — see
|
|
44
|
+
* `aws-jwt-verify/dist/esm/https-node.js`'s `https.request` call —
|
|
45
|
+
* which is what we want in production but breaks against
|
|
46
|
+
* cognito-local's plain-HTTP JWKS endpoint and surfaces as
|
|
47
|
+
* `ERR_INVALID_PROTOCOL: Protocol "http:" not supported. Expected
|
|
48
|
+
* "https:"` from inside the verify error path.
|
|
49
|
+
*
|
|
50
|
+
* Exported for direct unit testing.
|
|
51
|
+
*/
|
|
52
|
+
export declare class HttpAwareJsonFetcher implements JsonFetcher {
|
|
53
|
+
private readonly httpsFallback;
|
|
54
|
+
constructor(httpsFallback?: JsonFetcher);
|
|
55
|
+
fetch: (uri: string, requestOptions?: Record<string, unknown>, data?: Buffer) => Promise<Json>;
|
|
19
56
|
}
|
|
20
57
|
/**
|
|
21
58
|
* Verify a Cognito-signed JWT and return its claims, or `null` when the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/server/verify.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/server/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE3E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAG3D,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAgCD;;;;;;;;;;;GAWG;AACH,qBAAa,oBAAqB,YAAW,WAAW;IACtD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAc;gBAEhC,aAAa,GAAE,WAAqC;IAIhE,KAAK,GACH,KAAK,MAAM,EACX,iBAAiB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,OAAO,MAAM,KACZ,OAAO,CAAC,IAAI,CAAC,CA0Bd;CACH;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAyDzC;AAED,iEAAiE;AACjE,wBAAgB,6BAA6B,IAAI,IAAI,CAEpD"}
|
package/dist/server/verify.js
CHANGED
|
@@ -1,23 +1,92 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JWT verification against a Cognito User Pool's JWKS.
|
|
3
3
|
*
|
|
4
|
-
* Wraps `aws-jwt-verify`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Wraps `aws-jwt-verify` so consumers don't take a direct dependency on
|
|
5
|
+
* it. Two code paths:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Production** — `CognitoJwtVerifier` builds the issuer + JWKS URL
|
|
8
|
+
* from the user-pool id (`https://cognito-idp.<region>.amazonaws.com/<userPoolId>`).
|
|
9
|
+
* 2. **`vk dev` (cognito-local)** — when `endpoint` is set we fall
|
|
10
|
+
* through to the generic `JwtVerifier` with an explicit issuer
|
|
11
|
+
* (`<endpoint>/<userPoolId>`) and `jwksUri`
|
|
12
|
+
* (`<endpoint>/<userPoolId>/.well-known/jwks.json`). The
|
|
13
|
+
* Cognito-specific `token_use` + `client_id` checks are reapplied
|
|
14
|
+
* via `validateCognitoJwtFields`.
|
|
15
|
+
*
|
|
16
|
+
* The verifier is cached per `(userPoolId, tokenUse, clientId, endpoint)`
|
|
17
|
+
* tuple so the JWKS is fetched once per cold start.
|
|
8
18
|
*
|
|
9
19
|
* Use this when API Gateway is NOT fronting your Lambda with a Cognito
|
|
10
20
|
* Authorizer — for example, cookie-based sessions where the Lambda
|
|
11
21
|
* itself reads the cookie and verifies the token.
|
|
12
22
|
*/
|
|
13
|
-
import
|
|
23
|
+
import http from 'node:http';
|
|
24
|
+
import { CognitoJwtVerifier, JwtRsaVerifier } from 'aws-jwt-verify';
|
|
25
|
+
import { validateCognitoJwtFields } from 'aws-jwt-verify/cognito-verifier';
|
|
26
|
+
import { SimpleJsonFetcher } from 'aws-jwt-verify/https';
|
|
27
|
+
import { SimpleJwksCache } from 'aws-jwt-verify/jwk';
|
|
14
28
|
const verifierCache = new Map();
|
|
15
29
|
function cacheKey(opts) {
|
|
16
30
|
const tokenUse = opts.tokenUse ?? 'access';
|
|
17
31
|
const clientId = Array.isArray(opts.clientId)
|
|
18
32
|
? opts.clientId.join(',')
|
|
19
33
|
: (opts.clientId ?? 'null');
|
|
20
|
-
|
|
34
|
+
const endpoint = opts.endpoint ?? '';
|
|
35
|
+
return `${opts.userPoolId}|${tokenUse}|${clientId}|${endpoint}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Strip a trailing slash from a URL so subsequent path joins don't end
|
|
39
|
+
* up with `//` — `<endpoint>/<userPoolId>` is the issuer cognito-local
|
|
40
|
+
* emits, and a `//` would silently fail signature checks.
|
|
41
|
+
*/
|
|
42
|
+
function trimTrailingSlash(url) {
|
|
43
|
+
return url.endsWith('/') ? url.slice(0, -1) : url;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `JsonFetcher` that transparently handles `http://` URIs by routing
|
|
47
|
+
* them through Node's `http` module. The library's stock
|
|
48
|
+
* `SimpleJsonFetcher` is hardcoded to `https`-only — see
|
|
49
|
+
* `aws-jwt-verify/dist/esm/https-node.js`'s `https.request` call —
|
|
50
|
+
* which is what we want in production but breaks against
|
|
51
|
+
* cognito-local's plain-HTTP JWKS endpoint and surfaces as
|
|
52
|
+
* `ERR_INVALID_PROTOCOL: Protocol "http:" not supported. Expected
|
|
53
|
+
* "https:"` from inside the verify error path.
|
|
54
|
+
*
|
|
55
|
+
* Exported for direct unit testing.
|
|
56
|
+
*/
|
|
57
|
+
export class HttpAwareJsonFetcher {
|
|
58
|
+
httpsFallback;
|
|
59
|
+
constructor(httpsFallback = new SimpleJsonFetcher()) {
|
|
60
|
+
this.httpsFallback = httpsFallback;
|
|
61
|
+
}
|
|
62
|
+
fetch = (uri, requestOptions, data) => {
|
|
63
|
+
if (!uri.startsWith('http://')) {
|
|
64
|
+
return this.httpsFallback.fetch(uri, requestOptions, data);
|
|
65
|
+
}
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const req = http.get(uri, (res) => {
|
|
68
|
+
const status = res.statusCode ?? 0;
|
|
69
|
+
if (status < 200 || status >= 300) {
|
|
70
|
+
res.resume();
|
|
71
|
+
reject(new Error(`HTTP ${status} fetching ${uri}`));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const chunks = [];
|
|
75
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
76
|
+
res.on('end', () => {
|
|
77
|
+
try {
|
|
78
|
+
const text = Buffer.concat(chunks).toString('utf-8');
|
|
79
|
+
resolve(JSON.parse(text));
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
reject(err);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
res.on('error', reject);
|
|
86
|
+
});
|
|
87
|
+
req.on('error', reject);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
21
90
|
}
|
|
22
91
|
/**
|
|
23
92
|
* Verify a Cognito-signed JWT and return its claims, or `null` when the
|
|
@@ -29,8 +98,47 @@ function cacheKey(opts) {
|
|
|
29
98
|
*/
|
|
30
99
|
export async function verifyAndDecode(token, options) {
|
|
31
100
|
const key = cacheKey(options);
|
|
32
|
-
|
|
33
|
-
|
|
101
|
+
const cached = verifierCache.get(key);
|
|
102
|
+
let verifier;
|
|
103
|
+
if (cached) {
|
|
104
|
+
verifier = cached;
|
|
105
|
+
}
|
|
106
|
+
else if (options.endpoint) {
|
|
107
|
+
// Dev path: cognito-local. Use the generic OIDC verifier with the
|
|
108
|
+
// local issuer + JWKS URL, and reapply Cognito-specific checks
|
|
109
|
+
// (`token_use`, `client_id` / `aud`) via `customJwtCheck`.
|
|
110
|
+
//
|
|
111
|
+
// **HTTP fetcher.** `aws-jwt-verify`'s built-in JWKS fetcher is
|
|
112
|
+
// hardcoded to HTTPS (see `aws-jwt-verify/dist/esm/https-node.js`
|
|
113
|
+
// → `https.request`). cognito-local serves the JWKS over plain
|
|
114
|
+
// HTTP, so we inject `HttpAwareJsonFetcher` via a `SimpleJwksCache`
|
|
115
|
+
// — without it the verifier rejects every token with
|
|
116
|
+
// `ERR_INVALID_PROTOCOL: Protocol "http:" not supported. Expected
|
|
117
|
+
// "https:"` and the middleware silently treats it as "invalid
|
|
118
|
+
// token" → 401 on every authenticated request.
|
|
119
|
+
const base = `${trimTrailingSlash(options.endpoint)}/${options.userPoolId}`;
|
|
120
|
+
verifier = JwtRsaVerifier.create({
|
|
121
|
+
issuer: base,
|
|
122
|
+
// `audience: null` — only Cognito ID tokens carry an `aud` claim;
|
|
123
|
+
// access tokens have `client_id`. `validateCognitoJwtFields`
|
|
124
|
+
// handles both. Setting `audience` here would force-check `aud`
|
|
125
|
+
// and fail access tokens.
|
|
126
|
+
audience: null,
|
|
127
|
+
jwksUri: `${base}/.well-known/jwks.json`,
|
|
128
|
+
customJwtCheck: ({ payload }) => {
|
|
129
|
+
validateCognitoJwtFields(payload, {
|
|
130
|
+
tokenUse: options.tokenUse ?? null,
|
|
131
|
+
clientId: options.clientId ?? null,
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
}, {
|
|
135
|
+
jwksCache: new SimpleJwksCache({
|
|
136
|
+
fetcher: new HttpAwareJsonFetcher(),
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
verifierCache.set(key, verifier);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
34
142
|
verifier = CognitoJwtVerifier.create({
|
|
35
143
|
userPoolId: options.userPoolId,
|
|
36
144
|
tokenUse: options.tokenUse ?? 'access',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/server/verify.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/server/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAoB,MAAM,sBAAsB,CAAC;AAC3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AE,OAAO,CAAC,QAAQ,IAAI,IAAI;SACnC,CAAC,CAAC;QACH,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7C,OAAO,OAAkC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,6BAA6B;IAC3C,aAAa,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit/auth",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.20260430161503",
|
|
4
4
|
"description": "Authentication and authorization for VentureKit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@venturekit/core": "0.0.0-dev.
|
|
32
|
+
"@venturekit/core": "0.0.0-dev.20260430161503",
|
|
33
33
|
"@aws-sdk/client-cognito-identity-provider": "^3.668.0",
|
|
34
34
|
"aws-jwt-verify": "^4.0.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@venturekit/runtime": "0.0.0-dev.
|
|
37
|
+
"@venturekit/runtime": "0.0.0-dev.20260430161503"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@venturekit/runtime": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@venturekit/runtime": "0.0.0-dev.
|
|
45
|
+
"@venturekit/runtime": "0.0.0-dev.20260430161503",
|
|
46
46
|
"@types/aws-lambda": "^8.10.131",
|
|
47
47
|
"@types/node": "^25.6.0",
|
|
48
48
|
"typescript": "^5.3.0"
|