@workos/authkit-session 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -27
- package/dist/core/AuthKitCore.d.ts +20 -0
- package/dist/core/AuthKitCore.d.ts.map +1 -1
- package/dist/core/AuthKitCore.js +36 -4
- package/dist/core/AuthKitCore.js.map +1 -1
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts +2 -1
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts.map +1 -1
- package/dist/core/encryption/ironWebcryptoEncryption.js +2 -2
- package/dist/core/encryption/ironWebcryptoEncryption.js.map +1 -1
- package/dist/core/errors.d.ts +9 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +18 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/pkce/cookieOptions.d.ts +36 -0
- package/dist/core/pkce/cookieOptions.d.ts.map +1 -0
- package/dist/core/pkce/cookieOptions.js +55 -0
- package/dist/core/pkce/cookieOptions.js.map +1 -0
- package/dist/core/pkce/generateAuthorizationUrl.d.ts +45 -0
- package/dist/core/pkce/generateAuthorizationUrl.d.ts.map +1 -0
- package/dist/core/pkce/generateAuthorizationUrl.js +82 -0
- package/dist/core/pkce/generateAuthorizationUrl.js.map +1 -0
- package/dist/core/pkce/state.d.ts +53 -0
- package/dist/core/pkce/state.d.ts.map +1 -0
- package/dist/core/pkce/state.js +91 -0
- package/dist/core/pkce/state.js.map +1 -0
- package/dist/core/session/CookieSessionStorage.d.ts +25 -15
- package/dist/core/session/CookieSessionStorage.d.ts.map +1 -1
- package/dist/core/session/CookieSessionStorage.js +20 -27
- package/dist/core/session/CookieSessionStorage.js.map +1 -1
- package/dist/core/session/TokenManager.js +2 -2
- package/dist/core/session/TokenManager.js.map +1 -1
- package/dist/core/session/serializeCookie.d.ts +13 -0
- package/dist/core/session/serializeCookie.d.ts.map +1 -0
- package/dist/core/session/serializeCookie.js +32 -0
- package/dist/core/session/serializeCookie.js.map +1 -0
- package/dist/core/session/types.d.ts +71 -2
- package/dist/core/session/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/operations/AuthOperations.d.ts +15 -13
- package/dist/operations/AuthOperations.d.ts.map +1 -1
- package/dist/operations/AuthOperations.js +22 -34
- package/dist/operations/AuthOperations.js.map +1 -1
- package/dist/service/AuthService.d.ts +58 -15
- package/dist/service/AuthService.d.ts.map +1 -1
- package/dist/service/AuthService.js +157 -71
- package/dist/service/AuthService.js.map +1 -1
- package/dist/service/factory.d.ts.map +1 -1
- package/dist/service/factory.js +4 -3
- package/dist/service/factory.js.map +1 -1
- package/dist/utils.d.ts +16 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +23 -0
- package/dist/utils.js.map +1 -1
- package/package.json +23 -20
- package/src/core/AuthKitCore.spec.ts +109 -0
- package/src/core/AuthKitCore.ts +55 -4
- package/src/core/encryption/ironWebcryptoEncryption.spec.ts +62 -0
- package/src/core/encryption/ironWebcryptoEncryption.ts +2 -2
- package/src/core/errors.spec.ts +33 -142
- package/src/core/errors.ts +21 -0
- package/src/core/pkce/cookieOptions.spec.ts +144 -0
- package/src/core/pkce/cookieOptions.ts +64 -0
- package/src/core/pkce/generateAuthorizationUrl.ts +123 -0
- package/src/core/pkce/pkce.spec.ts +166 -0
- package/src/core/pkce/state.spec.ts +216 -0
- package/src/core/pkce/state.ts +120 -0
- package/src/core/session/CookieSessionStorage.spec.ts +79 -3
- package/src/core/session/CookieSessionStorage.ts +56 -36
- package/src/core/session/TokenManager.ts +2 -2
- package/src/core/session/serializeCookie.ts +33 -0
- package/src/core/session/types.ts +79 -2
- package/src/index.ts +3 -0
- package/src/operations/AuthOperations.spec.ts +107 -62
- package/src/operations/AuthOperations.ts +34 -40
- package/src/service/AuthService.spec.ts +615 -98
- package/src/service/AuthService.ts +198 -73
- package/src/service/factory.spec.ts +4 -3
- package/src/service/factory.ts +6 -3
- package/src/utils.ts +22 -0
package/dist/service/factory.js
CHANGED
|
@@ -50,9 +50,10 @@ export function createAuthService(options) {
|
|
|
50
50
|
signOut: (sessionId, opts) => getService().signOut(sessionId, opts),
|
|
51
51
|
switchOrganization: (session, organizationId) => getService().switchOrganization(session, organizationId),
|
|
52
52
|
refreshSession: (session, organizationId) => getService().refreshSession(session, organizationId),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
createAuthorization: (response, opts) => getService().createAuthorization(response, opts),
|
|
54
|
+
createSignIn: (response, opts) => getService().createSignIn(response, opts),
|
|
55
|
+
createSignUp: (response, opts) => getService().createSignUp(response, opts),
|
|
56
|
+
clearPendingVerifier: (response, opts) => getService().clearPendingVerifier(response, opts),
|
|
56
57
|
getWorkOS: () => getService().getWorkOS(),
|
|
57
58
|
handleCallback: (request, response, opts) => getService().handleCallback(request, response, opts),
|
|
58
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/service/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAK9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,iBAAiB,CAAsB,OAMtD;IACC,MAAM,EACJ,qBAAqB,EACrB,aAAa,GAAG,GAAG,EAAE,CAAC,SAAS,EAAE,EACjC,iBAAiB,GAAG,GAAG,EAAE,CAAC,iBAAiB,GAC5C,GAAG,OAAO,CAAC;IAEZ,0DAA0D;IAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE;QAC3B,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,yDAAyD;IACzD,sFAAsF;IACtF,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;QACnD,UAAU,EAAE,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QACvD,WAAW,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,CACrC,UAAU,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC;QACjD,YAAY,EAAE,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC;QAC7D,OAAO,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;QACnE,kBAAkB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,CAC9C,UAAU,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC;QAC1D,cAAc,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,CAC1C,UAAU,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC;QACtD,mBAAmB,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/service/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAK9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,iBAAiB,CAAsB,OAMtD;IACC,MAAM,EACJ,qBAAqB,EACrB,aAAa,GAAG,GAAG,EAAE,CAAC,SAAS,EAAE,EACjC,iBAAiB,GAAG,GAAG,EAAE,CAAC,iBAAiB,GAC5C,GAAG,OAAO,CAAC;IAEZ,0DAA0D;IAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE;QAC3B,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,yDAAyD;IACzD,sFAAsF;IACtF,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;QACnD,UAAU,EAAE,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QACvD,WAAW,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,CACrC,UAAU,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC;QACjD,YAAY,EAAE,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC;QAC7D,OAAO,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;QACnE,kBAAkB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,CAC9C,UAAU,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,CAAC;QAC1D,cAAc,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,CAC1C,UAAU,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC;QACtD,mBAAmB,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CACtC,UAAU,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC;QAClD,YAAY,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC;QAC3E,YAAY,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC;QAC3E,oBAAoB,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CACvC,UAAU,EAAE,CAAC,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC;QACnD,SAAS,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE;QACzC,cAAc,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAC1C,UAAU,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC;KACnB,CAAC;AACxC,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -6,4 +6,20 @@
|
|
|
6
6
|
* @returns A function that can only be called once.
|
|
7
7
|
*/
|
|
8
8
|
export declare function once<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
|
|
9
|
+
/**
|
|
10
|
+
* Constant-time byte-array equality.
|
|
11
|
+
*
|
|
12
|
+
* Used for comparing security-sensitive values (OAuth state, tokens, MACs)
|
|
13
|
+
* where early-return on mismatch would leak timing information about how
|
|
14
|
+
* many leading bytes matched.
|
|
15
|
+
*
|
|
16
|
+
* Runtime-portable: no `node:crypto`, no `Buffer` — works in Node, browsers,
|
|
17
|
+
* and edge runtimes. Callers produce `Uint8Array`s via `TextEncoder`.
|
|
18
|
+
*
|
|
19
|
+
* Contract:
|
|
20
|
+
* - Returns false immediately if lengths differ (length is not secret).
|
|
21
|
+
* - Once past the length gate, inspects EVERY byte regardless of mismatches.
|
|
22
|
+
* - No branches whose count depends on byte values.
|
|
23
|
+
*/
|
|
24
|
+
export declare function constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
9
25
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EACnD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAC9B,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAW7B"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EACnD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAC9B,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAW7B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAKvE"}
|
package/dist/utils.js
CHANGED
|
@@ -16,4 +16,27 @@ export function once(fn) {
|
|
|
16
16
|
return result;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Constant-time byte-array equality.
|
|
21
|
+
*
|
|
22
|
+
* Used for comparing security-sensitive values (OAuth state, tokens, MACs)
|
|
23
|
+
* where early-return on mismatch would leak timing information about how
|
|
24
|
+
* many leading bytes matched.
|
|
25
|
+
*
|
|
26
|
+
* Runtime-portable: no `node:crypto`, no `Buffer` — works in Node, browsers,
|
|
27
|
+
* and edge runtimes. Callers produce `Uint8Array`s via `TextEncoder`.
|
|
28
|
+
*
|
|
29
|
+
* Contract:
|
|
30
|
+
* - Returns false immediately if lengths differ (length is not secret).
|
|
31
|
+
* - Once past the length gate, inspects EVERY byte regardless of mismatches.
|
|
32
|
+
* - No branches whose count depends on byte values.
|
|
33
|
+
*/
|
|
34
|
+
export function constantTimeEqual(a, b) {
|
|
35
|
+
if (a.length !== b.length)
|
|
36
|
+
return false;
|
|
37
|
+
let diff = 0;
|
|
38
|
+
for (let i = 0; i < a.length; i++)
|
|
39
|
+
diff |= a[i] ^ b[i];
|
|
40
|
+
return diff === 0;
|
|
41
|
+
}
|
|
19
42
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAClB,EAA+B;IAE/B,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,MAAe,CAAC;IAEpB,OAAO,CAAC,GAAG,IAAW,EAAW,EAAE;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACrB,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAClB,EAA+B;IAE/B,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,MAAe,CAAC;IAEpB,OAAO,CAAC,GAAG,IAAW,EAAW,EAAE;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACrB,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAa,EAAE,CAAa;IAC5D,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IACzD,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workos/authkit-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Framework-agnostic authentication library for WorkOS with pluggable storage adapters",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "WorkOS",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/workos/authkit-session.git"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"src",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
5
17
|
"type": "module",
|
|
6
18
|
"main": "./dist/index.js",
|
|
7
19
|
"types": "./dist/index.d.ts",
|
|
@@ -11,40 +23,31 @@
|
|
|
11
23
|
"default": "./dist/index.js"
|
|
12
24
|
}
|
|
13
25
|
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"url": "https://github.com/workos/authkit-session.git"
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@workos-inc/node": "^8.0.0",
|
|
28
|
+
"iron-webcrypto": "^2.0.0",
|
|
29
|
+
"jose": "^6.1.3",
|
|
30
|
+
"valibot": "^1.3.1"
|
|
20
31
|
},
|
|
21
32
|
"devDependencies": {
|
|
22
33
|
"@types/node": "^20.17.0",
|
|
23
34
|
"@vitest/coverage-v8": "^4.0.17",
|
|
24
|
-
"
|
|
35
|
+
"oxfmt": "^0.42.0",
|
|
36
|
+
"oxlint": "^1.57.0",
|
|
25
37
|
"typescript": "^5.9.3",
|
|
26
38
|
"vitest": "^4.0.17"
|
|
27
39
|
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@workos-inc/node": "8.0.0",
|
|
30
|
-
"iron-webcrypto": "^2.0.0",
|
|
31
|
-
"jose": "^6.1.3"
|
|
32
|
-
},
|
|
33
40
|
"engines": {
|
|
34
41
|
"node": ">=20.0.0"
|
|
35
42
|
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist",
|
|
38
|
-
"src",
|
|
39
|
-
"README.md"
|
|
40
|
-
],
|
|
41
43
|
"scripts": {
|
|
42
44
|
"clean": "rm -rf dist",
|
|
43
45
|
"build": "tsc -p tsconfig.build.json",
|
|
44
46
|
"rebuild": "pnpm run clean && pnpm run build",
|
|
45
47
|
"dev": "tsc -p tsconfig.build.json --watch",
|
|
46
|
-
"
|
|
47
|
-
"format": "
|
|
48
|
+
"format": "oxfmt --write .",
|
|
49
|
+
"format:check": "oxfmt --check .",
|
|
50
|
+
"lint": "oxlint .",
|
|
48
51
|
"typecheck": "tsc --noEmit",
|
|
49
52
|
"test": "vitest --run",
|
|
50
53
|
"test:coverage": "vitest --run --coverage",
|
|
@@ -259,4 +259,113 @@ describe('AuthKitCore', () => {
|
|
|
259
259
|
);
|
|
260
260
|
});
|
|
261
261
|
});
|
|
262
|
+
|
|
263
|
+
describe('validateAndRefresh()', () => {
|
|
264
|
+
// Decodable JWT with sid + exp + org_id. Signature is garbage → verifyToken false.
|
|
265
|
+
const oldJwt =
|
|
266
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsInNpZCI6InNlc3Npb25fOTk5IiwiZXhwIjoxMDAwMDAwMDAwLCJvcmdfaWQiOiJvcmdfYWJjIn0.sig';
|
|
267
|
+
const newJwt =
|
|
268
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsInNpZCI6InNlc3Npb25fbmV3IiwiZXhwIjozMDAwMDAwMDAwfQ.sig';
|
|
269
|
+
|
|
270
|
+
function makeRefreshClient(capture?: { opts?: any }) {
|
|
271
|
+
return {
|
|
272
|
+
userManagement: {
|
|
273
|
+
getJwksUrl: () => 'https://api.workos.com/sso/jwks/test-client-id',
|
|
274
|
+
authenticateWithRefreshToken: async (opts: any) => {
|
|
275
|
+
if (capture) capture.opts = opts;
|
|
276
|
+
return {
|
|
277
|
+
accessToken: newJwt,
|
|
278
|
+
refreshToken: 'new-rt',
|
|
279
|
+
user: mockUser,
|
|
280
|
+
impersonator: undefined,
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
it('forces refresh when token invalid and returns new session', async () => {
|
|
288
|
+
const testCore = new AuthKitCore(
|
|
289
|
+
mockConfig as any,
|
|
290
|
+
makeRefreshClient() as any,
|
|
291
|
+
mockEncryption as any,
|
|
292
|
+
);
|
|
293
|
+
const session = {
|
|
294
|
+
accessToken: oldJwt,
|
|
295
|
+
refreshToken: 'rt',
|
|
296
|
+
user: mockUser,
|
|
297
|
+
impersonator: undefined,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const result = await testCore.validateAndRefresh(session);
|
|
301
|
+
|
|
302
|
+
expect(result.refreshed).toBe(true);
|
|
303
|
+
expect(result.session.accessToken).toBe(newJwt);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('propagates explicit organizationId into refresh', async () => {
|
|
307
|
+
const capture: { opts?: any } = {};
|
|
308
|
+
const testCore = new AuthKitCore(
|
|
309
|
+
mockConfig as any,
|
|
310
|
+
makeRefreshClient(capture) as any,
|
|
311
|
+
mockEncryption as any,
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
await testCore.validateAndRefresh(
|
|
315
|
+
{
|
|
316
|
+
accessToken: oldJwt,
|
|
317
|
+
refreshToken: 'rt',
|
|
318
|
+
user: mockUser,
|
|
319
|
+
impersonator: undefined,
|
|
320
|
+
},
|
|
321
|
+
{ organizationId: 'org_explicit' },
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
expect(capture.opts?.organizationId).toBe('org_explicit');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('continues when access token is unparseable', async () => {
|
|
328
|
+
const testCore = new AuthKitCore(
|
|
329
|
+
mockConfig as any,
|
|
330
|
+
makeRefreshClient() as any,
|
|
331
|
+
mockEncryption as any,
|
|
332
|
+
);
|
|
333
|
+
const session = {
|
|
334
|
+
accessToken: 'not-a-jwt',
|
|
335
|
+
refreshToken: 'rt',
|
|
336
|
+
user: mockUser,
|
|
337
|
+
impersonator: undefined,
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const result = await testCore.validateAndRefresh(session);
|
|
341
|
+
|
|
342
|
+
expect(result.refreshed).toBe(true);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe('verifyCallbackState()', () => {
|
|
347
|
+
it('throws OAuthStateMismatchError when stateFromUrl missing', async () => {
|
|
348
|
+
await expect(
|
|
349
|
+
core.verifyCallbackState({
|
|
350
|
+
stateFromUrl: undefined,
|
|
351
|
+
cookieValue: 'x',
|
|
352
|
+
}),
|
|
353
|
+
).rejects.toMatchObject({ name: 'OAuthStateMismatchError' });
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('throws PKCECookieMissingError when cookie missing', async () => {
|
|
357
|
+
await expect(
|
|
358
|
+
core.verifyCallbackState({
|
|
359
|
+
stateFromUrl: 'x',
|
|
360
|
+
cookieValue: undefined,
|
|
361
|
+
}),
|
|
362
|
+
).rejects.toMatchObject({ name: 'PKCECookieMissingError' });
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('throws OAuthStateMismatchError when values differ', async () => {
|
|
366
|
+
await expect(
|
|
367
|
+
core.verifyCallbackState({ stateFromUrl: 'a', cookieValue: 'b' }),
|
|
368
|
+
).rejects.toMatchObject({ name: 'OAuthStateMismatchError' });
|
|
369
|
+
});
|
|
370
|
+
});
|
|
262
371
|
});
|
package/src/core/AuthKitCore.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { Impersonator, User, WorkOS } from '@workos-inc/node';
|
|
2
2
|
import { createRemoteJWKSet, decodeJwt, jwtVerify } from 'jose';
|
|
3
|
-
import { once } from '../utils.js';
|
|
3
|
+
import { constantTimeEqual, once } from '../utils.js';
|
|
4
4
|
import type { AuthKitConfig } from './config/types.js';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
OAuthStateMismatchError,
|
|
7
|
+
PKCECookieMissingError,
|
|
8
|
+
SessionEncryptionError,
|
|
9
|
+
TokenRefreshError,
|
|
10
|
+
} from './errors.js';
|
|
11
|
+
import { type PKCEState, unsealState } from './pkce/state.js';
|
|
6
12
|
import type {
|
|
7
13
|
BaseTokenClaims,
|
|
8
14
|
CustomClaims,
|
|
@@ -104,8 +110,8 @@ export class AuthKitCore {
|
|
|
104
110
|
): BaseTokenClaims & TCustomClaims {
|
|
105
111
|
try {
|
|
106
112
|
return decodeJwt<BaseTokenClaims & TCustomClaims>(token);
|
|
107
|
-
} catch (
|
|
108
|
-
throw new Error('Invalid token');
|
|
113
|
+
} catch (cause) {
|
|
114
|
+
throw new Error('Invalid token', { cause });
|
|
109
115
|
}
|
|
110
116
|
}
|
|
111
117
|
|
|
@@ -147,6 +153,51 @@ export class AuthKitCore {
|
|
|
147
153
|
}
|
|
148
154
|
}
|
|
149
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Verify the OAuth callback state against the PKCE verifier cookie and
|
|
158
|
+
* return the unsealed state blob.
|
|
159
|
+
*
|
|
160
|
+
* Core owns encryption, so verification lives here rather than on
|
|
161
|
+
* AuthService. Byte-compares the query-string `state` against the cookie
|
|
162
|
+
* value BEFORE attempting to decrypt — smaller crypto attack surface and
|
|
163
|
+
* no decryption cost on obvious mismatches.
|
|
164
|
+
*
|
|
165
|
+
* @throws {OAuthStateMismatchError} state missing or does not match cookie
|
|
166
|
+
* @throws {PKCECookieMissingError} cookie not sent — typically a proxy or
|
|
167
|
+
* Set-Cookie propagation issue on the adapter's callback path
|
|
168
|
+
* @throws {SessionEncryptionError} seal tampered, wrong password, TTL expired,
|
|
169
|
+
* or schema mismatch on the unsealed payload
|
|
170
|
+
*/
|
|
171
|
+
async verifyCallbackState(params: {
|
|
172
|
+
stateFromUrl: string | undefined;
|
|
173
|
+
cookieValue: string | undefined;
|
|
174
|
+
}): Promise<PKCEState> {
|
|
175
|
+
const { stateFromUrl, cookieValue } = params;
|
|
176
|
+
|
|
177
|
+
if (!stateFromUrl) {
|
|
178
|
+
throw new OAuthStateMismatchError(
|
|
179
|
+
'Missing state parameter from callback URL',
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
if (!cookieValue) {
|
|
183
|
+
throw new PKCECookieMissingError(
|
|
184
|
+
'PKCE verifier cookie missing — cannot verify OAuth state. Ensure Set-Cookie headers are propagated on redirects.',
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const encoder = new TextEncoder();
|
|
188
|
+
const urlBytes = encoder.encode(stateFromUrl);
|
|
189
|
+
const cookieBytes = encoder.encode(cookieValue);
|
|
190
|
+
if (!constantTimeEqual(urlBytes, cookieBytes)) {
|
|
191
|
+
throw new OAuthStateMismatchError('OAuth state mismatch');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return unsealState(
|
|
195
|
+
this.encryption,
|
|
196
|
+
this.config.cookiePassword,
|
|
197
|
+
cookieValue,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
150
201
|
/**
|
|
151
202
|
* Refresh tokens using WorkOS API.
|
|
152
203
|
*
|
|
@@ -64,4 +64,66 @@ describe('ironWebcryptoEncryption', () => {
|
|
|
64
64
|
expect(unsealed).toEqual(testData);
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
describe('TTL enforcement', () => {
|
|
69
|
+
beforeEach(() => {
|
|
70
|
+
vi.useFakeTimers();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
vi.useRealTimers();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('unseals successfully before TTL expires', async () => {
|
|
78
|
+
vi.setSystemTime(new Date('2026-01-01T00:00:00.000Z'));
|
|
79
|
+
const sealed = await encryption.sealData(testData, {
|
|
80
|
+
password: testPassword,
|
|
81
|
+
ttl: 600,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Advance less than TTL
|
|
85
|
+
vi.setSystemTime(new Date('2026-01-01T00:09:00.000Z')); // +540s
|
|
86
|
+
const unsealed = await encryption.unsealData(sealed, {
|
|
87
|
+
password: testPassword,
|
|
88
|
+
ttl: 600,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(unsealed).toEqual(testData);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('throws when TTL has expired on unseal', async () => {
|
|
95
|
+
vi.setSystemTime(new Date('2026-01-01T00:00:00.000Z'));
|
|
96
|
+
const sealed = await encryption.sealData(testData, {
|
|
97
|
+
password: testPassword,
|
|
98
|
+
ttl: 1,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Advance past TTL + skew (60s default)
|
|
102
|
+
vi.setSystemTime(new Date('2026-01-01T00:02:00.000Z'));
|
|
103
|
+
await expect(
|
|
104
|
+
encryption.unsealData(sealed, {
|
|
105
|
+
password: testPassword,
|
|
106
|
+
ttl: 1,
|
|
107
|
+
}),
|
|
108
|
+
).rejects.toThrow();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('preserves session-cookie flow: seal without TTL, unseal without TTL', async () => {
|
|
112
|
+
// This is the invariant AuthKitCore.encryptSession/decryptSession relies on.
|
|
113
|
+
vi.setSystemTime(new Date('2026-01-01T00:00:00.000Z'));
|
|
114
|
+
const sealed = await encryption.sealData(testData, {
|
|
115
|
+
password: testPassword,
|
|
116
|
+
// no ttl — matches AuthKitCore.encryptSession
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Advance time substantially — session cookies must still unseal.
|
|
120
|
+
vi.setSystemTime(new Date('2027-01-01T00:00:00.000Z'));
|
|
121
|
+
const unsealed = await encryption.unsealData(sealed, {
|
|
122
|
+
password: testPassword,
|
|
123
|
+
// no ttl — matches AuthKitCore.decryptSession
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(unsealed).toEqual(testData);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
67
129
|
});
|
|
@@ -58,7 +58,7 @@ export class SessionEncryption implements SessionEncryptionInterface {
|
|
|
58
58
|
// Decrypt data from iron-session with HMAC verification
|
|
59
59
|
async unsealData<T = unknown>(
|
|
60
60
|
encryptedData: string,
|
|
61
|
-
{ password }: { password: string },
|
|
61
|
+
{ password, ttl = 0 }: { password: string; ttl?: number | undefined },
|
|
62
62
|
): Promise<T> {
|
|
63
63
|
// First, parse the seal to extract the version
|
|
64
64
|
const { sealWithoutVersion, tokenVersion } = this.parseSeal(encryptedData);
|
|
@@ -80,7 +80,7 @@ export class SessionEncryption implements SessionEncryptionInterface {
|
|
|
80
80
|
iterations: 1,
|
|
81
81
|
minPasswordlength: 32,
|
|
82
82
|
},
|
|
83
|
-
ttl: 0
|
|
83
|
+
ttl: ttl * 1000, // Convert seconds to milliseconds. 0 = no TTL enforcement.
|
|
84
84
|
timestampSkewSec: 60,
|
|
85
85
|
localtimeOffsetMsec: 0,
|
|
86
86
|
});
|
package/src/core/errors.spec.ts
CHANGED
|
@@ -1,100 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthKitError,
|
|
3
|
+
OAuthStateMismatchError,
|
|
4
|
+
PKCECookieMissingError,
|
|
5
|
+
PKCEPayloadTooLargeError,
|
|
3
6
|
SessionEncryptionError,
|
|
4
7
|
TokenValidationError,
|
|
5
8
|
TokenRefreshError,
|
|
6
9
|
} from './errors.js';
|
|
7
10
|
|
|
8
11
|
describe('AuthKitError', () => {
|
|
9
|
-
it('
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
expect(error.message).toBe('Test error');
|
|
13
|
-
expect(error.name).toBe('AuthKitError');
|
|
14
|
-
expect(error).toBeInstanceOf(Error);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('creates error with cause', () => {
|
|
18
|
-
const originalError = new Error('Original error');
|
|
19
|
-
const error = new AuthKitError('Test error', originalError);
|
|
20
|
-
|
|
21
|
-
expect(error.cause).toBe(originalError);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('creates error with data', () => {
|
|
25
|
-
const data = { userId: '123', action: 'login' };
|
|
26
|
-
const error = new AuthKitError('Test error', undefined, data);
|
|
27
|
-
|
|
28
|
-
expect(error.data).toEqual(data);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('creates error with cause and data', () => {
|
|
32
|
-
const originalError = new Error('Original error');
|
|
12
|
+
it('carries message, cause, and arbitrary data', () => {
|
|
13
|
+
const cause = new Error('Original');
|
|
33
14
|
const data = { userId: '123' };
|
|
34
|
-
const error = new AuthKitError('Test
|
|
15
|
+
const error = new AuthKitError('Test', cause, data);
|
|
35
16
|
|
|
36
|
-
expect(error.
|
|
17
|
+
expect(error.message).toBe('Test');
|
|
18
|
+
expect(error.name).toBe('AuthKitError');
|
|
19
|
+
expect(error.cause).toBe(cause);
|
|
37
20
|
expect(error.data).toEqual(data);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('SessionEncryptionError', () => {
|
|
42
|
-
it('creates error with correct name', () => {
|
|
43
|
-
const error = new SessionEncryptionError('Encryption failed');
|
|
44
|
-
|
|
45
|
-
expect(error.name).toBe('SessionEncryptionError');
|
|
46
|
-
expect(error.message).toBe('Encryption failed');
|
|
47
|
-
expect(error).toBeInstanceOf(AuthKitError);
|
|
48
21
|
expect(error).toBeInstanceOf(Error);
|
|
49
22
|
});
|
|
50
|
-
|
|
51
|
-
it('creates error with cause', () => {
|
|
52
|
-
const originalError = new Error('Crypto error');
|
|
53
|
-
const error = new SessionEncryptionError(
|
|
54
|
-
'Encryption failed',
|
|
55
|
-
originalError,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
expect(error.cause).toBe(originalError);
|
|
59
|
-
});
|
|
60
23
|
});
|
|
61
24
|
|
|
62
|
-
describe('
|
|
63
|
-
it('
|
|
64
|
-
const error = new TokenValidationError('Token invalid');
|
|
65
|
-
|
|
66
|
-
expect(error.name).toBe('TokenValidationError');
|
|
67
|
-
expect(error.message).toBe('Token invalid');
|
|
68
|
-
expect(error).toBeInstanceOf(AuthKitError);
|
|
69
|
-
expect(error).toBeInstanceOf(Error);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('creates error with cause', () => {
|
|
73
|
-
const originalError = new Error('JWT malformed');
|
|
74
|
-
const error = new TokenValidationError('Token invalid', originalError);
|
|
75
|
-
|
|
76
|
-
expect(error.cause).toBe(originalError);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('TokenRefreshError', () => {
|
|
81
|
-
it('creates error with correct name', () => {
|
|
82
|
-
const error = new TokenRefreshError('Refresh failed');
|
|
83
|
-
|
|
84
|
-
expect(error.name).toBe('TokenRefreshError');
|
|
85
|
-
expect(error.message).toBe('Refresh failed');
|
|
86
|
-
expect(error).toBeInstanceOf(AuthKitError);
|
|
87
|
-
expect(error).toBeInstanceOf(Error);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('creates error with cause', () => {
|
|
91
|
-
const originalError = new Error('Network error');
|
|
92
|
-
const error = new TokenRefreshError('Refresh failed', originalError);
|
|
93
|
-
|
|
94
|
-
expect(error.cause).toBe(originalError);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('creates error with userId and sessionId', () => {
|
|
25
|
+
describe('TokenRefreshError context', () => {
|
|
26
|
+
it('captures optional userId and sessionId', () => {
|
|
98
27
|
const error = new TokenRefreshError('Refresh failed', undefined, {
|
|
99
28
|
userId: 'user_123',
|
|
100
29
|
sessionId: 'session_456',
|
|
@@ -104,37 +33,7 @@ describe('TokenRefreshError', () => {
|
|
|
104
33
|
expect(error.sessionId).toBe('session_456');
|
|
105
34
|
});
|
|
106
35
|
|
|
107
|
-
it('
|
|
108
|
-
const originalError = new Error('Network error');
|
|
109
|
-
const error = new TokenRefreshError('Refresh failed', originalError, {
|
|
110
|
-
userId: 'user_123',
|
|
111
|
-
sessionId: 'session_456',
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
expect(error.cause).toBe(originalError);
|
|
115
|
-
expect(error.userId).toBe('user_123');
|
|
116
|
-
expect(error.sessionId).toBe('session_456');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('creates error with partial context (userId only)', () => {
|
|
120
|
-
const error = new TokenRefreshError('Refresh failed', undefined, {
|
|
121
|
-
userId: 'user_123',
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
expect(error.userId).toBe('user_123');
|
|
125
|
-
expect(error.sessionId).toBeUndefined();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('creates error with partial context (sessionId only)', () => {
|
|
129
|
-
const error = new TokenRefreshError('Refresh failed', undefined, {
|
|
130
|
-
sessionId: 'session_456',
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(error.userId).toBeUndefined();
|
|
134
|
-
expect(error.sessionId).toBe('session_456');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('has undefined properties when no context provided', () => {
|
|
36
|
+
it('leaves context fields undefined when omitted', () => {
|
|
138
37
|
const error = new TokenRefreshError('Refresh failed');
|
|
139
38
|
|
|
140
39
|
expect(error.userId).toBeUndefined();
|
|
@@ -142,36 +41,28 @@ describe('TokenRefreshError', () => {
|
|
|
142
41
|
});
|
|
143
42
|
});
|
|
144
43
|
|
|
145
|
-
describe('error
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
it('can be caught as AuthKitError', () => {
|
|
165
|
-
const errors = [
|
|
166
|
-
new SessionEncryptionError('test'),
|
|
167
|
-
new TokenValidationError('test'),
|
|
168
|
-
new TokenRefreshError('test'),
|
|
169
|
-
];
|
|
170
|
-
|
|
171
|
-
errors.forEach(error => {
|
|
44
|
+
describe('error subclasses', () => {
|
|
45
|
+
const cases: Array<[string, new (msg: string) => AuthKitError]> = [
|
|
46
|
+
['SessionEncryptionError', SessionEncryptionError],
|
|
47
|
+
['TokenValidationError', TokenValidationError],
|
|
48
|
+
['TokenRefreshError', TokenRefreshError],
|
|
49
|
+
['OAuthStateMismatchError', OAuthStateMismatchError],
|
|
50
|
+
['PKCECookieMissingError', PKCECookieMissingError],
|
|
51
|
+
['PKCEPayloadTooLargeError', PKCEPayloadTooLargeError],
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
it.each(cases)(
|
|
55
|
+
'%s preserves name, message, and AuthKitError inheritance',
|
|
56
|
+
(name, Ctor) => {
|
|
57
|
+
const error = new Ctor('msg');
|
|
58
|
+
|
|
59
|
+
expect(error.name).toBe(name);
|
|
60
|
+
expect(error.message).toBe('msg');
|
|
61
|
+
expect(error).toBeInstanceOf(Ctor);
|
|
62
|
+
expect(error).toBeInstanceOf(AuthKitError);
|
|
172
63
|
expect(() => {
|
|
173
64
|
throw error;
|
|
174
65
|
}).toThrow(AuthKitError);
|
|
175
|
-
}
|
|
176
|
-
|
|
66
|
+
},
|
|
67
|
+
);
|
|
177
68
|
});
|
package/src/core/errors.ts
CHANGED
|
@@ -23,6 +23,27 @@ export class TokenValidationError extends AuthKitError {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export class OAuthStateMismatchError extends AuthKitError {
|
|
27
|
+
constructor(message: string, cause?: unknown) {
|
|
28
|
+
super(message, cause);
|
|
29
|
+
this.name = 'OAuthStateMismatchError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class PKCECookieMissingError extends AuthKitError {
|
|
34
|
+
constructor(message: string, cause?: unknown) {
|
|
35
|
+
super(message, cause);
|
|
36
|
+
this.name = 'PKCECookieMissingError';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class PKCEPayloadTooLargeError extends AuthKitError {
|
|
41
|
+
constructor(message: string, cause?: unknown) {
|
|
42
|
+
super(message, cause);
|
|
43
|
+
this.name = 'PKCEPayloadTooLargeError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
26
47
|
export class TokenRefreshError extends AuthKitError {
|
|
27
48
|
readonly userId?: string;
|
|
28
49
|
readonly sessionId?: string;
|