@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
package/dist/actions/index.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ 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-
|
|
8
|
-
import 'zod
|
|
9
|
-
import '@aura-stack/jose/jose';
|
|
7
|
+
import '../index-DkaLJFn8.js';
|
|
8
|
+
import 'zod';
|
|
10
9
|
import '../schemas.js';
|
|
11
|
-
import '
|
|
12
|
-
import '
|
|
10
|
+
import '@aura-stack/router/cookie';
|
|
11
|
+
import '@aura-stack/jose';
|
|
12
|
+
import '@aura-stack/jose/jose';
|
|
13
13
|
import '../@types/utility.js';
|
package/dist/actions/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import "../chunk-ITQ7352M.js";
|
|
2
|
+
import {
|
|
3
|
+
signOutAction
|
|
4
|
+
} from "../chunk-A3N4PVAT.js";
|
|
5
|
+
import {
|
|
6
|
+
callbackAction
|
|
7
|
+
} from "../chunk-KSWLO5ZU.js";
|
|
8
|
+
import "../chunk-GA2SMTJO.js";
|
|
9
|
+
import "../chunk-IVET23KF.js";
|
|
2
10
|
import {
|
|
3
11
|
csrfTokenAction
|
|
4
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-HT4YLL7N.js";
|
|
5
13
|
import {
|
|
6
14
|
sessionAction
|
|
7
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-JVFTCTTE.js";
|
|
8
16
|
import {
|
|
9
17
|
signInAction
|
|
10
|
-
} from "../chunk-
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
} from "../chunk-SJPDVKUS.js";
|
|
14
|
-
import "../chunk-CAKJT3KS.js";
|
|
15
|
-
import {
|
|
16
|
-
callbackAction
|
|
17
|
-
} from "../chunk-HGJ4TXY4.js";
|
|
18
|
-
import "../chunk-RLT4RFKV.js";
|
|
19
|
-
import "../chunk-UJJ7R56J.js";
|
|
20
|
-
import "../chunk-ZV4BH47P.js";
|
|
21
|
-
import "../chunk-6SM22VVJ.js";
|
|
18
|
+
} from "../chunk-3EUWD5BB.js";
|
|
19
|
+
import "../chunk-N4SX7TZT.js";
|
|
20
|
+
import "../chunk-W6LG7BFW.js";
|
|
22
21
|
import "../chunk-STHEPPUZ.js";
|
|
23
|
-
import "../chunk-
|
|
24
|
-
import "../chunk-
|
|
25
|
-
import "../chunk-
|
|
26
|
-
import "../chunk-
|
|
27
|
-
import "../chunk-
|
|
22
|
+
import "../chunk-N2APGLXA.js";
|
|
23
|
+
import "../chunk-CXLATHS5.js";
|
|
24
|
+
import "../chunk-EIL2FPSS.js";
|
|
25
|
+
import "../chunk-RRLIF4PQ.js";
|
|
26
|
+
import "../chunk-ZNCZVF6U.js";
|
|
27
|
+
import "../chunk-YRCB5FLE.js";
|
|
28
28
|
export {
|
|
29
29
|
callbackAction,
|
|
30
30
|
csrfTokenAction,
|
|
@@ -28,12 +28,15 @@ var import_router2 = require("@aura-stack/router");
|
|
|
28
28
|
// src/utils.ts
|
|
29
29
|
var import_router = require("@aura-stack/router");
|
|
30
30
|
|
|
31
|
-
// src/
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
// src/errors.ts
|
|
32
|
+
var AuthInternalError = class extends Error {
|
|
33
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
34
|
+
code;
|
|
35
|
+
constructor(code, message, options) {
|
|
36
|
+
super(message, options);
|
|
37
|
+
this.code = code;
|
|
38
|
+
this.name = new.target.name;
|
|
39
|
+
Error.captureStackTrace(this, new.target);
|
|
37
40
|
}
|
|
38
41
|
};
|
|
39
42
|
|
|
@@ -51,137 +54,50 @@ var cacheControl = {
|
|
|
51
54
|
};
|
|
52
55
|
|
|
53
56
|
// src/cookie.ts
|
|
54
|
-
var import_cookie = require("cookie");
|
|
55
|
-
|
|
56
|
-
// src/assert.ts
|
|
57
|
-
var isRequest = (value) => {
|
|
58
|
-
return typeof Request !== "undefined" && value instanceof Request;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// src/cookie.ts
|
|
62
|
-
var import_cookie2 = require("cookie");
|
|
63
|
-
var COOKIE_NAME = "aura-auth";
|
|
57
|
+
var import_cookie = require("@aura-stack/router/cookie");
|
|
64
58
|
var defaultCookieOptions = {
|
|
65
59
|
httpOnly: true,
|
|
66
60
|
sameSite: "lax",
|
|
67
61
|
path: "/",
|
|
68
62
|
maxAge: 60 * 60 * 24 * 15
|
|
69
63
|
};
|
|
70
|
-
var
|
|
71
|
-
secure: false,
|
|
64
|
+
var oauthCookieOptions = {
|
|
72
65
|
httpOnly: true,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
secure: true,
|
|
77
|
-
prefix: "__Secure-"
|
|
78
|
-
};
|
|
79
|
-
var defaultHostCookieConfig = {
|
|
80
|
-
secure: true,
|
|
81
|
-
prefix: "__Host-",
|
|
82
|
-
path: "/",
|
|
83
|
-
domain: void 0
|
|
66
|
+
maxAge: 5 * 60,
|
|
67
|
+
sameSite: "lax",
|
|
68
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
84
69
|
};
|
|
85
|
-
var
|
|
70
|
+
var expiredCookieAttributes = {
|
|
86
71
|
...defaultCookieOptions,
|
|
87
72
|
expires: /* @__PURE__ */ new Date(0),
|
|
88
73
|
maxAge: 0
|
|
89
74
|
};
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
name: options?.name ?? COOKIE_NAME,
|
|
93
|
-
prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
|
|
94
|
-
...defaultCookieOptions,
|
|
95
|
-
...options
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
var setCookie = (cookieName, value, options) => {
|
|
99
|
-
const { prefix, name } = defineDefaultCookieOptions(options);
|
|
100
|
-
const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
|
|
101
|
-
return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
|
|
102
|
-
...defaultCookieOptions,
|
|
103
|
-
...options
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
var getCookie = (petition, cookie, options, optional = false) => {
|
|
107
|
-
const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ");
|
|
75
|
+
var getCookie = (request, cookieName) => {
|
|
76
|
+
const cookies = request.headers.get("Cookie");
|
|
108
77
|
if (!cookies) {
|
|
109
|
-
|
|
110
|
-
return "";
|
|
111
|
-
}
|
|
112
|
-
throw new AuthError("invalid_request", "No cookies found. There is no active session");
|
|
78
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
|
|
113
79
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (value === void 0) {
|
|
118
|
-
if (optional) {
|
|
119
|
-
return "";
|
|
120
|
-
}
|
|
121
|
-
throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`);
|
|
80
|
+
const value = (0, import_cookie.parse)(cookies)[cookieName];
|
|
81
|
+
if (!value) {
|
|
82
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
|
|
122
83
|
}
|
|
123
84
|
return value;
|
|
124
85
|
};
|
|
125
|
-
var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
|
|
126
|
-
const name = cookieOptions.name ?? COOKIE_NAME;
|
|
127
|
-
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://");
|
|
128
|
-
if (!cookieOptions.options?.httpOnly) {
|
|
129
|
-
console.warn(
|
|
130
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
if (cookieOptions.options?.domain === "*") {
|
|
134
|
-
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
|
|
135
|
-
}
|
|
136
|
-
if (!isSecure) {
|
|
137
|
-
const options = cookieOptions.options;
|
|
138
|
-
if (options?.secure) {
|
|
139
|
-
console.warn(
|
|
140
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
if (options?.sameSite == "none") {
|
|
144
|
-
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
|
|
145
|
-
}
|
|
146
|
-
if (process.env.NODE_ENV === "production") {
|
|
147
|
-
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
...defaultCookieOptions,
|
|
151
|
-
...cookieOptions.options,
|
|
152
|
-
sameSite: options?.sameSite === "none" ? "lax" : options?.sameSite ?? "lax",
|
|
153
|
-
...defaultStandardCookieConfig,
|
|
154
|
-
name
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return cookieOptions.strategy === "host" ? {
|
|
158
|
-
...defaultCookieOptions,
|
|
159
|
-
...cookieOptions.options,
|
|
160
|
-
...defaultHostCookieConfig,
|
|
161
|
-
name
|
|
162
|
-
} : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
|
|
163
|
-
};
|
|
164
|
-
var expireCookie = (name, options) => {
|
|
165
|
-
return setCookie(name, "", { ...options, ...expiredCookieOptions });
|
|
166
|
-
};
|
|
167
86
|
|
|
168
87
|
// src/actions/session/session.ts
|
|
169
88
|
var sessionAction = (0, import_router2.createEndpoint)("GET", "/session", async (ctx) => {
|
|
170
89
|
const {
|
|
171
90
|
request,
|
|
172
|
-
context: {
|
|
91
|
+
context: { jose, cookies }
|
|
173
92
|
} = ctx;
|
|
174
|
-
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
|
|
175
93
|
try {
|
|
176
|
-
const session = getCookie(request,
|
|
94
|
+
const session = getCookie(request, cookies.sessionToken.name);
|
|
177
95
|
const decoded = await jose.decodeJWT(session);
|
|
178
96
|
const { exp, iat, jti, nbf, ...user } = decoded;
|
|
179
97
|
const headers = new Headers(cacheControl);
|
|
180
98
|
return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
|
|
181
|
-
} catch {
|
|
182
|
-
const headers = new
|
|
183
|
-
const sessionCookie = expireCookie("sessionToken", cookieOptions);
|
|
184
|
-
headers.set("Set-Cookie", sessionCookie);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
const headers = new import_router2.HeadersBuilder(cacheControl).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
185
101
|
return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
|
|
186
102
|
}
|
|
187
103
|
});
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sessionAction
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
5
|
-
import "../../chunk-6SM22VVJ.js";
|
|
3
|
+
} from "../../chunk-JVFTCTTE.js";
|
|
4
|
+
import "../../chunk-W6LG7BFW.js";
|
|
6
5
|
import "../../chunk-STHEPPUZ.js";
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
6
|
+
import "../../chunk-CXLATHS5.js";
|
|
7
|
+
import "../../chunk-RRLIF4PQ.js";
|
|
9
8
|
export {
|
|
10
9
|
sessionAction
|
|
11
10
|
};
|
|
@@ -35,28 +35,28 @@ var isValidURL = (value) => {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
// src/schemas.ts
|
|
38
|
-
var
|
|
39
|
-
var OAuthProviderConfigSchema = (0,
|
|
40
|
-
authorizeURL: (0,
|
|
41
|
-
accessToken: (0,
|
|
42
|
-
scope: (0,
|
|
43
|
-
userInfo: (0,
|
|
44
|
-
responseType: (0,
|
|
45
|
-
clientId: (0,
|
|
46
|
-
clientSecret: (0,
|
|
38
|
+
var import_zod = require("zod");
|
|
39
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
40
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
41
|
+
accessToken: (0, import_zod.string)().url(),
|
|
42
|
+
scope: (0, import_zod.string)().optional(),
|
|
43
|
+
userInfo: (0, import_zod.string)().url(),
|
|
44
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
45
|
+
clientId: (0, import_zod.string)(),
|
|
46
|
+
clientSecret: (0, import_zod.string)()
|
|
47
47
|
});
|
|
48
48
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
49
|
-
redirectURI: (0,
|
|
50
|
-
state: (0,
|
|
51
|
-
codeChallenge: (0,
|
|
52
|
-
codeChallengeMethod: (0,
|
|
49
|
+
redirectURI: (0, import_zod.string)(),
|
|
50
|
+
state: (0, import_zod.string)(),
|
|
51
|
+
codeChallenge: (0, import_zod.string)(),
|
|
52
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
53
53
|
});
|
|
54
|
-
var OAuthAuthorizationResponse = (0,
|
|
55
|
-
state: (0,
|
|
56
|
-
code: (0,
|
|
54
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
55
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
56
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
57
57
|
});
|
|
58
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
59
|
-
error: (0,
|
|
58
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
59
|
+
error: (0, import_zod.enum)([
|
|
60
60
|
"invalid_request",
|
|
61
61
|
"unauthorized_client",
|
|
62
62
|
"access_denied",
|
|
@@ -65,24 +65,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
|
65
65
|
"server_error",
|
|
66
66
|
"temporarily_unavailable"
|
|
67
67
|
]),
|
|
68
|
-
error_description: (0,
|
|
69
|
-
error_uri: (0,
|
|
70
|
-
state: (0,
|
|
68
|
+
error_description: (0, import_zod.string)().optional(),
|
|
69
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
70
|
+
state: (0, import_zod.string)()
|
|
71
71
|
});
|
|
72
72
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
73
|
-
redirectURI: (0,
|
|
74
|
-
code: (0,
|
|
75
|
-
codeVerifier: (0,
|
|
73
|
+
redirectURI: (0, import_zod.string)(),
|
|
74
|
+
code: (0, import_zod.string)(),
|
|
75
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
76
76
|
});
|
|
77
|
-
var OAuthAccessTokenResponse = (0,
|
|
78
|
-
access_token: (0,
|
|
79
|
-
token_type: (0,
|
|
80
|
-
expires_in: (0,
|
|
81
|
-
refresh_token: (0,
|
|
82
|
-
scope: (0,
|
|
77
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
78
|
+
access_token: (0, import_zod.string)(),
|
|
79
|
+
token_type: (0, import_zod.string)().optional(),
|
|
80
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
81
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
82
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
83
83
|
});
|
|
84
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
85
|
-
error: (0,
|
|
84
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
85
|
+
error: (0, import_zod.enum)([
|
|
86
86
|
"invalid_request",
|
|
87
87
|
"invalid_client",
|
|
88
88
|
"invalid_grant",
|
|
@@ -90,55 +90,45 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
|
90
90
|
"unsupported_grant_type",
|
|
91
91
|
"invalid_scope"
|
|
92
92
|
]),
|
|
93
|
-
error_description: (0,
|
|
94
|
-
error_uri: (0,
|
|
93
|
+
error_description: (0, import_zod.string)().optional(),
|
|
94
|
+
error_uri: (0, import_zod.string)().optional()
|
|
95
95
|
});
|
|
96
|
-
var OAuthErrorResponse = (0,
|
|
97
|
-
error: (0,
|
|
98
|
-
error_description: (0,
|
|
96
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
97
|
+
error: (0, import_zod.string)(),
|
|
98
|
+
error_description: (0, import_zod.string)().optional()
|
|
99
|
+
});
|
|
100
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
101
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
102
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
99
103
|
});
|
|
100
104
|
|
|
101
|
-
// src/
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
105
|
+
// src/errors.ts
|
|
106
|
+
var AuthInternalError = class extends Error {
|
|
107
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
108
|
+
code;
|
|
109
|
+
constructor(code, message, options2) {
|
|
110
|
+
super(message, options2);
|
|
111
|
+
this.code = code;
|
|
112
|
+
this.name = new.target.name;
|
|
113
|
+
Error.captureStackTrace(this, new.target);
|
|
110
114
|
}
|
|
111
115
|
};
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
var AuthSecurityError = class extends Error {
|
|
117
|
+
type = "AUTH_SECURITY_ERROR";
|
|
118
|
+
code;
|
|
119
|
+
constructor(code, message, options2) {
|
|
120
|
+
super(message, options2);
|
|
121
|
+
this.code = code;
|
|
122
|
+
this.name = new.target.name;
|
|
123
|
+
Error.captureStackTrace(this, new.target);
|
|
116
124
|
}
|
|
117
125
|
};
|
|
118
|
-
var
|
|
119
|
-
return error instanceof
|
|
120
|
-
};
|
|
121
|
-
var ERROR_RESPONSE = {
|
|
122
|
-
AUTHORIZATION: {
|
|
123
|
-
INVALID_REQUEST: "invalid_request",
|
|
124
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
125
|
-
ACCESS_DENIED: "access_denied",
|
|
126
|
-
UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
|
|
127
|
-
INVALID_SCOPE: "invalid_scope",
|
|
128
|
-
SERVER_ERROR: "server_error",
|
|
129
|
-
TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
|
|
130
|
-
},
|
|
131
|
-
ACCESS_TOKEN: {
|
|
132
|
-
INVALID_REQUEST: "invalid_request",
|
|
133
|
-
INVALID_CLIENT: "invalid_client",
|
|
134
|
-
INVALID_GRANT: "invalid_grant",
|
|
135
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
136
|
-
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
137
|
-
INVALID_SCOPE: "invalid_scope"
|
|
138
|
-
}
|
|
126
|
+
var isAuthSecurityError = (error) => {
|
|
127
|
+
return error instanceof AuthSecurityError;
|
|
139
128
|
};
|
|
140
129
|
|
|
141
130
|
// src/utils.ts
|
|
131
|
+
var import_router = require("@aura-stack/router");
|
|
142
132
|
var toSnakeCase = (str) => {
|
|
143
133
|
return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
|
|
144
134
|
};
|
|
@@ -155,9 +145,9 @@ var equals = (a, b) => {
|
|
|
155
145
|
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
156
146
|
return a === b;
|
|
157
147
|
};
|
|
158
|
-
var sanitizeURL = (
|
|
148
|
+
var sanitizeURL = (url) => {
|
|
159
149
|
try {
|
|
160
|
-
let decodedURL = decodeURIComponent(
|
|
150
|
+
let decodedURL = decodeURIComponent(url).trim();
|
|
161
151
|
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
|
|
162
152
|
let protocol = "";
|
|
163
153
|
let rest = decodedURL;
|
|
@@ -185,25 +175,41 @@ var sanitizeURL = (url2) => {
|
|
|
185
175
|
}
|
|
186
176
|
return sanitized;
|
|
187
177
|
} catch {
|
|
188
|
-
return
|
|
178
|
+
return url.trim();
|
|
189
179
|
}
|
|
190
180
|
};
|
|
191
181
|
var getNormalizedOriginPath = (path) => {
|
|
192
182
|
try {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return `${
|
|
183
|
+
const url = new URL(path);
|
|
184
|
+
url.hash = "";
|
|
185
|
+
url.search = "";
|
|
186
|
+
return `${url.origin}${url.pathname}`;
|
|
197
187
|
} catch {
|
|
198
188
|
return sanitizeURL(path);
|
|
199
189
|
}
|
|
200
190
|
};
|
|
191
|
+
var formatZodError = (error) => {
|
|
192
|
+
if (!error.issues || error.issues.length === 0) {
|
|
193
|
+
return {};
|
|
194
|
+
}
|
|
195
|
+
return error.issues.reduce((previous, issue) => {
|
|
196
|
+
const key = issue.path.join(".");
|
|
197
|
+
return {
|
|
198
|
+
...previous,
|
|
199
|
+
[key]: {
|
|
200
|
+
code: issue.code,
|
|
201
|
+
message: issue.message
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}, {});
|
|
205
|
+
};
|
|
201
206
|
|
|
202
207
|
// src/actions/signIn/authorization.ts
|
|
203
208
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
204
209
|
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
205
210
|
if (!parsed.success) {
|
|
206
|
-
|
|
211
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
212
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
207
213
|
}
|
|
208
214
|
const { authorizeURL, ...options2 } = parsed.data;
|
|
209
215
|
const { userInfo, accessToken, clientSecret, ...required } = options2;
|
|
@@ -221,8 +227,8 @@ var getOriginURL = (request, trustedProxyHeaders) => {
|
|
|
221
227
|
}
|
|
222
228
|
};
|
|
223
229
|
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
224
|
-
const
|
|
225
|
-
return `${
|
|
230
|
+
const url = getOriginURL(request, trustedProxyHeaders);
|
|
231
|
+
return `${url.origin}${basePath}/callback/${oauth}`;
|
|
226
232
|
};
|
|
227
233
|
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
228
234
|
try {
|
|
@@ -236,15 +242,18 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
|
236
242
|
}
|
|
237
243
|
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
238
244
|
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
239
|
-
throw new
|
|
245
|
+
throw new AuthSecurityError(
|
|
246
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
247
|
+
"The redirectTo parameter does not match the hosted origin."
|
|
248
|
+
);
|
|
240
249
|
}
|
|
241
250
|
return sanitizeURL(redirectToURL.pathname);
|
|
242
251
|
}
|
|
243
252
|
if (referer) {
|
|
244
253
|
const refererURL = new URL(sanitizeURL(referer));
|
|
245
254
|
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
246
|
-
throw new
|
|
247
|
-
|
|
255
|
+
throw new AuthSecurityError(
|
|
256
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
248
257
|
"The referer of the request does not match the hosted origin."
|
|
249
258
|
);
|
|
250
259
|
}
|
|
@@ -253,16 +262,16 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
|
253
262
|
if (origin) {
|
|
254
263
|
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
255
264
|
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
256
|
-
throw new
|
|
265
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
257
266
|
}
|
|
258
267
|
return sanitizeURL(originURL.pathname);
|
|
259
268
|
}
|
|
260
269
|
return "/";
|
|
261
270
|
} catch (error) {
|
|
262
|
-
if (
|
|
271
|
+
if (isAuthSecurityError(error)) {
|
|
263
272
|
throw error;
|
|
264
273
|
}
|
|
265
|
-
throw new
|
|
274
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
266
275
|
}
|
|
267
276
|
};
|
|
268
277
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import 'zod
|
|
3
|
-
import '@aura-stack/jose/jose';
|
|
1
|
+
import { h as OAuthProviderCredentials } from '../../index-DkaLJFn8.js';
|
|
2
|
+
import 'zod';
|
|
4
3
|
import '../../schemas.js';
|
|
5
|
-
import '
|
|
6
|
-
import '
|
|
4
|
+
import '@aura-stack/router/cookie';
|
|
5
|
+
import '@aura-stack/jose';
|
|
6
|
+
import '@aura-stack/jose/jose';
|
|
7
7
|
import '../../@types/utility.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
createRedirectTo,
|
|
4
4
|
createRedirectURI,
|
|
5
5
|
getOriginURL
|
|
6
|
-
} from "../../chunk-
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
10
|
-
import "../../chunk-
|
|
6
|
+
} from "../../chunk-N4SX7TZT.js";
|
|
7
|
+
import "../../chunk-CXLATHS5.js";
|
|
8
|
+
import "../../chunk-EIL2FPSS.js";
|
|
9
|
+
import "../../chunk-RRLIF4PQ.js";
|
|
10
|
+
import "../../chunk-YRCB5FLE.js";
|
|
11
11
|
export {
|
|
12
12
|
createAuthorizationURL,
|
|
13
13
|
createRedirectTo,
|