@aura-stack/auth 0.1.0-rc.9 → 0.2.0-rc.1

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.
Files changed (153) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +7 -31
  3. package/dist/@types/index.js +1 -1
  4. package/dist/@types/router.d.cjs +1 -1
  5. package/dist/@types/router.d.d.ts +7 -7
  6. package/dist/@types/utility.cjs +15 -15
  7. package/dist/@types/utility.d.ts +4 -8
  8. package/dist/@types/utility.js +1 -1
  9. package/dist/actions/callback/access-token.cjs +176 -155
  10. package/dist/actions/callback/access-token.d.ts +15 -20
  11. package/dist/actions/callback/access-token.js +10 -4
  12. package/dist/actions/callback/callback.cjs +394 -490
  13. package/dist/actions/callback/callback.d.ts +10 -12
  14. package/dist/actions/callback/callback.js +16 -12
  15. package/dist/actions/callback/userinfo.cjs +166 -145
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +12 -6
  18. package/dist/actions/csrfToken/csrfToken.cjs +112 -190
  19. package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
  20. package/dist/actions/csrfToken/csrfToken.js +12 -8
  21. package/dist/actions/index.cjs +652 -814
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +34 -18
  24. package/dist/actions/session/session.cjs +86 -176
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +10 -7
  27. package/dist/actions/signIn/authorization.cjs +254 -263
  28. package/dist/actions/signIn/authorization.d.ts +12 -18
  29. package/dist/actions/signIn/authorization.js +16 -6
  30. package/dist/actions/signIn/signIn.cjs +320 -456
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +13 -10
  33. package/dist/actions/signOut/signOut.cjs +304 -473
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +14 -11
  36. package/dist/assert.cjs +40 -36
  37. package/dist/assert.d.ts +13 -4
  38. package/dist/assert.js +12 -2
  39. package/dist/chunk-3EUWD5BB.js +63 -0
  40. package/dist/chunk-42XB3YCW.js +19 -17
  41. package/dist/chunk-6R2YZ4AC.js +22 -0
  42. package/dist/chunk-A3N4PVAT.js +70 -0
  43. package/dist/chunk-B737EUJV.js +22 -0
  44. package/dist/chunk-CXLATHS5.js +143 -0
  45. package/dist/chunk-E3OXBRYF.js +19 -17
  46. package/dist/chunk-EIL2FPSS.js +22 -0
  47. package/dist/chunk-EMKJA2GJ.js +89 -0
  48. package/dist/chunk-FIPU4MLT.js +18 -16
  49. package/dist/chunk-FKRDCWBF.js +19 -17
  50. package/dist/chunk-GA2SMTJO.js +58 -0
  51. package/dist/chunk-HP34YGGJ.js +22 -0
  52. package/dist/chunk-HT4YLL7N.js +35 -0
  53. package/dist/chunk-IKHPGFCW.js +11 -9
  54. package/dist/chunk-IUYZQTJV.js +30 -0
  55. package/dist/chunk-IVET23KF.js +58 -0
  56. package/dist/chunk-JVFTCTTE.js +33 -0
  57. package/dist/chunk-KRNOMBXQ.js +19 -17
  58. package/dist/chunk-KSWLO5ZU.js +102 -0
  59. package/dist/chunk-N2APGLXA.js +71 -0
  60. package/dist/chunk-N4SX7TZT.js +96 -0
  61. package/dist/chunk-RRLIF4PQ.js +55 -0
  62. package/dist/chunk-STHEPPUZ.js +8 -6
  63. package/dist/chunk-TLE4PXY3.js +39 -0
  64. package/dist/chunk-W6LG7BFW.js +197 -0
  65. package/dist/chunk-YRCB5FLE.js +79 -0
  66. package/dist/chunk-ZNCZVF6U.js +14 -0
  67. package/dist/cookie.cjs +222 -187
  68. package/dist/cookie.d.ts +39 -76
  69. package/dist/cookie.js +27 -34
  70. package/dist/errors.cjs +85 -0
  71. package/dist/errors.d.ts +49 -0
  72. package/dist/errors.js +18 -0
  73. package/dist/headers.cjs +28 -28
  74. package/dist/headers.d.ts +2 -2
  75. package/dist/headers.js +6 -2
  76. package/dist/index-DkaLJFn8.d.ts +679 -0
  77. package/dist/index.cjs +1074 -1007
  78. package/dist/index.d.ts +10 -31
  79. package/dist/index.js +85 -51
  80. package/dist/jose.cjs +74 -66
  81. package/dist/jose.d.ts +11 -8
  82. package/dist/jose.js +10 -5
  83. package/dist/oauth/bitbucket.cjs +38 -38
  84. package/dist/oauth/bitbucket.d.ts +7 -7
  85. package/dist/oauth/bitbucket.js +6 -2
  86. package/dist/oauth/discord.cjs +47 -48
  87. package/dist/oauth/discord.d.ts +7 -7
  88. package/dist/oauth/discord.js +6 -2
  89. package/dist/oauth/figma.cjs +39 -39
  90. package/dist/oauth/figma.d.ts +7 -7
  91. package/dist/oauth/figma.js +6 -2
  92. package/dist/oauth/github.cjs +31 -31
  93. package/dist/oauth/github.d.ts +7 -7
  94. package/dist/oauth/github.js +6 -2
  95. package/dist/oauth/gitlab.cjs +39 -39
  96. package/dist/oauth/gitlab.d.ts +7 -7
  97. package/dist/oauth/gitlab.js +6 -2
  98. package/dist/oauth/index.cjs +350 -180
  99. package/dist/oauth/index.d.ts +7 -26
  100. package/dist/oauth/index.js +51 -9
  101. package/dist/oauth/mailchimp.cjs +46 -0
  102. package/dist/oauth/mailchimp.d.ts +7 -0
  103. package/dist/oauth/mailchimp.js +6 -0
  104. package/dist/oauth/pinterest.cjs +46 -0
  105. package/dist/oauth/pinterest.d.ts +7 -0
  106. package/dist/oauth/pinterest.js +6 -0
  107. package/dist/oauth/spotify.cjs +39 -39
  108. package/dist/oauth/spotify.d.ts +7 -7
  109. package/dist/oauth/spotify.js +6 -2
  110. package/dist/oauth/strava.cjs +46 -0
  111. package/dist/oauth/strava.d.ts +7 -0
  112. package/dist/oauth/strava.js +6 -0
  113. package/dist/oauth/x.cjs +39 -39
  114. package/dist/oauth/x.d.ts +7 -7
  115. package/dist/oauth/x.js +6 -2
  116. package/dist/request.cjs +38 -0
  117. package/dist/request.d.ts +13 -0
  118. package/dist/request.js +6 -0
  119. package/dist/schemas.cjs +103 -97
  120. package/dist/schemas.d.ts +96 -126
  121. package/dist/schemas.js +20 -18
  122. package/dist/secure.cjs +106 -101
  123. package/dist/secure.d.ts +17 -17
  124. package/dist/secure.js +19 -4
  125. package/dist/utils.cjs +197 -135
  126. package/dist/utils.d.ts +20 -26
  127. package/dist/utils.js +25 -21
  128. package/package.json +8 -7
  129. package/dist/chunk-256KIVJL.js +0 -110
  130. package/dist/chunk-6SM22VVJ.js +0 -15
  131. package/dist/chunk-CAKJT3KS.js +0 -77
  132. package/dist/chunk-EBPE35JT.js +0 -29
  133. package/dist/chunk-FJUDBLCP.js +0 -52
  134. package/dist/chunk-GZU3RBTB.js +0 -51
  135. package/dist/chunk-HGJ4TXY4.js +0 -105
  136. package/dist/chunk-HMRKN75I.js +0 -74
  137. package/dist/chunk-JAPMIE6S.js +0 -8
  138. package/dist/chunk-LLR722CL.js +0 -75
  139. package/dist/chunk-RLT4RFKV.js +0 -36
  140. package/dist/chunk-SJPDVKUS.js +0 -93
  141. package/dist/chunk-SMQO5WD7.js +0 -20
  142. package/dist/chunk-UJJ7R56J.js +0 -42
  143. package/dist/chunk-UTDLUEEG.js +0 -25
  144. package/dist/chunk-VFTYH33W.js +0 -44
  145. package/dist/chunk-XXJKNKGQ.js +0 -27
  146. package/dist/chunk-ZV4BH47P.js +0 -156
  147. package/dist/error.cjs +0 -88
  148. package/dist/error.d.ts +0 -62
  149. package/dist/error.js +0 -9
  150. package/dist/index-DpfbvTZ_.d.ts +0 -597
  151. package/dist/response.cjs +0 -34
  152. package/dist/response.d.ts +0 -10
  153. package/dist/response.js +0 -2
