@aura-stack/auth 0.4.0-rc.5 → 0.5.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.
Files changed (201) hide show
  1. package/dist/@types/index.d.ts +8 -3
  2. package/dist/@types/router.d.cjs +0 -17
  3. package/dist/@types/router.d.d.ts +7 -2
  4. package/dist/@types/router.d.js +0 -1
  5. package/dist/actions/callback/access-token.cjs +130 -71
  6. package/dist/actions/callback/access-token.d.ts +9 -4
  7. package/dist/actions/callback/access-token.js +3 -4
  8. package/dist/actions/callback/callback.cjs +428 -152
  9. package/dist/actions/callback/callback.d.ts +11 -3
  10. package/dist/actions/callback/callback.js +12 -10
  11. package/dist/actions/callback/userinfo.cjs +159 -65
  12. package/dist/actions/callback/userinfo.d.ts +8 -3
  13. package/dist/actions/callback/userinfo.js +7 -6
  14. package/dist/actions/csrfToken/csrfToken.cjs +70 -19
  15. package/dist/actions/csrfToken/csrfToken.js +8 -7
  16. package/dist/actions/index.cjs +780 -348
  17. package/dist/actions/index.d.ts +6 -2
  18. package/dist/actions/index.js +23 -18
  19. package/dist/actions/session/session.cjs +107 -26
  20. package/dist/actions/session/session.js +7 -5
  21. package/dist/actions/signIn/authorization-url.cjs +288 -0
  22. package/dist/actions/signIn/authorization-url.d.ts +31 -0
  23. package/dist/actions/signIn/authorization-url.js +16 -0
  24. package/dist/actions/signIn/authorization.cjs +209 -211
  25. package/dist/actions/signIn/authorization.d.ts +32 -21
  26. package/dist/actions/signIn/authorization.js +12 -9
  27. package/dist/actions/signIn/signIn.cjs +470 -235
  28. package/dist/actions/signIn/signIn.d.ts +12 -3
  29. package/dist/actions/signIn/signIn.js +11 -8
  30. package/dist/actions/signOut/signOut.cjs +376 -228
  31. package/dist/actions/signOut/signOut.d.ts +1 -1
  32. package/dist/actions/signOut/signOut.js +10 -9
  33. package/dist/api/createApi.cjs +750 -0
  34. package/dist/api/createApi.d.ts +12 -0
  35. package/dist/api/createApi.js +19 -0
  36. package/dist/api/getSession.cjs +141 -0
  37. package/dist/api/getSession.d.ts +16 -0
  38. package/dist/api/getSession.js +10 -0
  39. package/dist/api/signIn.cjs +549 -0
  40. package/dist/api/signIn.d.ts +26 -0
  41. package/dist/api/signIn.js +15 -0
  42. package/dist/api/signOut.cjs +279 -0
  43. package/dist/api/signOut.d.ts +16 -0
  44. package/dist/api/signOut.js +13 -0
  45. package/dist/assert.cjs +150 -5
  46. package/dist/assert.d.ts +26 -3
  47. package/dist/assert.js +17 -3
  48. package/dist/{chunk-YRCB5FLE.js → chunk-2A5B7GWR.js} +52 -6
  49. package/dist/chunk-2GQLSIJ2.js +40 -0
  50. package/dist/chunk-2IR674WX.js +44 -0
  51. package/dist/chunk-3J5TUH2I.js +50 -0
  52. package/dist/chunk-4RWSYUKX.js +98 -0
  53. package/dist/chunk-4YHJ4IEQ.js +25 -0
  54. package/dist/chunk-54CZPKR4.js +25 -0
  55. package/dist/chunk-5LZ7TOM3.js +25 -0
  56. package/dist/chunk-7BE46WWS.js +88 -0
  57. package/dist/chunk-7YYXFKLR.js +35 -0
  58. package/dist/chunk-C3A37LQC.js +33 -0
  59. package/dist/chunk-CITNGXDA.js +31 -0
  60. package/dist/chunk-CWX724AG.js +78 -0
  61. package/dist/chunk-D2CSIUKP.js +74 -0
  62. package/dist/chunk-E6G5YCI6.js +25 -0
  63. package/dist/chunk-EBAMFRB7.js +34 -0
  64. package/dist/chunk-EEE7UM5T.js +25 -0
  65. package/dist/{chunk-HT4YLL7N.js → chunk-FPCVZUVG.js} +10 -8
  66. package/dist/chunk-FW4W3REU.js +25 -0
  67. package/dist/chunk-GNNBM2WJ.js +83 -0
  68. package/dist/chunk-IPKO6UQN.js +25 -0
  69. package/dist/chunk-JOCGX3RP.js +59 -0
  70. package/dist/chunk-KBXWTD6E.js +94 -0
  71. package/dist/chunk-KMMAZFSJ.js +25 -0
  72. package/dist/chunk-LATR3NIV.js +117 -0
  73. package/dist/chunk-LAYPUDQF.js +39 -0
  74. package/dist/chunk-LDU7A2JE.js +25 -0
  75. package/dist/chunk-LX3TJ2TJ.js +294 -0
  76. package/dist/chunk-NHZBQNRR.js +143 -0
  77. package/dist/chunk-OVHNRULD.js +33 -0
  78. package/dist/chunk-PDP3PHB3.js +127 -0
  79. package/dist/chunk-PHYNROD4.js +47 -0
  80. package/dist/chunk-QQEKY4XP.js +29 -0
  81. package/dist/chunk-U4RK4LKJ.js +348 -0
  82. package/dist/{chunk-RRLIF4PQ.js → chunk-U5663F2U.js} +16 -1
  83. package/dist/chunk-UN7X6SU5.js +53 -0
  84. package/dist/chunk-UZQJJD6A.js +100 -0
  85. package/dist/chunk-V6LLEAR4.js +80 -0
  86. package/dist/chunk-WHNDRO3N.js +50 -0
  87. package/dist/{chunk-W6LG7BFW.js → chunk-XY5R3EHH.js} +30 -23
  88. package/dist/client/client.cjs +135 -0
  89. package/dist/client/client.d.ts +85 -0
  90. package/dist/client/client.js +9 -0
  91. package/dist/client/index.cjs +135 -0
  92. package/dist/client/index.d.ts +14 -0
  93. package/dist/client/index.js +10 -0
  94. package/dist/context.cjs +1237 -0
  95. package/dist/context.d.ts +16 -0
  96. package/dist/context.js +28 -0
  97. package/dist/cookie.cjs +57 -22
  98. package/dist/cookie.d.ts +11 -6
  99. package/dist/cookie.js +3 -2
  100. package/dist/createAuth.cjs +2320 -0
  101. package/dist/createAuth.d.ts +12 -0
  102. package/dist/createAuth.js +48 -0
  103. package/dist/env.cjs +78 -0
  104. package/dist/env.d.ts +10 -0
  105. package/dist/env.js +12 -0
  106. package/dist/errors.cjs +17 -0
  107. package/dist/errors.d.ts +15 -4
  108. package/dist/errors.js +5 -1
  109. package/dist/headers.cjs +28 -2
  110. package/dist/headers.d.ts +25 -1
  111. package/dist/headers.js +9 -3
  112. package/dist/index-_aXtxb_s.d.ts +1377 -0
  113. package/dist/index.cjs +1843 -610
  114. package/dist/index.d.ts +11 -92
  115. package/dist/index.js +53 -85
  116. package/dist/jose.cjs +113 -38
  117. package/dist/jose.d.ts +12 -23
  118. package/dist/jose.js +17 -7
  119. package/dist/logger.cjs +424 -0
  120. package/dist/logger.d.ts +12 -0
  121. package/dist/logger.js +17 -0
  122. package/dist/oauth/atlassian.cjs +57 -0
  123. package/dist/oauth/atlassian.d.ts +12 -0
  124. package/dist/oauth/atlassian.js +6 -0
  125. package/dist/oauth/bitbucket.cjs +19 -15
  126. package/dist/oauth/bitbucket.d.ts +7 -2
  127. package/dist/oauth/bitbucket.js +1 -1
  128. package/dist/oauth/discord.cjs +27 -24
  129. package/dist/oauth/discord.d.ts +7 -2
  130. package/dist/oauth/discord.js +1 -1
  131. package/dist/oauth/dropbox.cjs +53 -0
  132. package/dist/oauth/dropbox.d.ts +12 -0
  133. package/dist/oauth/dropbox.js +6 -0
  134. package/dist/oauth/figma.cjs +19 -16
  135. package/dist/oauth/figma.d.ts +7 -2
  136. package/dist/oauth/figma.js +1 -1
  137. package/dist/oauth/github.cjs +19 -8
  138. package/dist/oauth/github.d.ts +7 -2
  139. package/dist/oauth/github.js +1 -1
  140. package/dist/oauth/gitlab.cjs +19 -16
  141. package/dist/oauth/gitlab.d.ts +7 -2
  142. package/dist/oauth/gitlab.js +1 -1
  143. package/dist/oauth/index.cjs +529 -239
  144. package/dist/oauth/index.d.ts +7 -2
  145. package/dist/oauth/index.js +39 -22
  146. package/dist/oauth/mailchimp.cjs +19 -16
  147. package/dist/oauth/mailchimp.d.ts +7 -2
  148. package/dist/oauth/mailchimp.js +1 -1
  149. package/dist/oauth/notion.cjs +131 -0
  150. package/dist/oauth/notion.d.ts +12 -0
  151. package/dist/oauth/notion.js +9 -0
  152. package/dist/oauth/pinterest.cjs +19 -16
  153. package/dist/oauth/pinterest.d.ts +7 -2
  154. package/dist/oauth/pinterest.js +1 -1
  155. package/dist/oauth/spotify.cjs +19 -16
  156. package/dist/oauth/spotify.d.ts +7 -2
  157. package/dist/oauth/spotify.js +1 -1
  158. package/dist/oauth/strava.cjs +19 -16
  159. package/dist/oauth/strava.d.ts +7 -2
  160. package/dist/oauth/strava.js +1 -1
  161. package/dist/oauth/twitch.cjs +95 -0
  162. package/dist/oauth/twitch.d.ts +12 -0
  163. package/dist/oauth/twitch.js +7 -0
  164. package/dist/oauth/x.cjs +19 -16
  165. package/dist/oauth/x.d.ts +7 -2
  166. package/dist/oauth/x.js +1 -1
  167. package/dist/schemas.cjs +89 -42
  168. package/dist/schemas.d.ts +114 -18
  169. package/dist/schemas.js +5 -3
  170. package/dist/secure.cjs +73 -31
  171. package/dist/secure.d.ts +11 -11
  172. package/dist/secure.js +7 -6
  173. package/dist/utils.cjs +203 -90
  174. package/dist/utils.d.ts +21 -40
  175. package/dist/utils.js +21 -12
  176. package/package.json +9 -6
  177. package/dist/chunk-3EUWD5BB.js +0 -63
  178. package/dist/chunk-42XB3YCW.js +0 -22
  179. package/dist/chunk-6R2YZ4AC.js +0 -22
  180. package/dist/chunk-A3N4PVAT.js +0 -70
  181. package/dist/chunk-B737EUJV.js +0 -22
  182. package/dist/chunk-CXLATHS5.js +0 -143
  183. package/dist/chunk-E3OXBRYF.js +0 -22
  184. package/dist/chunk-EIL2FPSS.js +0 -22
  185. package/dist/chunk-EMKJA2GJ.js +0 -89
  186. package/dist/chunk-FIPU4MLT.js +0 -21
  187. package/dist/chunk-FKRDCWBF.js +0 -22
  188. package/dist/chunk-GA2SMTJO.js +0 -58
  189. package/dist/chunk-HP34YGGJ.js +0 -22
  190. package/dist/chunk-IKHPGFCW.js +0 -14
  191. package/dist/chunk-IUYZQTJV.js +0 -30
  192. package/dist/chunk-IVET23KF.js +0 -58
  193. package/dist/chunk-JVFTCTTE.js +0 -33
  194. package/dist/chunk-KRNOMBXQ.js +0 -22
  195. package/dist/chunk-KSWLO5ZU.js +0 -102
  196. package/dist/chunk-N2APGLXA.js +0 -71
  197. package/dist/chunk-N4SX7TZT.js +0 -96
  198. package/dist/chunk-STHEPPUZ.js +0 -11
  199. package/dist/chunk-TLE4PXY3.js +0 -39
  200. package/dist/index-B8jeIElf.d.ts +0 -679
  201. /package/dist/{chunk-DIVDFNAP.js → chunk-5X7JZMEF.js} +0 -0
