@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Remix session management utilities.
|
|
4
4
|
*
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
|
-
Object.defineProperty(exports,
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.createSessionStorage = createSessionStorage;
|
|
12
12
|
exports.resetDefaultStorage = resetDefaultStorage;
|
|
13
13
|
exports.getSession = getSession;
|
|
@@ -16,7 +16,7 @@ exports.requireAuth = requireAuth;
|
|
|
16
16
|
exports.getOptionalUser = getOptionalUser;
|
|
17
17
|
exports.getUserSession = getUserSession;
|
|
18
18
|
exports.logout = logout;
|
|
19
|
-
const node_1 = require(
|
|
19
|
+
const node_1 = require("@remix-run/node");
|
|
20
20
|
/**
|
|
21
21
|
* Default session storage instance.
|
|
22
22
|
* Lazily initialized to avoid accessing env at module load.
|
|
@@ -26,11 +26,11 @@ let defaultSessionStorage = null;
|
|
|
26
26
|
* Cookie configuration for session storage.
|
|
27
27
|
*/
|
|
28
28
|
const COOKIE_CONFIG = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
name: '__fnd_session',
|
|
30
|
+
httpOnly: true,
|
|
31
|
+
maxAge: 60 * 60 * 24 * 7, // 1 week
|
|
32
|
+
path: '/',
|
|
33
|
+
sameSite: 'lax',
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Creates a session storage with the given secret.
|
|
@@ -48,17 +48,17 @@ const COOKIE_CONFIG = {
|
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
function createSessionStorage(secret) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
const sessionSecret = secret ?? process.env.SESSION_SECRET;
|
|
52
|
+
if (!sessionSecret) {
|
|
53
|
+
throw new Error('SESSION_SECRET environment variable is required');
|
|
54
|
+
}
|
|
55
|
+
return (0, node_1.createCookieSessionStorage)({
|
|
56
|
+
cookie: {
|
|
57
|
+
...COOKIE_CONFIG,
|
|
58
|
+
secrets: [sessionSecret],
|
|
59
|
+
secure: process.env.NODE_ENV === 'production',
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Gets the default session storage instance.
|
|
@@ -67,10 +67,10 @@ function createSessionStorage(secret) {
|
|
|
67
67
|
* @internal
|
|
68
68
|
*/
|
|
69
69
|
function getDefaultStorage() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
if (!defaultSessionStorage) {
|
|
71
|
+
defaultSessionStorage = createSessionStorage();
|
|
72
|
+
}
|
|
73
|
+
return defaultSessionStorage;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Resets the default session storage. Useful for testing.
|
|
@@ -78,7 +78,7 @@ function getDefaultStorage() {
|
|
|
78
78
|
* @internal
|
|
79
79
|
*/
|
|
80
80
|
function resetDefaultStorage() {
|
|
81
|
-
|
|
81
|
+
defaultSessionStorage = null;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Gets the session from a request.
|
|
@@ -96,8 +96,8 @@ function resetDefaultStorage() {
|
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
98
|
async function getSession(request, storage) {
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const sessionStorage = storage ?? getDefaultStorage();
|
|
100
|
+
return sessionStorage.getSession(request.headers.get('Cookie'));
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Decodes a JWT token payload (base64).
|
|
@@ -108,13 +108,14 @@ async function getSession(request, storage) {
|
|
|
108
108
|
* @internal
|
|
109
109
|
*/
|
|
110
110
|
function decodeTokenPayload(token) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
try {
|
|
112
|
+
const payload = token.split('.')[1];
|
|
113
|
+
const decoded = Buffer.from(payload, 'base64').toString('utf-8');
|
|
114
|
+
return JSON.parse(decoded);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
118
119
|
}
|
|
119
120
|
/**
|
|
120
121
|
* Creates a user session with authentication tokens and redirects.
|
|
@@ -136,23 +137,23 @@ function decodeTokenPayload(token) {
|
|
|
136
137
|
* ```
|
|
137
138
|
*/
|
|
138
139
|
async function createUserSession(tokens, redirectTo, storage) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
140
|
+
const sessionStorage = storage ?? getDefaultStorage();
|
|
141
|
+
const session = await sessionStorage.getSession();
|
|
142
|
+
// Decode ID token to get user info
|
|
143
|
+
const payload = decodeTokenPayload(tokens.idToken);
|
|
144
|
+
// Store only essential user info in session to stay under cookie size limit (~4KB).
|
|
145
|
+
// We skip storing the full tokens (accessToken, idToken) as they're large JWTs.
|
|
146
|
+
// The refreshToken is stored to enable token refresh for API calls when needed.
|
|
147
|
+
session.set('refreshToken', tokens.refreshToken);
|
|
148
|
+
session.set('expiresAt', Date.now() + tokens.expiresIn * 1000);
|
|
149
|
+
session.set('userId', payload.sub);
|
|
150
|
+
session.set('email', payload.email ?? '');
|
|
151
|
+
session.set('groups', payload['cognito:groups'] ?? []);
|
|
152
|
+
return (0, node_1.redirect)(redirectTo, {
|
|
153
|
+
headers: {
|
|
154
|
+
'Set-Cookie': await sessionStorage.commitSession(session),
|
|
155
|
+
},
|
|
156
|
+
});
|
|
156
157
|
}
|
|
157
158
|
/**
|
|
158
159
|
* Requires authentication for a route.
|
|
@@ -176,19 +177,19 @@ async function createUserSession(tokens, redirectTo, storage) {
|
|
|
176
177
|
* ```
|
|
177
178
|
*/
|
|
178
179
|
async function requireAuth(request, redirectTo = '/login', storage) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
const session = await getSession(request, storage);
|
|
181
|
+
const userId = session.get('userId');
|
|
182
|
+
if (!userId) {
|
|
183
|
+
throw (0, node_1.redirect)(redirectTo);
|
|
184
|
+
}
|
|
185
|
+
// Check if tokens are near expiry (within 5 minutes)
|
|
186
|
+
const expiresAt = session.get('expiresAt');
|
|
187
|
+
if (expiresAt && Date.now() > expiresAt - 5 * 60 * 1000) {
|
|
188
|
+
// Tokens are near expiry
|
|
189
|
+
// In a full implementation, this would refresh tokens
|
|
190
|
+
// For now, we just return the userId as the session is still valid
|
|
191
|
+
}
|
|
192
|
+
return userId;
|
|
192
193
|
}
|
|
193
194
|
/**
|
|
194
195
|
* Gets the optional user from the session.
|
|
@@ -209,16 +210,16 @@ async function requireAuth(request, redirectTo = '/login', storage) {
|
|
|
209
210
|
* ```
|
|
210
211
|
*/
|
|
211
212
|
async function getOptionalUser(request, storage) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
const session = await getSession(request, storage);
|
|
214
|
+
const userId = session.get('userId');
|
|
215
|
+
if (!userId) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
userId,
|
|
220
|
+
email: session.get('email') ?? '',
|
|
221
|
+
groups: session.get('groups') ?? [],
|
|
222
|
+
};
|
|
222
223
|
}
|
|
223
224
|
/**
|
|
224
225
|
* Gets full session data including tokens.
|
|
@@ -243,20 +244,22 @@ async function getOptionalUser(request, storage) {
|
|
|
243
244
|
* ```
|
|
244
245
|
*/
|
|
245
246
|
async function getUserSession(request, storage) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
247
|
+
const session = await getSession(request, storage);
|
|
248
|
+
const userId = session.get('userId');
|
|
249
|
+
if (!userId) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
// Note: accessToken and idToken are not stored in session to stay under cookie limits.
|
|
254
|
+
// Use refreshToken to obtain fresh tokens when needed for API calls.
|
|
255
|
+
accessToken: session.get('accessToken'),
|
|
256
|
+
idToken: session.get('idToken'),
|
|
257
|
+
refreshToken: session.get('refreshToken'),
|
|
258
|
+
expiresAt: session.get('expiresAt'),
|
|
259
|
+
userId,
|
|
260
|
+
email: session.get('email') ?? '',
|
|
261
|
+
groups: session.get('groups') ?? [],
|
|
262
|
+
};
|
|
260
263
|
}
|
|
261
264
|
/**
|
|
262
265
|
* Logs out the user and redirects to the login page.
|
|
@@ -276,12 +279,12 @@ async function getUserSession(request, storage) {
|
|
|
276
279
|
* ```
|
|
277
280
|
*/
|
|
278
281
|
async function logout(request, redirectTo = '/login', storage) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
282
|
+
const sessionStorage = storage ?? getDefaultStorage();
|
|
283
|
+
const session = await getSession(request, storage);
|
|
284
|
+
return (0, node_1.redirect)(redirectTo, {
|
|
285
|
+
headers: {
|
|
286
|
+
'Set-Cookie': await sessionStorage.destroySession(session),
|
|
287
|
+
},
|
|
288
|
+
});
|
|
286
289
|
}
|
|
287
|
-
//# sourceMappingURL=session.server.js.map
|
|
290
|
+
//# sourceMappingURL=session.server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.server.js","sourceRoot":"","sources":["../../src/remix/session.server.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAsCH,oDAcC;AAoBD,kDAEC;AAiBD,gCAGC;AAuCD,8CAyBC;AAuBD,kCAqBC;AAoBD,0CAgBC;AAwBD,
|
|
1
|
+
{"version":3,"file":"session.server.js","sourceRoot":"","sources":["../../src/remix/session.server.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAsCH,oDAcC;AAoBD,kDAEC;AAiBD,gCAGC;AAuCD,8CAyBC;AAuBD,kCAqBC;AAoBD,0CAgBC;AAwBD,wCAsBC;AAmBD,wBAaC;AA1TD,0CAAuE;AAIvE;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-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
/** User's unique identifier */
|
|
11
|
+
sub: string;
|
|
12
|
+
/** Cognito groups the user belongs to */
|
|
13
|
+
'cognito:groups'?: string[];
|
|
14
|
+
/** Token use type */
|
|
15
|
+
token_use: 'access';
|
|
16
|
+
/** Token scopes */
|
|
17
|
+
scope?: string;
|
|
18
|
+
/** Issuer URL */
|
|
19
|
+
iss: string;
|
|
20
|
+
/** Expiration timestamp */
|
|
21
|
+
exp: number;
|
|
22
|
+
/** Issued at timestamp */
|
|
23
|
+
iat: number;
|
|
24
|
+
/** Client ID */
|
|
25
|
+
client_id: string;
|
|
26
|
+
/** Username */
|
|
27
|
+
username: string;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Cognito JWT payload structure from ID token.
|
|
31
31
|
*/
|
|
32
32
|
export interface CognitoIdTokenPayload {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
33
|
+
/** User's unique identifier */
|
|
34
|
+
sub: string;
|
|
35
|
+
/** User's email address */
|
|
36
|
+
email?: string;
|
|
37
|
+
/** Whether email is verified */
|
|
38
|
+
email_verified?: boolean;
|
|
39
|
+
/** Cognito groups the user belongs to */
|
|
40
|
+
'cognito:groups'?: string[];
|
|
41
|
+
/** Cognito username */
|
|
42
|
+
'cognito:username'?: string;
|
|
43
|
+
/** Token use type */
|
|
44
|
+
token_use: 'id';
|
|
45
|
+
/** Issuer URL */
|
|
46
|
+
iss: string;
|
|
47
|
+
/** Expiration timestamp */
|
|
48
|
+
exp: number;
|
|
49
|
+
/** Issued at timestamp */
|
|
50
|
+
iat: number;
|
|
51
|
+
/** Audience (client ID) */
|
|
52
|
+
aud: string;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Configuration for JWT verification.
|
|
56
56
|
*/
|
|
57
57
|
export interface JwtVerifierConfig {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
/** Cognito User Pool ID */
|
|
59
|
+
userPoolId: string;
|
|
60
|
+
/** Cognito Client ID */
|
|
61
|
+
clientId: string;
|
|
62
|
+
/** Token type to verify */
|
|
63
|
+
tokenUse?: 'access' | 'id';
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Configuration options for the auth middleware.
|
|
67
67
|
*/
|
|
68
68
|
export interface CognitoAuthOptions {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
/** Cognito User Pool ID (defaults to COGNITO_USER_POOL_ID env var) */
|
|
70
|
+
userPoolId?: string;
|
|
71
|
+
/** Cognito Client ID (defaults to COGNITO_CLIENT_ID env var) */
|
|
72
|
+
clientId?: string;
|
|
73
|
+
/** Required roles (Cognito groups). User must have at least one. */
|
|
74
|
+
roles?: string[];
|
|
75
|
+
/** Paths to skip authentication for */
|
|
76
|
+
skipPaths?: string[];
|
|
77
|
+
/** Token type to verify */
|
|
78
|
+
tokenUse?: 'access' | 'id';
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Result of successful token verification.
|
|
82
82
|
*/
|
|
83
83
|
export interface TokenVerificationResult {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
/** User ID (sub claim) */
|
|
85
|
+
userId: string;
|
|
86
|
+
/** User email (from ID token or access token if present) */
|
|
87
|
+
email?: string;
|
|
88
|
+
/** User's Cognito groups */
|
|
89
|
+
groups: string[];
|
|
90
|
+
/** Raw token payload */
|
|
91
|
+
payload: CognitoAccessTokenPayload | CognitoIdTokenPayload;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Configuration for FndAuthClient.
|
|
95
95
|
*/
|
|
96
96
|
export interface AuthClientConfig {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
/** Cognito User Pool ID */
|
|
98
|
+
userPoolId: string;
|
|
99
|
+
/** Cognito Client ID */
|
|
100
|
+
clientId: string;
|
|
101
|
+
/** AWS region (defaults to AWS_REGION env var) */
|
|
102
|
+
region?: string;
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Authentication tokens returned from Cognito.
|
|
106
106
|
*/
|
|
107
107
|
export interface AuthTokens {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
/** JWT access token */
|
|
109
|
+
accessToken: string;
|
|
110
|
+
/** JWT ID token */
|
|
111
|
+
idToken: string;
|
|
112
|
+
/** Refresh token for obtaining new tokens */
|
|
113
|
+
refreshToken: string;
|
|
114
|
+
/** Token expiration in seconds */
|
|
115
|
+
expiresIn: number;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Result of sign-up operation.
|
|
119
119
|
*/
|
|
120
120
|
export interface SignUpResult {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
121
|
+
/** Whether user confirmation is required */
|
|
122
|
+
userConfirmed: boolean;
|
|
123
|
+
/** Delivery details for confirmation code (if applicable) */
|
|
124
|
+
codeDeliveryDetails?: {
|
|
125
|
+
/** Destination (masked email/phone) */
|
|
126
|
+
destination?: string;
|
|
127
|
+
/** Delivery medium */
|
|
128
|
+
deliveryMedium?: 'EMAIL' | 'SMS';
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Challenge types that may be returned during sign-in.
|
|
133
|
+
*/
|
|
134
|
+
export type AuthChallenge = 'NEW_PASSWORD_REQUIRED' | 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA';
|
|
135
|
+
/**
|
|
136
|
+
* Result of sign-in operation.
|
|
137
|
+
*
|
|
138
|
+
* May return either tokens (successful auth) or a challenge (requires additional action).
|
|
139
|
+
*/
|
|
140
|
+
export type SignInResult = {
|
|
141
|
+
success: true;
|
|
142
|
+
tokens: AuthTokens;
|
|
143
|
+
} | {
|
|
144
|
+
success: false;
|
|
145
|
+
challenge: AuthChallenge;
|
|
146
|
+
session: string;
|
|
147
|
+
email: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Result of forgot password initiation.
|
|
151
|
+
*/
|
|
152
|
+
export interface ForgotPasswordResult {
|
|
153
|
+
/** Delivery details for reset code */
|
|
154
|
+
codeDeliveryDetails?: {
|
|
155
|
+
/** Destination (masked email/phone) */
|
|
156
|
+
destination?: string;
|
|
157
|
+
/** Delivery medium */
|
|
158
|
+
deliveryMedium?: 'EMAIL' | 'SMS';
|
|
159
|
+
};
|
|
130
160
|
}
|
|
131
161
|
/**
|
|
132
162
|
* Session data stored in cookies.
|
|
163
|
+
*
|
|
164
|
+
* Note: accessToken and idToken are optional because they are not stored
|
|
165
|
+
* in the cookie session to stay under browser cookie size limits (~4KB).
|
|
166
|
+
* Use the refreshToken to obtain fresh tokens when needed for API calls.
|
|
133
167
|
*/
|
|
134
168
|
export interface SessionData {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
169
|
+
/** JWT access token (not stored in session, use refreshToken to obtain) */
|
|
170
|
+
accessToken?: string;
|
|
171
|
+
/** JWT ID token (not stored in session, use refreshToken to obtain) */
|
|
172
|
+
idToken?: string;
|
|
173
|
+
/** Refresh token */
|
|
174
|
+
refreshToken: string;
|
|
175
|
+
/** Expiration timestamp (ms since epoch) */
|
|
176
|
+
expiresAt: number;
|
|
177
|
+
/** User ID (sub claim) */
|
|
178
|
+
userId: string;
|
|
179
|
+
/** User email */
|
|
180
|
+
email: string;
|
|
181
|
+
/** User's Cognito groups */
|
|
182
|
+
groups: string[];
|
|
149
183
|
}
|
|
150
184
|
/**
|
|
151
185
|
* User information extracted from session.
|
|
152
186
|
*/
|
|
153
187
|
export interface SessionUser {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
188
|
+
/** User ID */
|
|
189
|
+
userId: string;
|
|
190
|
+
/** User email */
|
|
191
|
+
email: string;
|
|
192
|
+
/** User's groups/roles */
|
|
193
|
+
groups: string[];
|
|
160
194
|
}
|
|
161
|
-
//# sourceMappingURL=types.d.ts.map
|
|
195
|
+
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,qBAAqB;IACrB,SAAS,EAAE,QAAQ,CAAC;IACpB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB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AK,CAAC;IAAC,SAAS,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,sCAAsC;IACtC,mBAAmB,CAAC,EAAE;QACpB,uCAAuC;QACvC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,sBAAsB;QACtB,cAAc,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;KAClC,CAAC;CACH;AAID;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,cAAc;IACd,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB"}
|
package/lib/types.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Type definitions for cognito-auth middleware and utilities.
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
//# sourceMappingURL=types.js.map
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
//# sourceMappingURL=types.js.map
|