package/dist/secure.cjs CHANGED
@@ -1,123 +1,128 @@
1
- "use strict"
2
- var __create = Object.create
3
- var __defProp = Object.defineProperty
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor
5
- var __getOwnPropNames = Object.getOwnPropertyNames
6
- var __getProtoOf = Object.getPrototypeOf
7
- var __hasOwnProp = Object.prototype.hasOwnProperty
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __export = (target, all) => {
9
- for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
10
- }
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
11
12
  var __copyProps = (to, from, except, desc) => {
12
- if ((from && typeof from === "object") || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable })
16
- }
17
- return to
18
- }
19
- var __toESM = (mod, isNodeMode, target) => (
20
- (target = mod != null ? __create(__getProtoOf(mod)) : {}),
21
- __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- )
29
- )
30
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod)
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
29
 
32
30
  // src/secure.ts
33
- var secure_exports = {}
31
+ var secure_exports = {};
34
32
  __export(secure_exports, {
35
- createCSRF: () => createCSRF,
36
- createDerivedSalt: () => createDerivedSalt,
37
- createHash: () => createHash,
38
- createPKCE: () => createPKCE,
39
- generateSecure: () => generateSecure,
40
- verifyCSRF: () => verifyCSRF,
41
- })
42
- module.exports = __toCommonJS(secure_exports)
43
- var import_node_crypto = __toESM(require("crypto"), 1)
33
+ createCSRF: () => createCSRF,
34
+ createDerivedSalt: () => createDerivedSalt,
35
+ createHash: () => createHash,
36
+ createPKCE: () => createPKCE,
37
+ generateSecure: () => generateSecure,
38
+ verifyCSRF: () => verifyCSRF
39
+ });
40
+ module.exports = __toCommonJS(secure_exports);
41
+ var import_crypto = __toESM(require("crypto"), 1);
44
42
 
