@aura-stack/auth 0.1.0 → 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.
- package/dist/@types/index.d.ts +5 -5
- package/dist/@types/router.d.d.ts +5 -5
- package/dist/@types/utility.d.ts +1 -5
- package/dist/actions/callback/access-token.cjs +95 -74
- package/dist/actions/callback/access-token.d.ts +7 -7
- package/dist/actions/callback/access-token.js +5 -3
- package/dist/actions/callback/callback.cjs +171 -249
- package/dist/actions/callback/callback.d.ts +6 -6
- package/dist/actions/callback/callback.js +10 -10
- package/dist/actions/callback/userinfo.cjs +81 -57
- package/dist/actions/callback/userinfo.d.ts +5 -5
- package/dist/actions/callback/userinfo.js +7 -5
- package/dist/actions/csrfToken/csrfToken.cjs +36 -105
- package/dist/actions/csrfToken/csrfToken.js +6 -6
- package/dist/actions/index.cjs +309 -444
- package/dist/actions/index.d.ts +5 -5
- package/dist/actions/index.js +19 -19
- package/dist/actions/session/session.cjs +25 -109
- package/dist/actions/session/session.js +4 -5
- package/dist/actions/signIn/authorization.cjs +96 -87
- package/dist/actions/signIn/authorization.d.ts +5 -5
- package/dist/actions/signIn/authorization.js +5 -5
- package/dist/actions/signIn/signIn.cjs +133 -242
- package/dist/actions/signIn/signIn.d.ts +6 -6
- package/dist/actions/signIn/signIn.js +8 -9
- package/dist/actions/signOut/signOut.cjs +136 -282
- package/dist/actions/signOut/signOut.js +8 -9
- package/dist/assert.cjs +5 -0
- package/dist/assert.d.ts +10 -1
- package/dist/assert.js +3 -1
- package/dist/chunk-3EUWD5BB.js +63 -0
- package/dist/chunk-6R2YZ4AC.js +22 -0
- package/dist/chunk-A3N4PVAT.js +70 -0
- package/dist/chunk-B737EUJV.js +22 -0
- package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
- package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
- package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
- package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
- package/dist/chunk-HP34YGGJ.js +22 -0
- package/dist/chunk-HT4YLL7N.js +35 -0
- package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
- package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
- package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
- package/dist/chunk-KSWLO5ZU.js +102 -0
- package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
- package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
- package/dist/chunk-RRLIF4PQ.js +55 -0
- package/dist/chunk-TLE4PXY3.js +39 -0
- package/dist/chunk-W6LG7BFW.js +197 -0
- package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
- package/dist/chunk-ZNCZVF6U.js +14 -0
- package/dist/cookie.cjs +140 -99
- package/dist/cookie.d.ts +35 -44
- package/dist/cookie.js +10 -17
- package/dist/errors.cjs +85 -0
- package/dist/errors.d.ts +49 -0
- package/dist/errors.js +18 -0
- package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
- package/dist/index.cjs +543 -443
- package/dist/index.d.ts +6 -6
- package/dist/index.js +42 -28
- package/dist/jose.cjs +25 -14
- package/dist/jose.d.ts +4 -1
- package/dist/jose.js +5 -4
- package/dist/oauth/bitbucket.d.ts +5 -5
- package/dist/oauth/discord.cjs +0 -1
- package/dist/oauth/discord.d.ts +5 -5
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/figma.d.ts +5 -5
- package/dist/oauth/github.d.ts +5 -5
- package/dist/oauth/gitlab.d.ts +5 -5
- package/dist/oauth/index.cjs +176 -6
- package/dist/oauth/index.d.ts +5 -5
- package/dist/oauth/index.js +19 -4
- package/dist/oauth/mailchimp.cjs +46 -0
- package/dist/oauth/mailchimp.d.ts +7 -0
- package/dist/oauth/mailchimp.js +6 -0
- package/dist/oauth/pinterest.cjs +46 -0
- package/dist/oauth/pinterest.d.ts +7 -0
- package/dist/oauth/pinterest.js +6 -0
- package/dist/oauth/spotify.d.ts +5 -5
- package/dist/oauth/strava.cjs +46 -0
- package/dist/oauth/strava.d.ts +7 -0
- package/dist/oauth/strava.js +6 -0
- package/dist/oauth/x.d.ts +5 -5
- package/dist/{response.cjs → request.cjs} +14 -10
- package/dist/request.d.ts +13 -0
- package/dist/request.js +6 -0
- package/dist/schemas.cjs +43 -37
- package/dist/schemas.d.ts +67 -64
- package/dist/schemas.js +3 -1
- package/dist/secure.cjs +32 -24
- package/dist/secure.d.ts +5 -5
- package/dist/secure.js +4 -3
- package/dist/utils.cjs +90 -15
- package/dist/utils.d.ts +11 -2
- package/dist/utils.js +8 -4
- package/package.json +8 -7
- package/dist/chunk-FJUDBLCP.js +0 -59
- package/dist/chunk-HGJ4TXY4.js +0 -137
- package/dist/chunk-JAPMIE6S.js +0 -10
- package/dist/chunk-LLR722CL.js +0 -96
- package/dist/chunk-SJPDVKUS.js +0 -112
- package/dist/chunk-SMQO5WD7.js +0 -30
- package/dist/chunk-UTDLUEEG.js +0 -31
- package/dist/chunk-ZV4BH47P.js +0 -154
- package/dist/error.cjs +0 -88
- package/dist/error.d.ts +0 -62
- package/dist/error.js +0 -16
- package/dist/response.d.ts +0 -10
- package/dist/response.js +0 -6
|
@@ -33,57 +33,46 @@ __export(signIn_exports, {
|
|
|
33
33
|
signInAction: () => signInAction
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(signIn_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_zod2 = require("zod");
|
|
37
37
|
var import_router2 = require("@aura-stack/router");
|
|
38
38
|
|
|
39
|
-
// src/
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// src/headers.ts
|
|
40
|
+
var cacheControl = {
|
|
41
|
+
"Cache-Control": "no-store",
|
|
42
|
+
Pragma: "no-cache",
|
|
43
|
+
Expires: "0",
|
|
44
|
+
Vary: "Cookie"
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
// src/secure.ts
|
|
47
|
-
var
|
|
48
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
48
49
|
|
|
49
50
|
// src/utils.ts
|
|
50
51
|
var import_router = require("@aura-stack/router");
|
|
51
52
|
|
|
52
|
-
// src/
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
// src/errors.ts
|
|
54
|
+
var AuthInternalError = class extends Error {
|
|
55
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
56
|
+
code;
|
|
57
|
+
constructor(code, message, options2) {
|
|
58
|
+
super(message, options2);
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.name = new.target.name;
|
|
61
|
+
Error.captureStackTrace(this, new.target);
|
|
58
62
|
}
|
|
59
63
|
};
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
var AuthSecurityError = class extends Error {
|
|
65
|
+
type = "AUTH_SECURITY_ERROR";
|
|
66
|
+
code;
|
|
67
|
+
constructor(code, message, options2) {
|
|
68
|
+
super(message, options2);
|
|
69
|
+
this.code = code;
|
|
70
|
+
this.name = new.target.name;
|
|
71
|
+
Error.captureStackTrace(this, new.target);
|
|
64
72
|
}
|
|
65
73
|
};
|
|
66
|
-
var
|
|
67
|
-
return error instanceof
|
|
68
|
-
};
|
|
69
|
-
var ERROR_RESPONSE = {
|
|
70
|
-
AUTHORIZATION: {
|
|
71
|
-
INVALID_REQUEST: "invalid_request",
|
|
72
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
73
|
-
ACCESS_DENIED: "access_denied",
|
|
74
|
-
UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
|
|
75
|
-
INVALID_SCOPE: "invalid_scope",
|
|
76
|
-
SERVER_ERROR: "server_error",
|
|
77
|
-
TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
|
|
78
|
-
},
|
|
79
|
-
ACCESS_TOKEN: {
|
|
80
|
-
INVALID_REQUEST: "invalid_request",
|
|
81
|
-
INVALID_CLIENT: "invalid_client",
|
|
82
|
-
INVALID_GRANT: "invalid_grant",
|
|
83
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
84
|
-
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
85
|
-
INVALID_SCOPE: "invalid_scope"
|
|
86
|
-
}
|
|
74
|
+
var isAuthSecurityError = (error) => {
|
|
75
|
+
return error instanceof AuthSecurityError;
|
|
87
76
|
};
|
|
88
77
|
|
|
89
78
|
// src/utils.ts
|
|
@@ -103,9 +92,9 @@ var equals = (a, b) => {
|
|
|
103
92
|
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
104
93
|
return a === b;
|
|
105
94
|
};
|
|
106
|
-
var sanitizeURL = (
|
|
95
|
+
var sanitizeURL = (url) => {
|
|
107
96
|
try {
|
|
108
|
-
let decodedURL = decodeURIComponent(
|
|
97
|
+
let decodedURL = decodeURIComponent(url).trim();
|
|
109
98
|
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
|
|
110
99
|
let protocol = "";
|
|
111
100
|
let rest = decodedURL;
|
|
@@ -133,36 +122,35 @@ var sanitizeURL = (url2) => {
|
|
|
133
122
|
}
|
|
134
123
|
return sanitized;
|
|
135
124
|
} catch {
|
|
136
|
-
return
|
|
125
|
+
return url.trim();
|
|
137
126
|
}
|
|
138
127
|
};
|
|
139
128
|
var getNormalizedOriginPath = (path) => {
|
|
140
129
|
try {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return `${
|
|
130
|
+
const url = new URL(path);
|
|
131
|
+
url.hash = "";
|
|
132
|
+
url.search = "";
|
|
133
|
+
return `${url.origin}${url.pathname}`;
|
|
145
134
|
} catch {
|
|
146
135
|
return sanitizeURL(path);
|
|
147
136
|
}
|
|
148
137
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
138
|
+
var formatZodError = (error) => {
|
|
139
|
+
if (!error.issues || error.issues.length === 0) {
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
return error.issues.reduce((previous, issue) => {
|
|
143
|
+
const key = issue.path.join(".");
|
|
144
|
+
return {
|
|
145
|
+
...previous,
|
|
146
|
+
[key]: {
|
|
147
|
+
code: issue.code,
|
|
148
|
+
message: issue.message
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}, {});
|
|
161
152
|
};
|
|
162
153
|
|
|
163
|
-
// src/cookie.ts
|
|
164
|
-
var import_cookie = require("cookie");
|
|
165
|
-
|
|
166
154
|
// src/assert.ts
|
|
167
155
|
var isValidURL = (value) => {
|
|
168
156
|
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
|
|
@@ -170,123 +158,42 @@ var isValidURL = (value) => {
|
|
|
170
158
|
return regex.test(value);
|
|
171
159
|
};
|
|
172
160
|
|
|
173
|
-
// src/
|
|
174
|
-
var
|
|
175
|
-
|
|
176
|
-
var defaultCookieOptions = {
|
|
177
|
-
httpOnly: true,
|
|
178
|
-
sameSite: "lax",
|
|
179
|
-
path: "/",
|
|
180
|
-
maxAge: 60 * 60 * 24 * 15
|
|
181
|
-
};
|
|
182
|
-
var defaultStandardCookieConfig = {
|
|
183
|
-
secure: false,
|
|
184
|
-
httpOnly: true,
|
|
185
|
-
prefix: ""
|
|
186
|
-
};
|
|
187
|
-
var defaultSecureCookieConfig = {
|
|
188
|
-
secure: true,
|
|
189
|
-
prefix: "__Secure-"
|
|
190
|
-
};
|
|
191
|
-
var defaultHostCookieConfig = {
|
|
192
|
-
secure: true,
|
|
193
|
-
prefix: "__Host-",
|
|
194
|
-
path: "/",
|
|
195
|
-
domain: void 0
|
|
196
|
-
};
|
|
197
|
-
var expiredCookieOptions = {
|
|
198
|
-
...defaultCookieOptions,
|
|
199
|
-
expires: /* @__PURE__ */ new Date(0),
|
|
200
|
-
maxAge: 0
|
|
201
|
-
};
|
|
202
|
-
var defineDefaultCookieOptions = (options2) => {
|
|
203
|
-
return {
|
|
204
|
-
name: options2?.name ?? COOKIE_NAME,
|
|
205
|
-
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
206
|
-
...defaultCookieOptions,
|
|
207
|
-
...options2
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
var setCookie = (cookieName, value, options2) => {
|
|
211
|
-
const { prefix, name } = defineDefaultCookieOptions(options2);
|
|
212
|
-
const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
|
|
213
|
-
return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
|
|
214
|
-
...defaultCookieOptions,
|
|
215
|
-
...options2
|
|
216
|
-
});
|
|
161
|
+
// src/secure.ts
|
|
162
|
+
var generateSecure = (length = 32) => {
|
|
163
|
+
return import_crypto.default.randomBytes(length).toString("base64url");
|
|
217
164
|
};
|
|
218
|
-
var
|
|
219
|
-
|
|
220
|
-
const isSecure = trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || request.headers.get("Forwarded")?.includes("proto=https") : request.url.startsWith("https://");
|
|
221
|
-
if (!cookieOptions.options?.httpOnly) {
|
|
222
|
-
console.warn(
|
|
223
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
if (cookieOptions.options?.domain === "*") {
|
|
227
|
-
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
|
|
228
|
-
}
|
|
229
|
-
if (!isSecure) {
|
|
230
|
-
const options2 = cookieOptions.options;
|
|
231
|
-
if (options2?.secure) {
|
|
232
|
-
console.warn(
|
|
233
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
if (options2?.sameSite == "none") {
|
|
237
|
-
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
|
|
238
|
-
}
|
|
239
|
-
if (process.env.NODE_ENV === "production") {
|
|
240
|
-
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
...defaultCookieOptions,
|
|
244
|
-
...cookieOptions.options,
|
|
245
|
-
sameSite: options2?.sameSite === "none" ? "lax" : options2?.sameSite ?? "lax",
|
|
246
|
-
...defaultStandardCookieConfig,
|
|
247
|
-
name
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
return cookieOptions.strategy === "host" ? {
|
|
251
|
-
...defaultCookieOptions,
|
|
252
|
-
...cookieOptions.options,
|
|
253
|
-
...defaultHostCookieConfig,
|
|
254
|
-
name
|
|
255
|
-
} : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
|
|
165
|
+
var createHash = (data, base = "hex") => {
|
|
166
|
+
return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
|
|
256
167
|
};
|
|
257
|
-
var
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
httpOnly: options2.httpOnly,
|
|
262
|
-
maxAge: 5 * 60,
|
|
263
|
-
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
264
|
-
};
|
|
168
|
+
var createPKCE = async (verifier) => {
|
|
169
|
+
const codeVerifier = verifier ?? generateSecure(86);
|
|
170
|
+
const codeChallenge = createHash(codeVerifier, "base64url");
|
|
171
|
+
return { codeVerifier, codeChallenge, method: "S256" };
|
|
265
172
|
};
|
|
266
173
|
|
|
267
174
|
// src/schemas.ts
|
|
268
|
-
var
|
|
269
|
-
var OAuthProviderConfigSchema = (0,
|
|
270
|
-
authorizeURL: (0,
|
|
271
|
-
accessToken: (0,
|
|
272
|
-
scope: (0,
|
|
273
|
-
userInfo: (0,
|
|
274
|
-
responseType: (0,
|
|
275
|
-
clientId: (0,
|
|
276
|
-
clientSecret: (0,
|
|
175
|
+
var import_zod = require("zod");
|
|
176
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
177
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
178
|
+
accessToken: (0, import_zod.string)().url(),
|
|
179
|
+
scope: (0, import_zod.string)().optional(),
|
|
180
|
+
userInfo: (0, import_zod.string)().url(),
|
|
181
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
182
|
+
clientId: (0, import_zod.string)(),
|
|
183
|
+
clientSecret: (0, import_zod.string)()
|
|
277
184
|
});
|
|
278
185
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
279
|
-
redirectURI: (0,
|
|
280
|
-
state: (0,
|
|
281
|
-
codeChallenge: (0,
|
|
282
|
-
codeChallengeMethod: (0,
|
|
186
|
+
redirectURI: (0, import_zod.string)(),
|
|
187
|
+
state: (0, import_zod.string)(),
|
|
188
|
+
codeChallenge: (0, import_zod.string)(),
|
|
189
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
283
190
|
});
|
|
284
|
-
var OAuthAuthorizationResponse = (0,
|
|
285
|
-
state: (0,
|
|
286
|
-
code: (0,
|
|
191
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
192
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
193
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
287
194
|
});
|
|
288
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
289
|
-
error: (0,
|
|
195
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
196
|
+
error: (0, import_zod.enum)([
|
|
290
197
|
"invalid_request",
|
|
291
198
|
"unauthorized_client",
|
|
292
199
|
"access_denied",
|
|
@@ -295,24 +202,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
|
295
202
|
"server_error",
|
|
296
203
|
"temporarily_unavailable"
|
|
297
204
|
]),
|
|
298
|
-
error_description: (0,
|
|
299
|
-
error_uri: (0,
|
|
300
|
-
state: (0,
|
|
205
|
+
error_description: (0, import_zod.string)().optional(),
|
|
206
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
207
|
+
state: (0, import_zod.string)()
|
|
301
208
|
});
|
|
302
209
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
303
|
-
redirectURI: (0,
|
|
304
|
-
code: (0,
|
|
305
|
-
codeVerifier: (0,
|
|
210
|
+
redirectURI: (0, import_zod.string)(),
|
|
211
|
+
code: (0, import_zod.string)(),
|
|
212
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
306
213
|
});
|
|
307
|
-
var OAuthAccessTokenResponse = (0,
|
|
308
|
-
access_token: (0,
|
|
309
|
-
token_type: (0,
|
|
310
|
-
expires_in: (0,
|
|
311
|
-
refresh_token: (0,
|
|
312
|
-
scope: (0,
|
|
214
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
215
|
+
access_token: (0, import_zod.string)(),
|
|
216
|
+
token_type: (0, import_zod.string)().optional(),
|
|
217
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
218
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
219
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
313
220
|
});
|
|
314
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
315
|
-
error: (0,
|
|
221
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
222
|
+
error: (0, import_zod.enum)([
|
|
316
223
|
"invalid_request",
|
|
317
224
|
"invalid_client",
|
|
318
225
|
"invalid_grant",
|
|
@@ -320,19 +227,24 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
|
320
227
|
"unsupported_grant_type",
|
|
321
228
|
"invalid_scope"
|
|
322
229
|
]),
|
|
323
|
-
error_description: (0,
|
|
324
|
-
error_uri: (0,
|
|
230
|
+
error_description: (0, import_zod.string)().optional(),
|
|
231
|
+
error_uri: (0, import_zod.string)().optional()
|
|
232
|
+
});
|
|
233
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
234
|
+
error: (0, import_zod.string)(),
|
|
235
|
+
error_description: (0, import_zod.string)().optional()
|
|
325
236
|
});
|
|
326
|
-
var
|
|
327
|
-
|
|
328
|
-
|
|
237
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
238
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
239
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
329
240
|
});
|
|
330
241
|
|
|
331
242
|
// src/actions/signIn/authorization.ts
|
|
332
243
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
333
244
|
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
334
245
|
if (!parsed.success) {
|
|
335
|
-
|
|
246
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
247
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
336
248
|
}
|
|
337
249
|
const { authorizeURL, ...options2 } = parsed.data;
|
|
338
250
|
const { userInfo, accessToken, clientSecret, ...required } = options2;
|
|
@@ -350,8 +262,8 @@ var getOriginURL = (request, trustedProxyHeaders) => {
|
|
|
350
262
|
}
|
|
351
263
|
};
|
|
352
264
|
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
353
|
-
const
|
|
354
|
-
return `${
|
|
265
|
+
const url = getOriginURL(request, trustedProxyHeaders);
|
|
266
|
+
return `${url.origin}${basePath}/callback/${oauth}`;
|
|
355
267
|
};
|
|
356
268
|
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
357
269
|
try {
|
|
@@ -365,15 +277,18 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
|
365
277
|
}
|
|
366
278
|
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
367
279
|
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
368
|
-
throw new
|
|
280
|
+
throw new AuthSecurityError(
|
|
281
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
282
|
+
"The redirectTo parameter does not match the hosted origin."
|
|
283
|
+
);
|
|
369
284
|
}
|
|
370
285
|
return sanitizeURL(redirectToURL.pathname);
|
|
371
286
|
}
|
|
372
287
|
if (referer) {
|
|
373
288
|
const refererURL = new URL(sanitizeURL(referer));
|
|
374
289
|
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
375
|
-
throw new
|
|
376
|
-
|
|
290
|
+
throw new AuthSecurityError(
|
|
291
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
377
292
|
"The referer of the request does not match the hosted origin."
|
|
378
293
|
);
|
|
379
294
|
}
|
|
@@ -382,16 +297,16 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
|
382
297
|
if (origin) {
|
|
383
298
|
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
384
299
|
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
385
|
-
throw new
|
|
300
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
386
301
|
}
|
|
387
302
|
return sanitizeURL(originURL.pathname);
|
|
388
303
|
}
|
|
389
304
|
return "/";
|
|
390
305
|
} catch (error) {
|
|
391
|
-
if (
|
|
306
|
+
if (isAuthSecurityError(error)) {
|
|
392
307
|
throw error;
|
|
393
308
|
}
|
|
394
|
-
throw new
|
|
309
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
395
310
|
}
|
|
396
311
|
};
|
|
397
312
|
|
|
@@ -399,9 +314,14 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
|
399
314
|
var signInConfig = (oauth) => {
|
|
400
315
|
return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
|
|
401
316
|
schemas: {
|
|
402
|
-
params:
|
|
403
|
-
oauth:
|
|
404
|
-
|
|
317
|
+
params: import_zod2.z.object({
|
|
318
|
+
oauth: import_zod2.z.enum(
|
|
319
|
+
Object.keys(oauth),
|
|
320
|
+
"The OAuth provider is not supported or invalid."
|
|
321
|
+
)
|
|
322
|
+
}),
|
|
323
|
+
searchParams: import_zod2.z.object({
|
|
324
|
+
redirectTo: import_zod2.z.string().optional()
|
|
405
325
|
})
|
|
406
326
|
}
|
|
407
327
|
});
|
|
@@ -413,52 +333,23 @@ var signInAction = (oauth) => {
|
|
|
413
333
|
async (ctx) => {
|
|
414
334
|
const {
|
|
415
335
|
request,
|
|
416
|
-
params: { oauth: oauth2
|
|
336
|
+
params: { oauth: oauth2 },
|
|
337
|
+
searchParams: { redirectTo },
|
|
417
338
|
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
418
339
|
} = ctx;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
431
|
-
const codeVerifierCookie = setCookie("code_verifier", codeVerifier, oauthCookie(cookieOptions));
|
|
432
|
-
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
433
|
-
const headers = new Headers();
|
|
434
|
-
headers.set("Location", authorization);
|
|
435
|
-
headers.append("Set-Cookie", stateCookie);
|
|
436
|
-
headers.append("Set-Cookie", redirectURICookie);
|
|
437
|
-
headers.append("Set-Cookie", redirectToCookie);
|
|
438
|
-
headers.append("Set-Cookie", codeVerifierCookie);
|
|
439
|
-
return Response.json(
|
|
440
|
-
{ oauth: oauth2 },
|
|
441
|
-
{
|
|
442
|
-
status: 302,
|
|
443
|
-
headers
|
|
444
|
-
}
|
|
445
|
-
);
|
|
446
|
-
} catch (error) {
|
|
447
|
-
if (isAuthError(error)) {
|
|
448
|
-
const { type, message } = error;
|
|
449
|
-
return AuraResponse.json(
|
|
450
|
-
{ error: type, error_description: message },
|
|
451
|
-
{ status: import_router2.statusCode.BAD_REQUEST }
|
|
452
|
-
);
|
|
340
|
+
const state = generateSecure();
|
|
341
|
+
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
|
|
342
|
+
const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
|
|
343
|
+
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
344
|
+
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
345
|
+
const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirectURI.name, redirectURI, cookies.redirectURI.attributes).setCookie(cookies.redirectTo.name, redirectToValue, cookies.redirectTo.attributes).setCookie(cookies.codeVerifier.name, codeVerifier, cookies.codeVerifier.attributes).toHeaders();
|
|
346
|
+
return Response.json(
|
|
347
|
+
{ oauth: oauth2 },
|
|
348
|
+
{
|
|
349
|
+
status: 302,
|
|
350
|
+
headers
|
|
453
351
|
}
|
|
454
|
-
|
|
455
|
-
{
|
|
456
|
-
error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
|
|
457
|
-
error_description: "An unexpected error occurred"
|
|
458
|
-
},
|
|
459
|
-
{ status: import_router2.statusCode.INTERNAL_SERVER_ERROR }
|
|
460
|
-
);
|
|
461
|
-
}
|
|
352
|
+
);
|
|
462
353
|
},
|
|
463
354
|
signInConfig(oauth)
|
|
464
355
|
);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as _aura_stack_router from '@aura-stack/router';
|
|
2
|
-
import {
|
|
3
|
-
import 'zod
|
|
4
|
-
import '@aura-stack/jose/jose';
|
|
2
|
+
import { j as OAuthProviderRecord } from '../../index-DkaLJFn8.js';
|
|
3
|
+
import 'zod';
|
|
5
4
|
import '../../schemas.js';
|
|
6
|
-
import '
|
|
7
|
-
import '
|
|
5
|
+
import '@aura-stack/router/cookie';
|
|
6
|
+
import '@aura-stack/jose';
|
|
7
|
+
import '@aura-stack/jose/jose';
|
|
8
8
|
import '../../@types/utility.js';
|
|
9
9
|
|
|
10
|
-
declare const signInAction: (oauth:
|
|
10
|
+
declare const signInAction: (oauth: OAuthProviderRecord) => _aura_stack_router.RouteEndpoint<"GET", "/signIn/:oauth", {}>;
|
|
11
11
|
|
|
12
12
|
export { signInAction };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
signInAction
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
6
|
-
import "../../chunk-
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
10
|
-
import "../../chunk-
|
|
11
|
-
import "../../chunk-HMRKN75I.js";
|
|
3
|
+
} from "../../chunk-3EUWD5BB.js";
|
|
4
|
+
import "../../chunk-N4SX7TZT.js";
|
|
5
|
+
import "../../chunk-STHEPPUZ.js";
|
|
6
|
+
import "../../chunk-N2APGLXA.js";
|
|
7
|
+
import "../../chunk-CXLATHS5.js";
|
|
8
|
+
import "../../chunk-EIL2FPSS.js";
|
|
9
|
+
import "../../chunk-RRLIF4PQ.js";
|
|
10
|
+
import "../../chunk-YRCB5FLE.js";
|
|
12
11
|
export {
|
|
13
12
|
signInAction
|
|
14
13
|
};
|