@aura-stack/auth 0.4.0 → 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 (149) hide show
  1. package/dist/@types/index.d.ts +6 -2
  2. package/dist/@types/router.d.d.ts +6 -2
  3. package/dist/actions/callback/access-token.cjs +103 -59
  4. package/dist/actions/callback/access-token.d.ts +7 -3
  5. package/dist/actions/callback/access-token.js +3 -3
  6. package/dist/actions/callback/callback.cjs +200 -134
  7. package/dist/actions/callback/callback.d.ts +32 -3
  8. package/dist/actions/callback/callback.js +11 -12
  9. package/dist/actions/callback/userinfo.cjs +103 -70
  10. package/dist/actions/callback/userinfo.d.ts +6 -2
  11. package/dist/actions/callback/userinfo.js +7 -8
  12. package/dist/actions/csrfToken/csrfToken.cjs +7 -15
  13. package/dist/actions/csrfToken/csrfToken.d.ts +3 -1
  14. package/dist/actions/csrfToken/csrfToken.js +7 -8
  15. package/dist/actions/index.cjs +502 -295
  16. package/dist/actions/index.d.ts +5 -2
  17. package/dist/actions/index.js +23 -20
  18. package/dist/actions/session/session.cjs +76 -24
  19. package/dist/actions/session/session.d.ts +3 -1
  20. package/dist/actions/session/session.js +6 -4
  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 +91 -132
  25. package/dist/actions/signIn/authorization.d.ts +17 -16
  26. package/dist/actions/signIn/authorization.js +8 -7
  27. package/dist/actions/signIn/signIn.cjs +319 -191
  28. package/dist/actions/signIn/signIn.d.ts +32 -3
  29. package/dist/actions/signIn/signIn.js +10 -9
  30. package/dist/actions/signOut/signOut.cjs +211 -212
  31. package/dist/actions/signOut/signOut.d.ts +9 -1
  32. package/dist/actions/signOut/signOut.js +9 -10
  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 +42 -9
  46. package/dist/assert.d.ts +8 -4
  47. package/dist/assert.js +5 -5
  48. package/dist/{chunk-KJBAQZX2.js → chunk-2A5B7GWR.js} +44 -11
  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-5X7JZMEF.js +0 -0
  54. package/dist/{chunk-TZB6MUXN.js → chunk-7BE46WWS.js} +21 -11
  55. package/dist/chunk-7YYXFKLR.js +35 -0
  56. package/dist/chunk-C3A37LQC.js +33 -0
  57. package/dist/chunk-CITNGXDA.js +31 -0
  58. package/dist/chunk-CWX724AG.js +78 -0
  59. package/dist/chunk-D2CSIUKP.js +74 -0
  60. package/dist/{chunk-ICAZ4OVS.js → chunk-FPCVZUVG.js} +2 -2
  61. package/dist/{chunk-XGLBNXL4.js → chunk-GNNBM2WJ.js} +17 -9
  62. package/dist/chunk-JOCGX3RP.js +59 -0
  63. package/dist/chunk-KBXWTD6E.js +94 -0
  64. package/dist/{chunk-XUP6KKNG.js → chunk-LATR3NIV.js} +48 -37
  65. package/dist/chunk-LAYPUDQF.js +39 -0
  66. package/dist/chunk-LX3TJ2TJ.js +294 -0
  67. package/dist/{chunk-6MXFPFR3.js → chunk-NHZBQNRR.js} +19 -19
  68. package/dist/{chunk-TM5IPSNF.js → chunk-PDP3PHB3.js} +33 -19
  69. package/dist/chunk-PHYNROD4.js +47 -0
  70. package/dist/chunk-QQEKY4XP.js +29 -0
  71. package/dist/{chunk-VNCNJKS2.js → chunk-U4RK4LKJ.js} +82 -1
  72. package/dist/{chunk-RRLIF4PQ.js → chunk-U5663F2U.js} +16 -1
  73. package/dist/chunk-UN7X6SU5.js +53 -0
  74. package/dist/chunk-UZQJJD6A.js +100 -0
  75. package/dist/{chunk-NUDITUKX.js → chunk-V6LLEAR4.js} +22 -15
  76. package/dist/{chunk-4MYWAOLG.js → chunk-WHNDRO3N.js} +20 -1
  77. package/dist/{chunk-5W4BRQYG.js → chunk-XY5R3EHH.js} +6 -3
  78. package/dist/client/client.cjs +135 -0
  79. package/dist/client/client.d.ts +85 -0
  80. package/dist/client/client.js +9 -0
  81. package/dist/client/index.cjs +135 -0
  82. package/dist/client/index.d.ts +14 -0
  83. package/dist/client/index.js +10 -0
  84. package/dist/context.cjs +1237 -0
  85. package/dist/context.d.ts +16 -0
  86. package/dist/context.js +28 -0
  87. package/dist/cookie.cjs +33 -2
  88. package/dist/cookie.d.ts +9 -5
  89. package/dist/cookie.js +3 -2
  90. package/dist/createAuth.cjs +2320 -0
  91. package/dist/createAuth.d.ts +12 -0
  92. package/dist/createAuth.js +48 -0
  93. package/dist/env.cjs +24 -2
  94. package/dist/env.d.ts +4 -1
  95. package/dist/env.js +9 -3
  96. package/dist/errors.cjs +17 -0
  97. package/dist/errors.d.ts +13 -3
  98. package/dist/errors.js +5 -1
  99. package/dist/{index-CSyIJmCM.d.ts → index-_aXtxb_s.d.ts} +383 -13
  100. package/dist/index.cjs +2135 -1547
  101. package/dist/index.d.ts +9 -30
  102. package/dist/index.js +46 -119
  103. package/dist/jose.cjs +52 -14
  104. package/dist/jose.d.ts +12 -25
  105. package/dist/jose.js +11 -3
  106. package/dist/logger.cjs +132 -0
  107. package/dist/logger.d.ts +6 -2
  108. package/dist/logger.js +10 -1
  109. package/dist/oauth/atlassian.cjs +57 -0
  110. package/dist/oauth/atlassian.d.ts +12 -0
  111. package/dist/oauth/atlassian.js +6 -0
  112. package/dist/oauth/bitbucket.d.ts +6 -2
  113. package/dist/oauth/discord.d.ts +6 -2
  114. package/dist/oauth/dropbox.cjs +53 -0
  115. package/dist/oauth/dropbox.d.ts +12 -0
  116. package/dist/oauth/dropbox.js +6 -0
  117. package/dist/oauth/figma.d.ts +6 -2
  118. package/dist/oauth/github.d.ts +6 -2
  119. package/dist/oauth/gitlab.d.ts +6 -2
  120. package/dist/oauth/index.cjs +278 -88
  121. package/dist/oauth/index.d.ts +6 -2
  122. package/dist/oauth/index.js +27 -11
  123. package/dist/oauth/mailchimp.d.ts +6 -2
  124. package/dist/oauth/notion.cjs +131 -0
  125. package/dist/oauth/notion.d.ts +12 -0
  126. package/dist/oauth/notion.js +9 -0
  127. package/dist/oauth/pinterest.d.ts +6 -2
  128. package/dist/oauth/spotify.d.ts +6 -2
  129. package/dist/oauth/strava.d.ts +6 -2
  130. package/dist/oauth/twitch.cjs +95 -0
  131. package/dist/oauth/twitch.d.ts +12 -0
  132. package/dist/oauth/twitch.js +7 -0
  133. package/dist/oauth/x.d.ts +6 -2
  134. package/dist/schemas.cjs +84 -51
  135. package/dist/schemas.d.ts +103 -23
  136. package/dist/schemas.js +1 -1
  137. package/dist/secure.cjs +36 -36
  138. package/dist/secure.d.ts +10 -4
  139. package/dist/secure.js +7 -6
  140. package/dist/utils.cjs +109 -3
  141. package/dist/utils.d.ts +15 -4
  142. package/dist/utils.js +11 -4
  143. package/package.json +9 -5
  144. package/dist/chunk-4EKY7655.js +0 -123
  145. package/dist/chunk-7QF22LHP.js +0 -67
  146. package/dist/chunk-ALG3GIV4.js +0 -95
  147. package/dist/chunk-FRJFWTOY.js +0 -70
  148. package/dist/chunk-PHFH2MGS.js +0 -36
  149. package/dist/chunk-QQVSRXGX.js +0 -149