45
43
  // src/utils.ts
46
- var import_router = require("@aura-stack/router")
44
+ var import_router = require("@aura-stack/router");
47
45
 
48
- // src/error.ts
49
- var AuthError = class extends Error {
50
- constructor(type, message) {
51
- super(message)
52
- this.type = type
53
- this.name = "AuthError"
54
- }
55
- }
56
- var InvalidCsrfTokenError = class extends AuthError {
57
- constructor(message = "The provided CSRF token is invalid or has expired") {
58
- super("invalid_csrf_token", message)
59
- this.name = "InvalidCsrfTokenError"
60
- }
61
- }
46
+ // src/errors.ts
47
+ var AuthSecurityError = class extends Error {
48
+ type = "AUTH_SECURITY_ERROR";
49
+ code;
50
+ constructor(code, message, options) {
51
+ super(message, options);
52
+ this.code = code;
53
+ this.name = new.target.name;
54
+ Error.captureStackTrace(this, new.target);
55
+ }
56
+ };
62
57
 
63
58
  // src/utils.ts
64
59
  var equals = (a, b) => {
65
- if (a === null || b === null || a === void 0 || b === void 0) return false
66
- return a === b
67
- }
60
+ if (a === null || b === null || a === void 0 || b === void 0) return false;
61
+ return a === b;
62
+ };
63
+
64
+ // src/assert.ts
65
+ var isJWTPayloadWithToken = (payload) => {
66
+ return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
67
+ };
68
68
 