@@ -4,10 +4,14 @@ export { sessionAction } from './session/session.js';
4
4
  export { signOutAction } from './signOut/signOut.js';
5
5
  export { csrfTokenAction } from './csrfToken/csrfToken.js';
6
6
  import '@aura-stack/router';
7
+ import 'zod/v4';
8
+ import '../index-_aXtxb_s.js';
7
9
  import 'zod';
8
- import '../index-B8jeIElf.js';
9
10
  import '../schemas.js';
10
- import '@aura-stack/router/cookie';
11
11
  import '@aura-stack/jose';
12
12
  import '@aura-stack/jose/jose';
13
+ import '@aura-stack/jose/crypto';
14
+ import '@aura-stack/router/cookie';
13
15
  import '../@types/utility.js';
16
+ import 'jose';
17
+ import 'zod/v4/core';
@@ -1,30 +1,35 @@
1
1
  import "../chunk-ITQ7352M.js";
2
- import {
3
- signOutAction
4
- } from "../chunk-A3N4PVAT.js";
5
2
  import {
6
3
  callbackAction
7
- } from "../chunk-KSWLO5ZU.js";
8
- import "../chunk-GA2SMTJO.js";
9
- import "../chunk-IVET23KF.js";
4
+ } from "../chunk-NHZBQNRR.js";
5
+ import "../chunk-GNNBM2WJ.js";
10
6
  import {
11
7
  csrfTokenAction
12
- } from "../chunk-HT4YLL7N.js";
8
+ } from "../chunk-FPCVZUVG.js";
9
+ import {
10
+ signInAction
11
+ } from "../chunk-UN7X6SU5.js";
13
12
  import {
14
13
  sessionAction
15
- } from "../chunk-JVFTCTTE.js";
14
+ } from "../chunk-7YYXFKLR.js";
16
15
  import {
17
- signInAction
18
- } from "../chunk-3EUWD5BB.js";
19
- import "../chunk-N4SX7TZT.js";
20
- import "../chunk-W6LG7BFW.js";
21
- import "../chunk-STHEPPUZ.js";
22
- import "../chunk-N2APGLXA.js";
23
- import "../chunk-CXLATHS5.js";
24
- import "../chunk-EIL2FPSS.js";
25
- import "../chunk-RRLIF4PQ.js";
16
+ signOutAction
17
+ } from "../chunk-3J5TUH2I.js";
18
+ import "../chunk-7BE46WWS.js";
19
+ import "../chunk-CITNGXDA.js";
20
+ import "../chunk-JOCGX3RP.js";
21
+ import "../chunk-D2CSIUKP.js";
22
+ import "../chunk-LATR3NIV.js";
23
+ import "../chunk-KBXWTD6E.js";
26
24
  import "../chunk-ZNCZVF6U.js";