@@ -4,11 +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 '../index-CSyIJmCM.js';
7
+ import 'zod/v4';
8
+ import '../index-_aXtxb_s.js';
8
9
  import 'zod';
9
10
  import '../schemas.js';
10
- import '../jose.js';
11
11
  import '@aura-stack/jose';
12
12
  import '@aura-stack/jose/jose';
13
+ import '@aura-stack/jose/crypto';
13
14
  import '@aura-stack/router/cookie';
14
15
  import '../@types/utility.js';
16
+ import 'jose';
17
+ import 'zod/v4/core';
@@ -1,32 +1,35 @@
1
1
  import "../chunk-ITQ7352M.js";
2
2
  import {
3
- signInAction
4
- } from "../chunk-7QF22LHP.js";
3
+ callbackAction
4
+ } from "../chunk-NHZBQNRR.js";
5
+ import "../chunk-GNNBM2WJ.js";
5
6
  import {
6
7
  csrfTokenAction
7
- } from "../chunk-ICAZ4OVS.js";
8
- import {
9
- signOutAction
10
- } from "../chunk-ALG3GIV4.js";
8
+ } from "../chunk-FPCVZUVG.js";
11
9
  import {
12
- callbackAction
13
- } from "../chunk-6MXFPFR3.js";
14
- import "../chunk-TZB6MUXN.js";
15
- import "../chunk-XGLBNXL4.js";
10
+ signInAction
11
+ } from "../chunk-UN7X6SU5.js";
16
12
  import {
17
13
  sessionAction
18
- } from "../chunk-PHFH2MGS.js";
19
- import "../chunk-XUP6KKNG.js";
14
+ } from "../chunk-7YYXFKLR.js";
15
+ import {
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";
20
24
  import "../chunk-ZNCZVF6U.js";
21
- import "../chunk-KJBAQZX2.js";
22
- import "../chunk-NUDITUKX.js";
23
- import "../chunk-4EKY7655.js";
24
- import "../chunk-QQVSRXGX.js";
25
- import "../chunk-5W4BRQYG.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";
26
32
  import "../chunk-EBAMFRB7.js";
27
- import "../chunk-FRJFWTOY.js";
28
- import "../chunk-4MYWAOLG.js";
29
- import "../chunk-RRLIF4PQ.js";
30
33
  export {
31
34
  callbackAction,
32
35
  csrfTokenAction,
@@ -53,8 +53,37 @@ var secureApiHeaders = {
53
53
  ...secureHeaders
54
54
  };
55
55
 
56
- // src/utils.ts
57
- var import_router = require("@aura-stack/router");
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");
58
87
 
59
88
  // src/errors.ts
60
89
  var AuthInternalError = class extends Error {
@@ -68,19 +97,7 @@ var AuthInternalError = class extends Error {
68
97
  }
69
98
  };
70
99
 
71
- // src/utils.ts
72
- var toISOString = (date) => {
73
- return new Date(date).toISOString();
74
- };
75
- var getErrorName = (error) => {
76
- if (error instanceof Error) {
77
- return error.name;
78
- }
79
- return typeof error === "string" ? error : "UnknownError";
80
- };
81
-
82
100
  // src/cookie.ts
83
- var import_cookie = require("@aura-stack/router/cookie");
84
101
  var defaultCookieOptions = {
85
102
  httpOnly: true,
86
103
  sameSite: "lax",
@@ -100,7 +117,7 @@ var expiredCookieAttributes = {
100
117
  secure: true
101
118
  };
102
119
  var getCookie = (request, cookieName) => {
103
- const cookies = request.headers.get("Cookie");
120
+ const cookies = request instanceof Request ? request.headers.get("Cookie") : request.get("Cookie");
104
121
  if (!cookies) {
105
122
  throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
106
123
  }
@@ -111,23 +128,58 @@ var getCookie = (request, cookieName) => {
111
128
  return value;
112
129
  };
113
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
+
114
168
  // src/actions/session/session.ts
115
169
  var sessionAction = (0, import_router2.createEndpoint)("GET", "/session", async (ctx) => {
116
170
  const {
117
171
  request,
118
- context: { jose, cookies, logger }
172
+ context: { cookies }
119
173
  } = ctx;
120
174
  try {
121
- const session = getCookie(request, cookies.sessionToken.name);
122
- const decoded = await jose.decodeJWT(session);
123
- logger?.log("AUTH_SESSION_VALID");
124
- const { exp, iat, jti, nbf, ...user } = decoded;
125
- const headers = new Headers(secureApiHeaders);
126
- 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 });
127
180
  } catch (error) {
128
- logger?.log("AUTH_SESSION_INVALID", { structuredData: { error_type: getErrorName(error) } });
129
181
  const headers = new import_router2.HeadersBuilder(secureApiHeaders).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
130
- return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
182
+ return Response.json({ session: null, authenticated: false }, { status: 401, headers });
131
183
  }
132
184
  });
133
185
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,5 +1,7 @@
1
1
  import * as _aura_stack_router from '@aura-stack/router';
2
2
 
3
- declare const sessionAction: _aura_stack_router.RouteEndpoint<"GET", "/session", {}>;
3
+ declare const sessionAction: _aura_stack_router.RouteEndpoint<"GET", "/session", {
4
+ schemas?: _aura_stack_router.EndpointSchemas | undefined;
5
+ }>;
4
6
 
5
7
  export { sessionAction };
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  sessionAction
3
- } from "../../chunk-PHFH2MGS.js";
4
- import "../../chunk-QQVSRXGX.js";
5
- import "../../chunk-5W4BRQYG.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";
6
9
  import "../../chunk-EBAMFRB7.js";
7
- import "../../chunk-RRLIF4PQ.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
+ };