69
69
  // src/secure.ts
70
70
  var generateSecure = (length = 32) => {
71
- return import_node_crypto.default.randomBytes(length).toString("base64url")
72
- }
71
+ return import_crypto.default.randomBytes(length).toString("base64url");
72
+ };
73
73
  var createHash = (data, base = "hex") => {
74
- return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base)
75
- }
74
+ return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
75
+ };
76
76
  var createPKCE = async (verifier) => {
77
- const codeVerifier = verifier ?? generateSecure(86)
78
- const codeChallenge = createHash(codeVerifier, "base64url")
79
- return { codeVerifier, codeChallenge, method: "S256" }
80
- }
77
+ const codeVerifier = verifier ?? generateSecure(86);
78
+ const codeChallenge = createHash(codeVerifier, "base64url");
79
+ return { codeVerifier, codeChallenge, method: "S256" };
80
+ };
81
81
  var createCSRF = async (jose, csrfCookie) => {
82
- try {
83
- const token = generateSecure(32)
84
- if (csrfCookie) {
85
- await jose.verifyJWS(csrfCookie)
86
- return csrfCookie
87
- }
88
- return jose.signJWS({ token })
89
- } catch {
90
- const token = generateSecure(32)
91
- return jose.signJWS({ token })
82
+ try {
83
+ const token = generateSecure(32);
84
+ if (csrfCookie) {
85
+ await jose.verifyJWS(csrfCookie);
86
+ return csrfCookie;
92
87
  }
93
- }
88
+ return jose.signJWS({ token });
89
+ } catch {
90
+ const token = generateSecure(32);
91
+ return jose.signJWS({ token });
92
+ }
93
+ };
94
94
  var verifyCSRF = async (jose, cookie, header) => {
95
- try {
96
- const { token: cookieToken } = await jose.verifyJWS(cookie)
97
- const { token: headerToken } = await jose.verifyJWS(header)
98
- const cookieBuffer = Buffer.from(cookieToken)
99
- const headerBuffer = Buffer.from(headerToken)
100
- if (!equals(headerBuffer.length, cookieBuffer.length)) {
101
- throw new InvalidCsrfTokenError()
102
- }
103
- if (!import_node_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
104
- throw new InvalidCsrfTokenError()
105
- }
106
- return true
107
- } catch {
108
- throw new InvalidCsrfTokenError()
95
+ try {
96
+ const cookiePayload = await jose.verifyJWS(cookie);
97
+ const headerPayload = await jose.verifyJWS(header);
98
+ if (!isJWTPayloadWithToken(cookiePayload)) {
99
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
100
+ }
101
+ if (!isJWTPayloadWithToken(headerPayload)) {
102
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
103
+ }
104
+ const cookieBuffer = Buffer.from(cookiePayload.token);
105
+ const headerBuffer = Buffer.from(headerPayload.token);
106
+ if (!equals(headerBuffer.length, cookieBuffer.length)) {
107
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
108
+ }
109
+ if (!import_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
110
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
109
111
  }
110
- }
112
+ return true;
113
+ } catch {
114
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
115
+ }
116
+ };
111
117
  var createDerivedSalt = (secret) => {
112
- return import_node_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex")
113
- }
118
+ return import_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
119
+ };
114
120
  // Annotate the CommonJS export names for ESM import in node:
