unjwt 0.5.29 → 0.5.30
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/adapters/h3.d.mts +3 -1
- package/dist/adapters/h3.mjs +45 -29
- package/dist/adapters/h3v1.d.mts +1 -1
- package/dist/adapters/h3v1.mjs +1 -1
- package/dist/adapters/h3v2.d.mts +4 -1
- package/dist/adapters/h3v2.mjs +39 -23
- package/package.json +1 -1
package/dist/adapters/h3.d.mts
CHANGED
|
@@ -14,6 +14,7 @@ interface SessionManager<T extends JWTClaims = JWTClaims, ConfigMaxAge extends E
|
|
|
14
14
|
readonly createdAt: number;
|
|
15
15
|
readonly expiresAt: ConfigMaxAge extends ExpiresIn ? number : T["exp"];
|
|
16
16
|
readonly data: SessionData<T>;
|
|
17
|
+
readonly token: string | undefined;
|
|
17
18
|
update: (update: SessionUpdate<T>) => Promise<SessionManager<T>>;
|
|
18
19
|
clear: () => Promise<SessionManager<T>>;
|
|
19
20
|
}
|
|
@@ -107,6 +108,7 @@ declare function useJWESession<T extends JWTClaims = JWTClaims, MaxAge extends E
|
|
|
107
108
|
* Get (and lazily initialize) the session for the current request.
|
|
108
109
|
*/
|
|
109
110
|
declare function getJWESession<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<SessionJWE<T, MaxAge>>;
|
|
111
|
+
declare function getJWESessionToken<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): string | undefined;
|
|
110
112
|
/**
|
|
111
113
|
* Update the session (optionally mutating the session data) and re-issue the JWE token.
|
|
112
114
|
*/
|
|
@@ -242,5 +244,5 @@ declare function verifyJWSSession<T extends JWTClaims = JWTClaims, MaxAge extend
|
|
|
242
244
|
*/
|
|
243
245
|
declare function clearJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
|
|
244
246
|
|
|
245
|
-
export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
247
|
+
export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
246
248
|
export type { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate };
|
package/dist/adapters/h3.mjs
CHANGED
|
@@ -33,6 +33,9 @@ async function useJWESession(event, config) {
|
|
|
33
33
|
get data() {
|
|
34
34
|
return event.context.sessions?.[sessionName]?.data || {};
|
|
35
35
|
},
|
|
36
|
+
get token() {
|
|
37
|
+
return getJWESessionToken(event, config);
|
|
38
|
+
},
|
|
36
39
|
update: async (update) => {
|
|
37
40
|
if (!isEvent(event)) {
|
|
38
41
|
throw new Error("[h3] Cannot update read-only session.");
|
|
@@ -84,20 +87,7 @@ async function getJWESession(event, config) {
|
|
|
84
87
|
data: /* @__PURE__ */ Object.create(null)
|
|
85
88
|
};
|
|
86
89
|
event.context.sessions[sessionName] = session;
|
|
87
|
-
|
|
88
|
-
if (config.sessionHeader !== false) {
|
|
89
|
-
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
90
|
-
const headerValue = _getReqHeader$1(event, headerName);
|
|
91
|
-
if (typeof headerValue === "string") {
|
|
92
|
-
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!token) {
|
|
96
|
-
const cookieHeader = _getReqHeader$1(event, "cookie");
|
|
97
|
-
if (cookieHeader) {
|
|
98
|
-
token = parse(String(cookieHeader))[sessionName];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
90
|
+
const token = getJWESessionToken(event, config);
|
|
101
91
|
if (token) {
|
|
102
92
|
const promise = unsealJWESession(event, config, token).catch(async (error_) => {
|
|
103
93
|
if (error_ instanceof Error && (error_.message.includes("Token has expired") || error_.message.includes("Token is too old"))) {
|
|
@@ -142,6 +132,24 @@ async function getJWESession(event, config) {
|
|
|
142
132
|
});
|
|
143
133
|
return session;
|
|
144
134
|
}
|
|
135
|
+
function getJWESessionToken(event, config) {
|
|
136
|
+
const sessionName = config.name || DEFAULT_NAME$1;
|
|
137
|
+
let token;
|
|
138
|
+
if (config.sessionHeader !== false) {
|
|
139
|
+
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
140
|
+
const headerValue = _getReqHeader$1(event, headerName);
|
|
141
|
+
if (typeof headerValue === "string") {
|
|
142
|
+
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!token) {
|
|
146
|
+
const cookieHeader = _getReqHeader$1(event, "cookie");
|
|
147
|
+
if (cookieHeader) {
|
|
148
|
+
token = parse(String(cookieHeader))[sessionName];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return token;
|
|
152
|
+
}
|
|
145
153
|
function _getReqHeader$1(event, name) {
|
|
146
154
|
if (event.node) {
|
|
147
155
|
return event.node?.req.headers[name];
|
|
@@ -337,6 +345,9 @@ async function useJWSSession(event, config) {
|
|
|
337
345
|
get data() {
|
|
338
346
|
return event.context.sessions?.[sessionName]?.data || {};
|
|
339
347
|
},
|
|
348
|
+
get token() {
|
|
349
|
+
return getJWSSessionToken(event, config);
|
|
350
|
+
},
|
|
340
351
|
update: async (update) => {
|
|
341
352
|
if (!isEvent(event)) {
|
|
342
353
|
throw new Error("[h3] Cannot update read-only session.");
|
|
@@ -388,20 +399,7 @@ async function getJWSSession(event, config) {
|
|
|
388
399
|
data: /* @__PURE__ */ Object.create(null)
|
|
389
400
|
};
|
|
390
401
|
event.context.sessions[sessionName] = session;
|
|
391
|
-
|
|
392
|
-
if (config.sessionHeader !== false) {
|
|
393
|
-
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
394
|
-
const headerValue = _getReqHeader(event, headerName);
|
|
395
|
-
if (typeof headerValue === "string") {
|
|
396
|
-
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
if (!token) {
|
|
400
|
-
const cookieHeader = _getReqHeader(event, "cookie");
|
|
401
|
-
if (cookieHeader) {
|
|
402
|
-
token = parse(String(cookieHeader))[sessionName];
|
|
403
|
-
}
|
|
404
|
-
}
|
|
402
|
+
const token = getJWSSessionToken(event, config);
|
|
405
403
|
if (token) {
|
|
406
404
|
const promise = verifyJWSSession(event, config, token).catch(async (error_) => {
|
|
407
405
|
if (error_ instanceof Error && (error_.message.includes("Token has expired") || error_.message.includes("Token is too old"))) {
|
|
@@ -446,6 +444,24 @@ async function getJWSSession(event, config) {
|
|
|
446
444
|
});
|
|
447
445
|
return session;
|
|
448
446
|
}
|
|
447
|
+
function getJWSSessionToken(event, config) {
|
|
448
|
+
const sessionName = config.name || DEFAULT_NAME;
|
|
449
|
+
let token;
|
|
450
|
+
if (config.sessionHeader !== false) {
|
|
451
|
+
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
452
|
+
const headerValue = _getReqHeader(event, headerName);
|
|
453
|
+
if (typeof headerValue === "string") {
|
|
454
|
+
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (!token) {
|
|
458
|
+
const cookieHeader = _getReqHeader(event, "cookie");
|
|
459
|
+
if (cookieHeader) {
|
|
460
|
+
token = parse(String(cookieHeader))[sessionName];
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return token;
|
|
464
|
+
}
|
|
449
465
|
function _getReqHeader(event, name) {
|
|
450
466
|
if (event.node) {
|
|
451
467
|
return event.node.req.headers[name];
|
|
@@ -605,4 +621,4 @@ function getVerifyKey(key) {
|
|
|
605
621
|
return _key;
|
|
606
622
|
}
|
|
607
623
|
|
|
608
|
-
export { clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
624
|
+
export { clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
package/dist/adapters/h3v1.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.9mL1vSFP.mjs';
|
|
2
2
|
export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.CtHrClHc.mjs';
|
|
3
|
-
export { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate, clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
|
|
3
|
+
export { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
|
|
4
4
|
export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BjP_dGnX.mjs';
|
|
5
5
|
import 'cookie-es';
|
|
6
6
|
import 'h3';
|
package/dist/adapters/h3v1.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.DyouTtLD.mjs';
|
|
2
|
-
export { clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
|
|
2
|
+
export { clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
|
|
3
3
|
import '../shared/unjwt.Be8NxwFK.mjs';
|
|
4
4
|
import 'h3';
|
|
5
5
|
import 'cookie-es';
|
package/dist/adapters/h3v2.d.mts
CHANGED
|
@@ -14,6 +14,7 @@ interface SessionManager<T extends JWTClaims = JWTClaims, ConfigMaxAge extends E
|
|
|
14
14
|
readonly createdAt: number;
|
|
15
15
|
readonly expiresAt: ConfigMaxAge extends ExpiresIn ? number : T["exp"];
|
|
16
16
|
readonly data: SessionData<T>;
|
|
17
|
+
readonly token: string | undefined;
|
|
17
18
|
update: (update: SessionUpdate<T>) => Promise<SessionManager<T>>;
|
|
18
19
|
clear: () => Promise<SessionManager<T>>;
|
|
19
20
|
}
|
|
@@ -85,6 +86,7 @@ declare function useJWESession<T extends JWTClaims = JWTClaims, MaxAge extends E
|
|
|
85
86
|
* Get the session for the current request.
|
|
86
87
|
*/
|
|
87
88
|
declare function getJWESession<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): Promise<SessionJWE<T, MaxAge>>;
|
|
89
|
+
declare function getJWESessionToken<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): string | undefined;
|
|
88
90
|
/**
|
|
89
91
|
* Update the session data for the current request.
|
|
90
92
|
*/
|
|
@@ -156,10 +158,11 @@ interface SessionConfigJWS<T extends JWTClaims = JWTClaims, MaxAge extends Expir
|
|
|
156
158
|
}
|
|
157
159
|
declare function useJWSSession<T extends JWTClaims, MaxAge extends ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
158
160
|
declare function getJWSSession<T extends JWTClaims, MaxAge extends ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionJWS<T, MaxAge>>;
|
|
161
|
+
declare function getJWSSessionToken<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): string | undefined;
|
|
159
162
|
declare function updateJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWS<T, MaxAge>>;
|
|
160
163
|
declare function signJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<string>;
|
|
161
164
|
declare function verifyJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(_event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
|
|
162
165
|
declare function clearJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
|
|
163
166
|
|
|
164
|
-
export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
167
|
+
export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
165
168
|
export type { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWS, SessionManager, SessionUpdate };
|
package/dist/adapters/h3v2.mjs
CHANGED
|
@@ -28,6 +28,9 @@ async function useJWESession(event, config) {
|
|
|
28
28
|
get data() {
|
|
29
29
|
return getSessionFromContext$1(event, sessionName)?.data || {};
|
|
30
30
|
},
|
|
31
|
+
get token() {
|
|
32
|
+
return getJWESessionToken(event, config);
|
|
33
|
+
},
|
|
31
34
|
update: async (update) => {
|
|
32
35
|
await updateJWESession(event, config, update);
|
|
33
36
|
return sessionManager;
|
|
@@ -74,17 +77,7 @@ async function getJWESession(event, config) {
|
|
|
74
77
|
data: new NullProtoObj()
|
|
75
78
|
};
|
|
76
79
|
context.sessions[sessionName] = session;
|
|
77
|
-
|
|
78
|
-
if (config.sessionHeader !== false) {
|
|
79
|
-
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
80
|
-
const headerValue = event.req.headers.get(headerName);
|
|
81
|
-
if (typeof headerValue === "string") {
|
|
82
|
-
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (!token) {
|
|
86
|
-
token = getChunkedCookie(event, sessionName);
|
|
87
|
-
}
|
|
80
|
+
const token = getJWESessionToken(event, config);
|
|
88
81
|
if (token) {
|
|
89
82
|
const promise = unsealJWESession(event, config, token).catch(async (error_) => {
|
|
90
83
|
if (error_ instanceof Error) {
|
|
@@ -127,6 +120,21 @@ async function getJWESession(event, config) {
|
|
|
127
120
|
});
|
|
128
121
|
return session;
|
|
129
122
|
}
|
|
123
|
+
function getJWESessionToken(event, config) {
|
|
124
|
+
const sessionName = config.name || DEFAULT_NAME$1;
|
|
125
|
+
let token;
|
|
126
|
+
if (config.sessionHeader !== false) {
|
|
127
|
+
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
128
|
+
const headerValue = event.req.headers.get(headerName);
|
|
129
|
+
if (typeof headerValue === "string") {
|
|
130
|
+
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!token) {
|
|
134
|
+
token = getChunkedCookie(event, sessionName);
|
|
135
|
+
}
|
|
136
|
+
return token;
|
|
137
|
+
}
|
|
130
138
|
async function updateJWESession(event, config, update) {
|
|
131
139
|
const sessionName = config.name || DEFAULT_NAME$1;
|
|
132
140
|
const context = getEventContext(event);
|
|
@@ -314,6 +322,9 @@ async function useJWSSession(event, config) {
|
|
|
314
322
|
get data() {
|
|
315
323
|
return getSessionFromContext(event, sessionName)?.data || {};
|
|
316
324
|
},
|
|
325
|
+
get token() {
|
|
326
|
+
return getJWSSessionToken(event, config);
|
|
327
|
+
},
|
|
317
328
|
update: async (update) => {
|
|
318
329
|
await updateJWSSession(event, config, update);
|
|
319
330
|
return sessionManager;
|
|
@@ -360,17 +371,7 @@ async function getJWSSession(event, config) {
|
|
|
360
371
|
data: new NullProtoObj()
|
|
361
372
|
};
|
|
362
373
|
context.sessions[sessionName] = session;
|
|
363
|
-
|
|
364
|
-
if (config.sessionHeader !== false) {
|
|
365
|
-
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
366
|
-
const headerValue = event.req.headers.get(headerName);
|
|
367
|
-
if (typeof headerValue === "string") {
|
|
368
|
-
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (!token) {
|
|
372
|
-
token = getChunkedCookie(event, sessionName);
|
|
373
|
-
}
|
|
374
|
+
const token = getJWSSessionToken(event, config);
|
|
374
375
|
if (token) {
|
|
375
376
|
const promise = verifyJWSSession(event, config, token).catch(async (error_) => {
|
|
376
377
|
if (error_ instanceof Error && (error_.message.includes("Token has expired") || error_.message.includes("Token is too old"))) {
|
|
@@ -410,6 +411,21 @@ async function getJWSSession(event, config) {
|
|
|
410
411
|
});
|
|
411
412
|
return session;
|
|
412
413
|
}
|
|
414
|
+
function getJWSSessionToken(event, config) {
|
|
415
|
+
const sessionName = config.name || DEFAULT_NAME;
|
|
416
|
+
let token;
|
|
417
|
+
if (config.sessionHeader !== false) {
|
|
418
|
+
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
419
|
+
const headerValue = event.req.headers.get(headerName);
|
|
420
|
+
if (typeof headerValue === "string") {
|
|
421
|
+
token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (!token) {
|
|
425
|
+
token = getChunkedCookie(event, sessionName);
|
|
426
|
+
}
|
|
427
|
+
return token;
|
|
428
|
+
}
|
|
413
429
|
async function updateJWSSession(event, config, update) {
|
|
414
430
|
const sessionName = config.name || DEFAULT_NAME;
|
|
415
431
|
const context = getEventContext(event);
|
|
@@ -581,4 +597,4 @@ function getVerifyKey(key) {
|
|
|
581
597
|
return _key;
|
|
582
598
|
}
|
|
583
599
|
|
|
584
|
-
export { clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
600
|
+
export { clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|