27
- import "../chunk-YRCB5FLE.js";
25
+ import "../chunk-V6LLEAR4.js";
26
+ import "../chunk-2A5B7GWR.js";
27
+ import "../chunk-UZQJJD6A.js";
28
+ import "../chunk-LX3TJ2TJ.js";
29
+ import "../chunk-XY5R3EHH.js";
30
+ import "../chunk-WHNDRO3N.js";
31
+ import "../chunk-U5663F2U.js";
32
+ import "../chunk-EBAMFRB7.js";
28
33
  export {
29
34
  callbackAction,
30
35
  csrfTokenAction,
@@ -25,8 +25,65 @@ __export(session_exports, {
25
25
  module.exports = __toCommonJS(session_exports);
26
26
  var import_router2 = require("@aura-stack/router");
27
27
 
28
- // src/utils.ts
29
- var import_router = require("@aura-stack/router");
28
+ // src/headers.ts
29
+ var cacheControl = {
30
+ "Cache-Control": "no-store",
31
+ Pragma: "no-cache",
32
+ Expires: "0",
33
+ Vary: "Cookie"
34
+ };
35
+ var contentSecurityPolicy = {
36
+ "Content-Security-Policy": [
37
+ "default-src 'none'",
38
+ "script-src 'self'",
39
+ "frame-src 'none'",
40
+ "object-src 'none'",
41
+ "frame-ancestors 'none'",
42
+ "base-uri 'none'"
43
+ ].join("; ")
44
+ };
45
+ var secureHeaders = {
46
+ "X-Content-Type-Options": "nosniff",
47
+ "X-Frame-Options": "DENY",
48
+ "Referrer-Policy": "strict-origin-when-cross-origin"
49
+ };
50
+ var secureApiHeaders = {
51
+ ...cacheControl,
52
+ ...contentSecurityPolicy,
53
+ ...secureHeaders
54
+ };
55
+
56
+ // src/env.ts
57
+ var import_meta = {};
58
+ var env = new Proxy({}, {
59
+ get(_, prop) {
60
+ if (typeof prop !== "string") return void 0;
61
+ const hasProperty = (process2) => {
62
+ return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
63
+ };
64
+ try {
65
+ if (typeof process !== "undefined" && hasProperty(process.env)) {
66
+ return process.env[prop];
67
+ }
68
+ if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
69
+ return import_meta.env[prop];
70
+ }
71
+ if (typeof Deno !== "undefined" && Deno.env?.get) {
72
+ return Deno.env.get(prop);
73
+ }
74
+ if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
75
+ return Bun.env[prop];
76
+ }
77
+ const globalValue = globalThis[prop];
78
+ return typeof globalValue === "string" ? globalValue : void 0;
79
+ } catch {
80
+ return void 0;
81
+ }
82
+ }
83
+ });
84
+
85
+ // src/cookie.ts
86
+ var import_cookie = require("@aura-stack/router/cookie");
30
87
 
31
88
  // src/errors.ts
32
89
  var AuthInternalError = class extends Error {
@@ -40,21 +97,7 @@ var AuthInternalError = class extends Error {
40
97
  }
41
98
  };
42
99
 
43
- // src/utils.ts
44
- var toISOString = (date) => {
45
- return new Date(date).toISOString();
46
- };
47
-
48
- // src/headers.ts
49
- var cacheControl = {
50
- "Cache-Control": "no-store",
51
- Pragma: "no-cache",
52
- Expires: "0",
53
- Vary: "Cookie"
54
- };
55
-
56
100
  // src/cookie.ts
57
- var import_cookie = require("@aura-stack/router/cookie");
58
101
  var defaultCookieOptions = {
59
102
  httpOnly: true,
60
103
  sameSite: "lax",
@@ -70,10 +113,11 @@ var oauthCookieOptions = {
70
113
  var expiredCookieAttributes = {
71
114
  ...defaultCookieOptions,
72
115
  expires: /* @__PURE__ */ new Date(0),
73
- maxAge: 0
116
+ maxAge: 0,
117
+ secure: true
74
118
  };
75
119
  var getCookie = (request, cookieName) => {
76
- const cookies = request.headers.get("Cookie");
120
+ const cookies = request instanceof Request ? request.headers.get("Cookie") : request.get("Cookie");
77
121
  if (!cookies) {
78
122
  throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
79
123
  }
@@ -84,21 +128,58 @@ var getCookie = (request, cookieName) => {
84
128
  return value;
85
129
  };
86
130
 
131
+ // src/utils.ts
132
+ var import_router = require("@aura-stack/router");
133
+
134
+ // src/assert.ts
135
+ var import_crypto = require("@aura-stack/jose/crypto");
136
+
137
+ // src/utils.ts
138
+ var toISOString = (date) => {
139
+ return new Date(date).toISOString();
140
+ };
141
+ var getErrorName = (error) => {
142
+ if (error instanceof Error) {
143
+ return error.name;
144
+ }
145
+ return typeof error === "string" ? error : "UnknownError";
146
+ };
147
+
148
+ // src/api/getSession.ts
149
+ var getSession = async ({ ctx, headers }) => {
150
+ try {
151
+ const session = getCookie(new Headers(headers), ctx.cookies.sessionToken.name);
152
+ const decoded = await ctx.jose.decodeJWT(session);
153
+ ctx?.logger?.log("AUTH_SESSION_VALID");
154
+ const { exp, iat, jti, nbf, aud, iss, ...user } = decoded;
155
+ return {
156
+ session: {
157
+ user,
158
+ expires: toISOString(exp * 1e3)
159
+ },
160
+ authenticated: true
161
+ };
162
+ } catch (error) {
163
+ ctx?.logger?.log("AUTH_SESSION_INVALID", { structuredData: { error_type: getErrorName(error) } });
164
+ return { session: null, authenticated: false };
165
+ }
166
+ };
167
+
87
168
  // src/actions/session/session.ts
88
169
  var sessionAction = (0, import_router2.createEndpoint)("GET", "/session", async (ctx) => {
89
170
  const {
90
171
  request,
91
- context: { jose, cookies }
172
+ context: { cookies }
92
173
  } = ctx;
93
174
  try {
94
- const session = getCookie(request, cookies.sessionToken.name);
95
- const decoded = await jose.decodeJWT(session);
96
- const { exp, iat, jti, nbf, ...user } = decoded;
97
- const headers = new Headers(cacheControl);
98
- return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
175
+ const session = await getSession({ ctx: ctx.context, headers: request.headers });
176
+ if (!session.authenticated) {
177
+ throw new AuthInternalError("INVALID_JWT_TOKEN", "Session not authenticated");
178
+ }
179
+ return Response.json(session, { headers: secureApiHeaders });
99
180
  } catch (error) {
100
- const headers = new import_router2.HeadersBuilder(cacheControl).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
101
- return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
181
+ const headers = new import_router2.HeadersBuilder(secureApiHeaders).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
182
+ return Response.json({ session: null, authenticated: false }, { status: 401, headers });
102
183
  }
103
184
  });
104
185
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  sessionAction
3
- } from "../../chunk-JVFTCTTE.js";
4
- import "../../chunk-W6LG7BFW.js";
5
- import "../../chunk-STHEPPUZ.js";
6
- import "../../chunk-CXLATHS5.js";
7
- import "../../chunk-RRLIF4PQ.js";
3
+ } from "../../chunk-7YYXFKLR.js";
4
+ import "../../chunk-CITNGXDA.js";
5
+ import "../../chunk-LX3TJ2TJ.js";
6
+ import "../../chunk-XY5R3EHH.js";
7
+ import "../../chunk-WHNDRO3N.js";
8
+ import "../../chunk-U5663F2U.js";
9
+ import "../../chunk-EBAMFRB7.js";
8
10
  export {
9
11
  sessionAction
10
12
  };
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/actions/signIn/authorization-url.ts
21
+ var authorization_url_exports = {};
22
+ __export(authorization_url_exports, {
23
+ buildAuthorizationURL: () => buildAuthorizationURL,
24
+ createAuthorizationURL: () => createAuthorizationURL,
25
+ setSearchParams: () => setSearchParams
26
+ });
27
+ module.exports = __toCommonJS(authorization_url_exports);
28
+
29
+ // src/errors.ts
30
+ var AuthInternalError = class extends Error {
31
+ type = "AUTH_INTERNAL_ERROR";
32
+ code;
33
+ constructor(code, message, options2) {
34
+ super(message, options2);
35
+ this.code = code;
36
+ this.name = new.target.name;
37
+ Error.captureStackTrace(this, new.target);
38
+ }
39
+ };
40
+ var AuthSecurityError = class extends Error {
41
+ type = "AUTH_SECURITY_ERROR";
42
+ code;
43
+ constructor(code, message, options2) {
44
+ super(message, options2);
45
+ this.code = code;
46
+ this.name = new.target.name;
47
+ Error.captureStackTrace(this, new.target);
48
+ }
49
+ };
50
+
51
+ // src/schemas.ts
52
+ var import_v4 = require("zod/v4");
53
+ var AuthorizeConfigSchema = import_v4.z.union([
54
+ (0, import_v4.string)().url(),
55
+ (0, import_v4.object)({
56
+ url: (0, import_v4.string)().url(),
57
+ params: (0, import_v4.object)({
58
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
59
+ scope: (0, import_v4.string)().optional()
60
+ })
61
+ })
62
+ ]);
63
+ var AccessTokenConfigSchema = import_v4.z.union([
64
+ (0, import_v4.string)().url(),
65
+ (0, import_v4.object)({
66
+ url: (0, import_v4.string)().url(),
67
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional()
68
+ })
69
+ ]);
70
+ var UserInfoConfigSchema = import_v4.z.union([
71
+ (0, import_v4.string)().url(),
72
+ (0, import_v4.object)({
73
+ url: (0, import_v4.string)().url(),
74
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional(),
75
+ method: (0, import_v4.string)().optional()
76
+ })
77
+ ]);
78
+ var OAuthProviderCredentialsSchema = (0, import_v4.object)({
79
+ id: (0, import_v4.string)(),
80
+ name: (0, import_v4.string)(),
81
+ authorize: AuthorizeConfigSchema.optional(),
82
+ /** @deprecated */
83
+ authorizeURL: (0, import_v4.string)().url().optional(),
84
+ accessToken: AccessTokenConfigSchema,
85
+ /** @deprecated */
86
+ scope: (0, import_v4.string)().optional(),
87
+ userInfo: UserInfoConfigSchema,
88
+ /** @deprecated */
89
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
90
+ clientId: (0, import_v4.string)(),
91
+ clientSecret: (0, import_v4.string)(),
92
+ profile: import_v4.z.function().optional()
93
+ });
94
+ var OAuthProviderConfigSchema = (0, import_v4.object)({
95
+ authorize: AuthorizeConfigSchema.optional(),
96
+ /** @deprecated */
97
+ authorizeURL: (0, import_v4.string)().url().optional(),
98
+ accessToken: AccessTokenConfigSchema,
99
+ /** @deprecated */
100
+ scope: (0, import_v4.string)().optional(),
101
+ userInfo: UserInfoConfigSchema,
102
+ /** @deprecated */
103
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
104
+ clientId: (0, import_v4.string)(),
105
+ clientSecret: (0, import_v4.string)()
106
+ });
107
+ var OAuthAuthorization = OAuthProviderConfigSchema.extend({
108
+ redirectURI: (0, import_v4.string)(),
109
+ state: (0, import_v4.string)(),
110
+ codeChallenge: (0, import_v4.string)(),
111
+ codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
112
+ });
113
+ var OAuthAuthorizationResponse = (0, import_v4.object)({
114
+ state: (0, import_v4.string)({ message: "Missing state parameter in the OAuth authorization response." }),
115
+ code: (0, import_v4.string)({ message: "Missing code parameter in the OAuth authorization response." })
116
+ });
117
+ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
118
+ error: (0, import_v4.enum)([
119
+ "invalid_request",
120
+ "unauthorized_client",
121
+ "access_denied",
122
+ "unsupported_response_type",
123
+ "invalid_scope",
124
+ "server_error",
125
+ "temporarily_unavailable"
126
+ ]),
127
+ error_description: (0, import_v4.string)().optional(),
128
+ error_uri: (0, import_v4.string)().optional(),
129
+ state: (0, import_v4.string)()
130
+ });
131
+ var OAuthAccessToken = OAuthProviderConfigSchema.extend({
132
+ redirectURI: (0, import_v4.string)(),
133
+ code: (0, import_v4.string)(),
134
+ codeVerifier: (0, import_v4.string)().min(43).max(128)
135
+ });
136
+ var OAuthAccessTokenResponse = (0, import_v4.object)({
137
+ access_token: (0, import_v4.string)(),
138
+ token_type: (0, import_v4.string)().optional(),
139
+ expires_in: (0, import_v4.number)().optional(),
140
+ refresh_token: (0, import_v4.string)().optional(),
141
+ scope: (0, import_v4.union)([(0, import_v4.string)().optional().or((0, import_v4.null)()), (0, import_v4.array)((0, import_v4.string)()).optional()])
142
+ });
143
+ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
144
+ error: (0, import_v4.enum)([
145
+ "invalid_request",
146
+ "invalid_client",
147
+ "invalid_grant",
148
+ "unauthorized_client",
149
+ "unsupported_grant_type",
150
+ "invalid_scope"
151
+ ]),
152
+ error_description: (0, import_v4.string)().optional(),
153
+ error_uri: (0, import_v4.string)().optional()
154
+ });
155
+ var OAuthErrorResponse = (0, import_v4.object)({
156
+ error: (0, import_v4.string)(),
157
+ error_description: (0, import_v4.string)().optional()
158
+ });
159
+ var OAuthEnvSchema = (0, import_v4.object)({
160
+ clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
161
+ clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
162
+ });
163
+
164
+ // src/utils.ts
165
+ var import_router = require("@aura-stack/router");
166
+
167
+ // src/env.ts
168
+ var import_meta = {};
169
+ var env = new Proxy({}, {
170
+ get(_, prop) {
171
+ if (typeof prop !== "string") return void 0;
172
+ const hasProperty = (process2) => {
173
+ return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
174
+ };
175
+ try {
176
+ if (typeof process !== "undefined" && hasProperty(process.env)) {
177
+ return process.env[prop];
178
+ }
179
+ if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
180
+ return import_meta.env[prop];
181
+ }
182
+ if (typeof Deno !== "undefined" && Deno.env?.get) {
183
+ return Deno.env.get(prop);
184
+ }
185
+ if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
186
+ return Bun.env[prop];
187
+ }
188
+ const globalValue = globalThis[prop];
189
+ return typeof globalValue === "string" ? globalValue : void 0;
190
+ } catch {
191
+ return void 0;
192
+ }
193
+ }
194
+ });
195
+
196
+ // src/assert.ts
197
+ var import_crypto = require("@aura-stack/jose/crypto");
198
+
199
+ // src/jose.ts
200
+ var import_jose = require("@aura-stack/jose");
201
+ var import_jose2 = require("@aura-stack/jose/jose");
202
+ var import_crypto2 = require("@aura-stack/jose/crypto");
203
+
204
+ // src/secure.ts
205
+ var generateSecure = (length = 32) => {
206
+ return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
207
+ };
208
+ var createSecretValue = (length = 32) => {
209
+ return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
210
+ };
211
+ var createHash = async (data) => {
212
+ const subtle = (0, import_crypto2.getSubtleCrypto)();
213
+ const digest = await subtle.digest("SHA-256", import_crypto2.encoder.encode(data));
214
+ return import_jose2.base64url.encode(new Uint8Array(digest));
215
+ };
216
+ var createPKCE = async (verifier) => {
217
+ const byteLength = verifier ? void 0 : Math.floor(Math.random() * (96 - 32 + 1) + 32);
218
+ const codeVerifier = verifier ?? generateSecure(byteLength ?? 64);
219
+ if (codeVerifier.length < 43 || codeVerifier.length > 128) {
220
+ throw new AuthSecurityError("PKCE_VERIFIER_INVALID", "The code verifier must be between 43 and 128 characters in length.");
221
+ }
222
+ const codeChallenge = await createHash(codeVerifier);
223
+ return { codeVerifier, codeChallenge, method: "S256" };
224
+ };
225
+
226
+ // src/actions/signIn/authorization-url.ts
227
+ var setSearchParams = (url, params) => {
228
+ for (const [key, value] of Object.entries(params)) {
229
+ if (value !== void 0 && value !== "") {
230
+ url.searchParams.set(key, value);
231
+ }
232
+ }
233
+ };
234
+ var buildAuthorizationURL = (oauth, redirect_uri, state, code_challenge, code_challenge_method) => {
235
+ const authorizeConfig = oauth.authorize;
236
+ const baseURL = typeof authorizeConfig === "string" ? authorizeConfig : authorizeConfig?.url ?? oauth.authorizeURL;
237
+ if (!baseURL) {
238
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "Missing authorization URL in OAuth provider configuration.");
239
+ }
240
+ const url = new URL(baseURL);
241
+ const authorizeParams = typeof authorizeConfig === "string" ? void 0 : authorizeConfig?.params;
242
+ setSearchParams(url, {
243
+ response_type: authorizeParams?.responseType ?? oauth.responseType ?? "code",
244
+ client_id: oauth.clientId,
245
+ redirect_uri,
246
+ state,
247
+ code_challenge,
248
+ code_challenge_method,
249
+ scope: authorizeParams?.scope ?? oauth.scope,
250
+ prompt: authorizeParams?.prompt,
251
+ response_mode: authorizeParams?.responseMode,
252
+ login_hint: authorizeParams?.loginHint,
253
+ nonce: authorizeParams?.nonce,
254
+ display: authorizeParams?.display,
255
+ audience: authorizeParams?.audience
256
+ });
257
+ return url.toString();
258
+ };
259
+ var createAuthorizationURL = async (oauth, redirectURI, ctx) => {
260
+ const state = createSecretValue();
261
+ const { codeVerifier, codeChallenge, method } = await createPKCE();
262
+ const authorization = buildAuthorizationURL(oauth, redirectURI, state, codeChallenge, method);
263
+ const parsed = OAuthAuthorization.safeParse({ ...oauth, redirectURI, state, codeChallenge, codeChallengeMethod: method });
264
+ if (!parsed.success) {
265
+ ctx?.logger?.log("INVALID_OAUTH_CONFIGURATION", {
266
+ structuredData: {
267
+ scope: oauth?.scope ?? "",
268
+ redirect_uri: redirectURI,
269
+ has_state: Boolean(state),
270
+ has_code_challenge: Boolean(codeChallenge),
271
+ code_challenge_method: method
272
+ }
273
+ });
274
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "The OAuth provider configuration is invalid.");
275
+ }
276
+ return {
277
+ authorization,
278
+ state,
279
+ codeVerifier,
280
+ method
281
+ };
282
+ };
283
+ // Annotate the CommonJS export names for ESM import in node:
284
+ 0 && (module.exports = {
285
+ buildAuthorizationURL,
286
+ createAuthorizationURL,
287
+ setSearchParams
288
+ });
@@ -0,0 +1,31 @@
1
+ import { k as OAuthProvider } from '../../index-_aXtxb_s.js';
2
+ import { GlobalContext } from '@aura-stack/router';
3
+ import 'zod';
4
+ import '../../schemas.js';
5
+ import 'zod/v4';
6
+ import '@aura-stack/jose';
7
+ import '@aura-stack/jose/jose';
8
+ import '@aura-stack/jose/crypto';
9
+ import '@aura-stack/router/cookie';
10
+ import '../../@types/utility.js';
11
+ import 'jose';
12
+ import 'zod/v4/core';
13
+
14
+ declare const setSearchParams: (url: URL, params: Record<string, string | undefined>) => void;
15
+ declare const buildAuthorizationURL: (oauth: OAuthProvider, redirect_uri: string, state: string, code_challenge: string, code_challenge_method: string) => string;
16
+ /**
17
+ * Constructs the request URI for the Authorization Request to the third-party OAuth service. It includes
18
+ * the necessary query parameters such as `client_id`, `redirect_uri`, `response_type`, `scope`, `state`,
19
+ * `code_challenge`, and `code_challenge_method`.
20
+ *
21
+ * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
22
+ * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4
23
+ */
24
+ declare const createAuthorizationURL: (oauth: OAuthProvider, redirectURI: string, ctx?: GlobalContext) => Promise<{
25
+ authorization: string;
26
+ state: string;
27
+ codeVerifier: string;
28
+ method: string;
29
+ }>;
30
+
31
+ export { buildAuthorizationURL, createAuthorizationURL, setSearchParams };
@@ -0,0 +1,16 @@
1
+ import {
2
+ buildAuthorizationURL,
3
+ createAuthorizationURL,
4
+ setSearchParams
5
+ } from "../../chunk-D2CSIUKP.js";
6
+ import "../../chunk-V6LLEAR4.js";
7
+ import "../../chunk-2A5B7GWR.js";
8
+ import "../../chunk-UZQJJD6A.js";
9
+ import "../../chunk-LX3TJ2TJ.js";
10
+ import "../../chunk-WHNDRO3N.js";
11
+ import "../../chunk-U5663F2U.js";
12
+ export {
13
+ buildAuthorizationURL,
14
+ createAuthorizationURL,
15
+ setSearchParams
16
+ };