115
- 0 &&
116
- (module.exports = {
117
- createCSRF,
118
- createDerivedSalt,
119
- createHash,
120
- createPKCE,
121
- generateSecure,
122
- verifyCSRF,
123
- })
121
+ 0 && (module.exports = {
122
+ createCSRF,
123
+ createDerivedSalt,
124
+ createHash,
125
+ createPKCE,
126
+ generateSecure,
127
+ verifyCSRF
128
+ });
package/dist/secure.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { A as AuthRuntimeConfig } from "./index-DpfbvTZ_.js"
2
- import "zod/v4"
3
- import "@aura-stack/jose/jose"
4
- import "./schemas.js"
5
- import "zod/v4/core"
6
- import "cookie"
7
- import "./@types/utility.js"
1
+ import { A as AuthRuntimeConfig } from './index-DkaLJFn8.js';
2
+ import 'zod';
3
+ import './schemas.js';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
+ import './@types/utility.js';
8
8
 
9
- declare const generateSecure: (length?: number) => string
10
- declare const createHash: (data: string, base?: "hex" | "base64" | "base64url") => string
9
+ declare const generateSecure: (length?: number) => string;
10
+ declare const createHash: (data: string, base?: "hex" | "base64" | "base64url") => string;
11
11
  /**
12
12
  * Creates the code challenge flow for PKCE OAuth flow. It generates a code verifier and its corresponding
13
13
  * code challenge using SHA-256 hashing.
@@ -18,24 +18,24 @@ declare const createHash: (data: string, base?: "hex" | "base64" | "base64url")
18
18
  * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
19
19
  */
20
20
  declare const createPKCE: (verifier?: string) => Promise<{
21
- codeVerifier: string
22
- codeChallenge: string
23
- method: string
24
- }>
21
+ codeVerifier: string;
22
+ codeChallenge: string;
23
+ method: string;
24
+ }>;
25
25
  /**
26
26
  * Creates a CSRF token to be used in OAuth flows to prevent cross-site request forgery attacks.
27
27
  *
28
28
  * @param csrfCookie - Optional existing CSRF cookie to verify and reuse
29
29
  * @returns Signed CSRF token
30
30
  */
31
- declare const createCSRF: (jose: AuthRuntimeConfig["jose"], csrfCookie?: string) => Promise<string>
32
- declare const verifyCSRF: (jose: AuthRuntimeConfig["jose"], cookie: string, header: string) => Promise<boolean>
31
+ declare const createCSRF: (jose: AuthRuntimeConfig["jose"], csrfCookie?: string) => Promise<string>;
32
+ declare const verifyCSRF: (jose: AuthRuntimeConfig["jose"], cookie: string, header: string) => Promise<boolean>;
33
33
  /**
34
34
  * Creates a deterministic derived salt from the provided secret.
35
35
  *
36
36
  * @param secret the base secret to derive the salt from
37
37
  * @returns the derived salt as a hexadecimal string
38
38
  */
39
- declare const createDerivedSalt: (secret: string) => string
39
+ declare const createDerivedSalt: (secret: string) => string;
40
40
 
41
- export { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF }
41
+ export { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF };
package/dist/secure.js CHANGED
@@ -1,4 +1,19 @@
1
- import { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF } from "./chunk-GZU3RBTB.js"
2
- import "./chunk-256KIVJL.js"
3
- import "./chunk-FJUDBLCP.js"
4
- export { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF }
1
+ import {
2
+ createCSRF,
3
+ createDerivedSalt,
4
+ createHash,
5
+ createPKCE,
6
+ generateSecure,
7
+ verifyCSRF
8
+ } from "./chunk-N2APGLXA.js";
9
+ import "./chunk-CXLATHS5.js";
10
+ import "./chunk-EIL2FPSS.js";
11
+ import "./chunk-RRLIF4PQ.js";
12
+ export {
13
+ createCSRF,
14
+ createDerivedSalt,
15
+ createHash,
16
+ createPKCE,
17
+ generateSecure,
18
+ verifyCSRF
19
+ };