@fnd-platform/cognito-auth 1.0.0-alpha.1 → 1.0.0-alpha.2
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/lib/client/auth-client.d.ts +151 -94
- package/lib/client/auth-client.d.ts.map +1 -1
- package/lib/client/auth-client.js +330 -209
- package/lib/client/auth-client.js.map +1 -1
- package/lib/client/errors.d.ts +45 -23
- package/lib/client/errors.d.ts.map +1 -1
- package/lib/client/errors.js +80 -38
- package/lib/client/errors.js.map +1 -1
- package/lib/client/index.js +8 -23
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/jwt.js +27 -27
- package/lib/remix/session.server.d.ts.map +1 -1
- package/lib/remix/session.server.js +98 -95
- package/lib/remix/session.server.js.map +1 -1
- package/lib/types.d.ts +140 -106
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +3 -3
- package/package.json +9 -9
- package/LICENSE +0 -21
package/lib/client/errors.d.ts
CHANGED
|
@@ -9,18 +9,7 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Error codes for authentication failures.
|
|
11
11
|
*/
|
|
12
|
-
export type AuthErrorCode =
|
|
13
|
-
| 'INVALID_CREDENTIALS'
|
|
14
|
-
| 'USER_NOT_FOUND'
|
|
15
|
-
| 'USER_NOT_CONFIRMED'
|
|
16
|
-
| 'CODE_MISMATCH'
|
|
17
|
-
| 'CODE_EXPIRED'
|
|
18
|
-
| 'TOKEN_EXPIRED'
|
|
19
|
-
| 'INVALID_TOKEN'
|
|
20
|
-
| 'USER_EXISTS'
|
|
21
|
-
| 'PASSWORD_POLICY'
|
|
22
|
-
| 'RATE_LIMITED'
|
|
23
|
-
| 'SERVICE_ERROR';
|
|
12
|
+
export type AuthErrorCode = 'INVALID_CREDENTIALS' | 'USER_NOT_FOUND' | 'USER_NOT_CONFIRMED' | 'NEW_PASSWORD_REQUIRED' | 'CODE_MISMATCH' | 'CODE_EXPIRED' | 'TOKEN_EXPIRED' | 'INVALID_TOKEN' | 'USER_EXISTS' | 'PASSWORD_POLICY' | 'RATE_LIMITED' | 'SERVICE_ERROR';
|
|
24
13
|
/**
|
|
25
14
|
* Authentication error with structured error code.
|
|
26
15
|
*
|
|
@@ -43,16 +32,49 @@ export type AuthErrorCode =
|
|
|
43
32
|
* ```
|
|
44
33
|
*/
|
|
45
34
|
export declare class AuthError extends Error {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
readonly code: AuthErrorCode;
|
|
36
|
+
readonly cause?: Error | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new AuthError.
|
|
39
|
+
*
|
|
40
|
+
* @param message - Human-readable error message
|
|
41
|
+
* @param code - Structured error code for programmatic handling
|
|
42
|
+
* @param cause - Original error that caused this error
|
|
43
|
+
*/
|
|
44
|
+
constructor(message: string, code: AuthErrorCode, cause?: Error | undefined);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown when user must change their password before signing in.
|
|
48
|
+
*
|
|
49
|
+
* This occurs when:
|
|
50
|
+
* - User was created by admin and has FORCE_CHANGE_PASSWORD status
|
|
51
|
+
* - Password has expired per user pool policy
|
|
52
|
+
*
|
|
53
|
+
* The session token must be used to complete the password change via
|
|
54
|
+
* `authClient.completeNewPassword()`.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* try {
|
|
59
|
+
* await authClient.signIn(email, password);
|
|
60
|
+
* } catch (error) {
|
|
61
|
+
* if (error instanceof NewPasswordRequiredError) {
|
|
62
|
+
* // Redirect to change password page with session
|
|
63
|
+
* redirect(`/change-password?session=${error.session}&email=${email}`);
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare class NewPasswordRequiredError extends AuthError {
|
|
69
|
+
readonly session: string;
|
|
70
|
+
readonly email: string;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a NewPasswordRequiredError.
|
|
73
|
+
*
|
|
74
|
+
* @param session - Cognito session token for completing password change
|
|
75
|
+
* @param email - User's email address
|
|
76
|
+
*/
|
|
77
|
+
constructor(session: string, email: string);
|
|
56
78
|
}
|
|
57
79
|
/**
|
|
58
80
|
* Maps a Cognito SDK error to an AuthError.
|
|
@@ -64,4 +86,4 @@ export declare class AuthError extends Error {
|
|
|
64
86
|
* @internal
|
|
65
87
|
*/
|
|
66
88
|
export declare function mapCognitoError(error: unknown, defaultMessage: string): AuthError;
|
|
67
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
89
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,qBAAqB,GACrB,gBAAgB,GAChB,oBAAoB,GACpB,eAAe,GACf,cAAc,GACd,eAAe,GACf,eAAe,GACf,aAAa,GACb,iBAAiB,GACjB,cAAc,GACd,eAAe,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,SAAU,SAAQ,KAAK;aAUhB,IAAI,EAAE,aAAa;aACnB,KAAK,CAAC,EAAE,KAAK;IAV/B;;;;;;OAMG;gBAED,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,aAAa,EACnB,KAAK,CAAC,EAAE,KAAK,YAAA;CAShC;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,SAAS,CAOjF"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,qBAAqB,GACrB,gBAAgB,GAChB,oBAAoB,GACpB,uBAAuB,GACvB,eAAe,GACf,cAAc,GACd,eAAe,GACf,eAAe,GACf,aAAa,GACb,iBAAiB,GACjB,cAAc,GACd,eAAe,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,SAAU,SAAQ,KAAK;aAUhB,IAAI,EAAE,aAAa;aACnB,KAAK,CAAC,EAAE,KAAK;IAV/B;;;;;;OAMG;gBAED,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,aAAa,EACnB,KAAK,CAAC,EAAE,KAAK,YAAA;CAShC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;aAQnC,OAAO,EAAE,MAAM;aACf,KAAK,EAAE,MAAM;IAR/B;;;;;OAKG;gBAEe,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM;CAQhC;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,SAAS,CAOjF"}
|
package/lib/client/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Authentication error types for FndAuthClient.
|
|
4
4
|
*
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
|
-
Object.defineProperty(exports,
|
|
11
|
-
exports.AuthError = void 0;
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.NewPasswordRequiredError = exports.AuthError = void 0;
|
|
12
12
|
exports.mapCognitoError = mapCognitoError;
|
|
13
13
|
/**
|
|
14
14
|
* Authentication error with structured error code.
|
|
@@ -32,43 +32,85 @@ exports.mapCognitoError = mapCognitoError;
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
class AuthError extends Error {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
code;
|
|
36
|
+
cause;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new AuthError.
|
|
39
|
+
*
|
|
40
|
+
* @param message - Human-readable error message
|
|
41
|
+
* @param code - Structured error code for programmatic handling
|
|
42
|
+
* @param cause - Original error that caused this error
|
|
43
|
+
*/
|
|
44
|
+
constructor(message, code, cause) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.cause = cause;
|
|
48
|
+
this.name = 'AuthError';
|
|
49
|
+
// Maintains proper stack trace in V8 environments
|
|
50
|
+
if (Error.captureStackTrace) {
|
|
51
|
+
Error.captureStackTrace(this, AuthError);
|
|
52
|
+
}
|
|
52
53
|
}
|
|
53
|
-
}
|
|
54
54
|
}
|
|
55
55
|
exports.AuthError = AuthError;
|
|
56
|
+
/**
|
|
57
|
+
* Error thrown when user must change their password before signing in.
|
|
58
|
+
*
|
|
59
|
+
* This occurs when:
|
|
60
|
+
* - User was created by admin and has FORCE_CHANGE_PASSWORD status
|
|
61
|
+
* - Password has expired per user pool policy
|
|
62
|
+
*
|
|
63
|
+
* The session token must be used to complete the password change via
|
|
64
|
+
* `authClient.completeNewPassword()`.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* try {
|
|
69
|
+
* await authClient.signIn(email, password);
|
|
70
|
+
* } catch (error) {
|
|
71
|
+
* if (error instanceof NewPasswordRequiredError) {
|
|
72
|
+
* // Redirect to change password page with session
|
|
73
|
+
* redirect(`/change-password?session=${error.session}&email=${email}`);
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
class NewPasswordRequiredError extends AuthError {
|
|
79
|
+
session;
|
|
80
|
+
email;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a NewPasswordRequiredError.
|
|
83
|
+
*
|
|
84
|
+
* @param session - Cognito session token for completing password change
|
|
85
|
+
* @param email - User's email address
|
|
86
|
+
*/
|
|
87
|
+
constructor(session, email) {
|
|
88
|
+
super('Password change required', 'NEW_PASSWORD_REQUIRED');
|
|
89
|
+
this.session = session;
|
|
90
|
+
this.email = email;
|
|
91
|
+
this.name = 'NewPasswordRequiredError';
|
|
92
|
+
if (Error.captureStackTrace) {
|
|
93
|
+
Error.captureStackTrace(this, NewPasswordRequiredError);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.NewPasswordRequiredError = NewPasswordRequiredError;
|
|
56
98
|
/**
|
|
57
99
|
* Maps Cognito exception names to AuthErrorCode.
|
|
58
100
|
*
|
|
59
101
|
* @internal
|
|
60
102
|
*/
|
|
61
103
|
const COGNITO_ERROR_MAP = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
NotAuthorizedException: 'INVALID_CREDENTIALS',
|
|
105
|
+
UserNotFoundException: 'USER_NOT_FOUND',
|
|
106
|
+
UserNotConfirmedException: 'USER_NOT_CONFIRMED',
|
|
107
|
+
CodeMismatchException: 'CODE_MISMATCH',
|
|
108
|
+
ExpiredCodeException: 'CODE_EXPIRED',
|
|
109
|
+
UsernameExistsException: 'USER_EXISTS',
|
|
110
|
+
InvalidPasswordException: 'PASSWORD_POLICY',
|
|
111
|
+
InvalidParameterException: 'PASSWORD_POLICY',
|
|
112
|
+
TooManyRequestsException: 'RATE_LIMITED',
|
|
113
|
+
LimitExceededException: 'RATE_LIMITED',
|
|
72
114
|
};
|
|
73
115
|
/**
|
|
74
116
|
* Maps a Cognito SDK error to an AuthError.
|
|
@@ -80,11 +122,11 @@ const COGNITO_ERROR_MAP = {
|
|
|
80
122
|
* @internal
|
|
81
123
|
*/
|
|
82
124
|
function mapCognitoError(error, defaultMessage) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
125
|
+
if (error instanceof Error) {
|
|
126
|
+
const errorName = error.name;
|
|
127
|
+
const code = COGNITO_ERROR_MAP[errorName] ?? 'SERVICE_ERROR';
|
|
128
|
+
return new AuthError(error.message || defaultMessage, code, error);
|
|
129
|
+
}
|
|
130
|
+
return new AuthError(defaultMessage, 'SERVICE_ERROR');
|
|
89
131
|
}
|
|
90
|
-
//# sourceMappingURL=errors.js.map
|
|
132
|
+
//# sourceMappingURL=errors.js.map
|
package/lib/client/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAkIH,0CAOC;AAtHD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,SAAU,SAAQ,KAAK;IAUhB;IACA;IAVlB;;;;;;OAMG;IACH,YACE,OAAe,EACC,IAAmB,EACnB,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAe;QACnB,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,kDAAkD;QAClD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC3C,CA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js
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Auth client exports.
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
Object.defineProperty(exports,
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.AuthError = exports.clearClientCache = exports.FndAuthClient = void 0;
|
|
9
|
-
var auth_client_js_1 = require(
|
|
10
|
-
Object.defineProperty(exports,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, 'clearClientCache', {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return auth_client_js_1.clearClientCache;
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
var errors_js_1 = require('./errors.js');
|
|
23
|
-
Object.defineProperty(exports, 'AuthError', {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return errors_js_1.AuthError;
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
9
|
+
var auth_client_js_1 = require("./auth-client.js");
|
|
10
|
+
Object.defineProperty(exports, "FndAuthClient", { enumerable: true, get: function () { return auth_client_js_1.FndAuthClient; } });
|
|
11
|
+
Object.defineProperty(exports, "clearClientCache", { enumerable: true, get: function () { return auth_client_js_1.clearClientCache; } });
|
|
12
|
+
var errors_js_1 = require("./errors.js");
|
|
13
|
+
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_js_1.AuthError; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -22,9 +22,9 @@ export { handler as authorizerHandler } from './authorizer/handler.js';
|
|
|
22
22
|
export { refreshAccessToken, clearClientCache } from './utils/token-refresh.js';
|
|
23
23
|
export type { TokenRefreshConfig, RefreshResult } from './utils/token-refresh.js';
|
|
24
24
|
export { FndAuthClient, clearClientCache as clearAuthClientCache } from './client/auth-client.js';
|
|
25
|
-
export { AuthError } from './client/errors.js';
|
|
25
|
+
export { AuthError, NewPasswordRequiredError } from './client/errors.js';
|
|
26
26
|
export type { AuthErrorCode } from './client/errors.js';
|
|
27
27
|
export { createSessionStorage, getSession, createUserSession, requireAuth, getOptionalUser, getUserSession, logout, } from './remix/session.server.js';
|
|
28
28
|
export { requireAdmin, requireRole, hasRole, hasAnyRole } from './remix/admin.server.js';
|
|
29
|
-
export type { AuthClientConfig, AuthTokens, SignUpResult, SessionData, SessionUser, } from './types.js';
|
|
29
|
+
export type { AuthClientConfig, AuthTokens, SignUpResult, ForgotPasswordResult, SessionData, SessionUser, } from './types.js';
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,YAAY,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGrE,YAAY,EACV,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG1F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EACV,yBAAyB,EACzB,UAAU,IAAI,iBAAiB,EAC/B,iBAAiB,IAAI,wBAAwB,GAC9C,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,OAAO,IAAI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AE,SAAS,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACzE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,cAAc,EACd,MAAM,GACP,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGzF,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,WAAW,GACZ,MAAM,YAAY,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @packageDocumentation
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.hasAnyRole = exports.hasRole = exports.requireRole = exports.requireAdmin = exports.logout = exports.getUserSession = exports.getOptionalUser = exports.requireAuth = exports.createUserSession = exports.getSession = exports.createSessionStorage = exports.AuthError = exports.clearAuthClientCache = exports.FndAuthClient = exports.clearClientCache = exports.refreshAccessToken = exports.authorizerHandler = exports.withCognitoAuth = exports.clearVerifierCache = exports.getVerifier = exports.verifyAndExtract = exports.verifyToken = exports.VALID_STAGES = exports.validateStage = exports.FndCognitoAuth = void 0;
|
|
16
|
+
exports.hasAnyRole = exports.hasRole = exports.requireRole = exports.requireAdmin = exports.logout = exports.getUserSession = exports.getOptionalUser = exports.requireAuth = exports.createUserSession = exports.getSession = exports.createSessionStorage = exports.NewPasswordRequiredError = exports.AuthError = exports.clearAuthClientCache = exports.FndAuthClient = exports.clearClientCache = exports.refreshAccessToken = exports.authorizerHandler = exports.withCognitoAuth = exports.clearVerifierCache = exports.getVerifier = exports.verifyAndExtract = exports.verifyToken = exports.VALID_STAGES = exports.validateStage = exports.FndCognitoAuth = void 0;
|
|
17
17
|
// ===== CDK Constructs =====
|
|
18
18
|
var cognito_construct_js_1 = require("./cognito-construct.js");
|
|
19
19
|
Object.defineProperty(exports, "FndCognitoAuth", { enumerable: true, get: function () { return cognito_construct_js_1.FndCognitoAuth; } });
|
|
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "FndAuthClient", { enumerable: true, get: functio
|
|
|
42
42
|
Object.defineProperty(exports, "clearAuthClientCache", { enumerable: true, get: function () { return auth_client_js_1.clearClientCache; } });
|
|
43
43
|
var errors_js_1 = require("./client/errors.js");
|
|
44
44
|
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_js_1.AuthError; } });
|
|
45
|
+
Object.defineProperty(exports, "NewPasswordRequiredError", { enumerable: true, get: function () { return errors_js_1.NewPasswordRequiredError; } });
|
|
45
46
|
// ===== Remix Utilities =====
|
|
46
47
|
var session_server_js_1 = require("./remix/session.server.js");
|
|
47
48
|
Object.defineProperty(exports, "createSessionStorage", { enumerable: true, get: function () { return session_server_js_1.createSessionStorage; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,6BAA6B;AAC7B,+DAAwD;AAA/C,sHAAA,cAAc,OAAA;AAEvB,+DAAqE;AAA5D,qHAAA,aAAa,OAAA;AAAE,oHAAA,YAAY,OAAA;AAWpC,4BAA4B;AAC5B,mCAA0F;AAAjF,qGAAA,WAAW,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAAE,qGAAA,WAAW,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAEvE,yBAAyB;AACzB,gDAAuD;AAA9C,0GAAA,eAAe,OAAA;AAOxB,gCAAgC;AAChC,sDAAuE;AAA9D,+GAAA,OAAO,OAAqB;AAErC,8BAA8B;AAC9B,6DAAgF;AAAvE,sHAAA,kBAAkB,OAAA;AAAE,oHAAA,gBAAgB,OAAA;AAG7C,0BAA0B;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verification utilities using aws-jwt-verify.
|
|
4
4
|
*
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
|
-
Object.defineProperty(exports,
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.getVerifier = getVerifier;
|
|
12
12
|
exports.verifyToken = verifyToken;
|
|
13
13
|
exports.verifyAndExtract = verifyAndExtract;
|
|
14
14
|
exports.clearVerifierCache = clearVerifierCache;
|
|
15
|
-
const aws_jwt_verify_1 = require(
|
|
15
|
+
const aws_jwt_verify_1 = require("aws-jwt-verify");
|
|
16
16
|
/** Verifier cache keyed by userPoolId+clientId+tokenUse */
|
|
17
17
|
const verifierCache = new Map();
|
|
18
18
|
/**
|
|
@@ -22,7 +22,7 @@ const verifierCache = new Map();
|
|
|
22
22
|
* @returns Cache key string
|
|
23
23
|
*/
|
|
24
24
|
function getCacheKey(config) {
|
|
25
|
-
|
|
25
|
+
return `${config.userPoolId}:${config.clientId}:${config.tokenUse ?? 'access'}`;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Gets or creates a verifier for the given configuration.
|
|
@@ -40,16 +40,16 @@ function getCacheKey(config) {
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
function getVerifier(config) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
const key = getCacheKey(config);
|
|
44
|
+
if (!verifierCache.has(key)) {
|
|
45
|
+
const verifier = aws_jwt_verify_1.CognitoJwtVerifier.create({
|
|
46
|
+
userPoolId: config.userPoolId,
|
|
47
|
+
clientId: config.clientId,
|
|
48
|
+
tokenUse: config.tokenUse ?? 'access',
|
|
49
|
+
});
|
|
50
|
+
verifierCache.set(key, verifier);
|
|
51
|
+
}
|
|
52
|
+
return verifierCache.get(key);
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Verifies a JWT token from Cognito.
|
|
@@ -69,10 +69,10 @@ function getVerifier(config) {
|
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
async function verifyToken(token, config) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const verifier = getVerifier(config);
|
|
73
|
+
const payload = await verifier.verify(token);
|
|
74
|
+
// Cast through unknown to handle aws-jwt-verify's generic payload type
|
|
75
|
+
return payload;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Verifies a token and returns a normalized result.
|
|
@@ -93,13 +93,13 @@ async function verifyToken(token, config) {
|
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
95
|
async function verifyAndExtract(token, config) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
const payload = await verifyToken(token, config);
|
|
97
|
+
return {
|
|
98
|
+
userId: payload.sub,
|
|
99
|
+
email: 'email' in payload ? payload.email : undefined,
|
|
100
|
+
groups: payload['cognito:groups'] ?? [],
|
|
101
|
+
payload,
|
|
102
|
+
};
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Clears the verifier cache. Useful for testing.
|
|
@@ -112,6 +112,6 @@ async function verifyAndExtract(token, config) {
|
|
|
112
112
|
* ```
|
|
113
113
|
*/
|
|
114
114
|
function clearVerifierCache() {
|
|
115
|
-
|
|
115
|
+
verifierCache.clear();
|
|
116
116
|
}
|
|
117
|
-
//# sourceMappingURL=jwt.js.map
|
|
117
|
+
//# sourceMappingURL=jwt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.server.d.ts","sourceRoot":"","sources":["../../src/remix/session.server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAA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