@aura-stack/auth 0.1.0-rc.9 → 0.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/index.cjs +15 -15
- package/dist/@types/index.d.ts +7 -31
- package/dist/@types/index.js +1 -1
- package/dist/@types/router.d.cjs +1 -1
- package/dist/@types/router.d.d.ts +7 -7
- package/dist/@types/utility.cjs +15 -15
- package/dist/@types/utility.d.ts +4 -8
- package/dist/@types/utility.js +1 -1
- package/dist/actions/callback/access-token.cjs +176 -155
- package/dist/actions/callback/access-token.d.ts +15 -20
- package/dist/actions/callback/access-token.js +10 -4
- package/dist/actions/callback/callback.cjs +394 -490
- package/dist/actions/callback/callback.d.ts +10 -12
- package/dist/actions/callback/callback.js +16 -12
- package/dist/actions/callback/userinfo.cjs +166 -145
- package/dist/actions/callback/userinfo.d.ts +9 -9
- package/dist/actions/callback/userinfo.js +12 -6
- package/dist/actions/csrfToken/csrfToken.cjs +112 -190
- package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
- package/dist/actions/csrfToken/csrfToken.js +12 -8
- package/dist/actions/index.cjs +652 -814
- package/dist/actions/index.d.ts +13 -13
- package/dist/actions/index.js +34 -18
- package/dist/actions/session/session.cjs +86 -176
- package/dist/actions/session/session.d.ts +3 -3
- package/dist/actions/session/session.js +10 -7
- package/dist/actions/signIn/authorization.cjs +254 -263
- package/dist/actions/signIn/authorization.d.ts +12 -18
- package/dist/actions/signIn/authorization.js +16 -6
- package/dist/actions/signIn/signIn.cjs +320 -456
- package/dist/actions/signIn/signIn.d.ts +10 -10
- package/dist/actions/signIn/signIn.js +13 -10
- package/dist/actions/signOut/signOut.cjs +304 -473
- package/dist/actions/signOut/signOut.d.ts +3 -3
- package/dist/actions/signOut/signOut.js +14 -11
- package/dist/assert.cjs +40 -36
- package/dist/assert.d.ts +13 -4
- package/dist/assert.js +12 -2
- package/dist/chunk-3EUWD5BB.js +63 -0
- package/dist/chunk-42XB3YCW.js +19 -17
- package/dist/chunk-6R2YZ4AC.js +22 -0
- package/dist/chunk-A3N4PVAT.js +70 -0
- package/dist/chunk-B737EUJV.js +22 -0
- package/dist/chunk-CXLATHS5.js +143 -0
- package/dist/chunk-E3OXBRYF.js +19 -17
- package/dist/chunk-EIL2FPSS.js +22 -0
- package/dist/chunk-EMKJA2GJ.js +89 -0
- package/dist/chunk-FIPU4MLT.js +18 -16
- package/dist/chunk-FKRDCWBF.js +19 -17
- package/dist/chunk-GA2SMTJO.js +58 -0
- package/dist/chunk-HP34YGGJ.js +22 -0
- package/dist/chunk-HT4YLL7N.js +35 -0
- package/dist/chunk-IKHPGFCW.js +11 -9
- package/dist/chunk-IUYZQTJV.js +30 -0
- package/dist/chunk-IVET23KF.js +58 -0
- package/dist/chunk-JVFTCTTE.js +33 -0
- package/dist/chunk-KRNOMBXQ.js +19 -17
- package/dist/chunk-KSWLO5ZU.js +102 -0
- package/dist/chunk-N2APGLXA.js +71 -0
- package/dist/chunk-N4SX7TZT.js +96 -0
- package/dist/chunk-RRLIF4PQ.js +55 -0
- package/dist/chunk-STHEPPUZ.js +8 -6
- package/dist/chunk-TLE4PXY3.js +39 -0
- package/dist/chunk-W6LG7BFW.js +197 -0
- package/dist/chunk-YRCB5FLE.js +79 -0
- package/dist/chunk-ZNCZVF6U.js +14 -0
- package/dist/cookie.cjs +222 -187
- package/dist/cookie.d.ts +39 -76
- package/dist/cookie.js +27 -34
- package/dist/errors.cjs +85 -0
- package/dist/errors.d.ts +49 -0
- package/dist/errors.js +18 -0
- package/dist/headers.cjs +28 -28
- package/dist/headers.d.ts +2 -2
- package/dist/headers.js +6 -2
- package/dist/index-DkaLJFn8.d.ts +679 -0
- package/dist/index.cjs +1074 -1007
- package/dist/index.d.ts +10 -31
- package/dist/index.js +85 -51
- package/dist/jose.cjs +74 -66
- package/dist/jose.d.ts +11 -8
- package/dist/jose.js +10 -5
- package/dist/oauth/bitbucket.cjs +38 -38
- package/dist/oauth/bitbucket.d.ts +7 -7
- package/dist/oauth/bitbucket.js +6 -2
- package/dist/oauth/discord.cjs +47 -48
- package/dist/oauth/discord.d.ts +7 -7
- package/dist/oauth/discord.js +6 -2
- package/dist/oauth/figma.cjs +39 -39
- package/dist/oauth/figma.d.ts +7 -7
- package/dist/oauth/figma.js +6 -2
- package/dist/oauth/github.cjs +31 -31
- package/dist/oauth/github.d.ts +7 -7
- package/dist/oauth/github.js +6 -2
- package/dist/oauth/gitlab.cjs +39 -39
- package/dist/oauth/gitlab.d.ts +7 -7
- package/dist/oauth/gitlab.js +6 -2
- package/dist/oauth/index.cjs +350 -180
- package/dist/oauth/index.d.ts +7 -26
- package/dist/oauth/index.js +51 -9
- 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.cjs +39 -39
- package/dist/oauth/spotify.d.ts +7 -7
- package/dist/oauth/spotify.js +6 -2
- 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.cjs +39 -39
- package/dist/oauth/x.d.ts +7 -7
- package/dist/oauth/x.js +6 -2
- package/dist/request.cjs +38 -0
- package/dist/request.d.ts +13 -0
- package/dist/request.js +6 -0
- package/dist/schemas.cjs +103 -97
- package/dist/schemas.d.ts +96 -126
- package/dist/schemas.js +20 -18
- package/dist/secure.cjs +106 -101
- package/dist/secure.d.ts +17 -17
- package/dist/secure.js +19 -4
- package/dist/utils.cjs +197 -135
- package/dist/utils.d.ts +20 -26
- package/dist/utils.js +25 -21
- package/package.json +8 -7
- package/dist/chunk-256KIVJL.js +0 -110
- package/dist/chunk-6SM22VVJ.js +0 -15
- package/dist/chunk-CAKJT3KS.js +0 -77
- package/dist/chunk-EBPE35JT.js +0 -29
- package/dist/chunk-FJUDBLCP.js +0 -52
- package/dist/chunk-GZU3RBTB.js +0 -51
- package/dist/chunk-HGJ4TXY4.js +0 -105
- package/dist/chunk-HMRKN75I.js +0 -74
- package/dist/chunk-JAPMIE6S.js +0 -8
- package/dist/chunk-LLR722CL.js +0 -75
- package/dist/chunk-RLT4RFKV.js +0 -36
- package/dist/chunk-SJPDVKUS.js +0 -93
- package/dist/chunk-SMQO5WD7.js +0 -20
- package/dist/chunk-UJJ7R56J.js +0 -42
- package/dist/chunk-UTDLUEEG.js +0 -25
- package/dist/chunk-VFTYH33W.js +0 -44
- package/dist/chunk-XXJKNKGQ.js +0 -27
- package/dist/chunk-ZV4BH47P.js +0 -156
- package/dist/error.cjs +0 -88
- package/dist/error.d.ts +0 -62
- package/dist/error.js +0 -9
- package/dist/index-DpfbvTZ_.d.ts +0 -597
- package/dist/response.cjs +0 -34
- package/dist/response.d.ts +0 -10
- package/dist/response.js +0 -2
|
@@ -1,513 +1,344 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
var __create = Object.create
|
|
3
|
-
var __defProp = Object.defineProperty
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
|
|
10
|
-
}
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
)
|
|
30
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod)
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
29
|
|
|
32
30
|
// src/actions/signOut/signOut.ts
|
|
33
|
-
var signOut_exports = {}
|
|
31
|
+
var signOut_exports = {};
|
|
34
32
|
__export(signOut_exports, {
|
|
35
|
-
|
|
36
|
-
})
|
|
37
|
-
module.exports = __toCommonJS(signOut_exports)
|
|
38
|
-
var
|
|
39
|
-
var import_router2 = require("@aura-stack/router")
|
|
33
|
+
signOutAction: () => signOutAction
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(signOut_exports);
|
|
36
|
+
var import_zod2 = require("zod");
|
|
37
|
+
var import_router2 = require("@aura-stack/router");
|
|
40
38
|
|
|
41
39
|
// src/secure.ts
|
|
42
|
-
var
|
|
40
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
43
41
|
|
|
44
42
|
// src/utils.ts
|
|
45
|
-
var import_router = require("@aura-stack/router")
|
|
43
|
+
var import_router = require("@aura-stack/router");
|
|
46
44
|
|
|
47
|
-
// src/
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
var InvalidRedirectToError = class extends AuthError {
|
|
62
|
-
constructor(message = "The redirectTo parameter does not match the hosted origin.") {
|
|
63
|
-
super("invalid_redirect_to", message)
|
|
64
|
-
this.name = "InvalidRedirectToError"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
var isAuthError = (error) => {
|
|
68
|
-
return error instanceof AuthError
|
|
69
|
-
}
|
|
70
|
-
var ERROR_RESPONSE = {
|
|
71
|
-
AUTHORIZATION: {
|
|
72
|
-
INVALID_REQUEST: "invalid_request",
|
|
73
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
74
|
-
ACCESS_DENIED: "access_denied",
|
|
75
|
-
UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
|
|
76
|
-
INVALID_SCOPE: "invalid_scope",
|
|
77
|
-
SERVER_ERROR: "server_error",
|
|
78
|
-
TEMPORARILY_UNAVAILABLE: "temporarily_unavailable",
|
|
79
|
-
},
|
|
80
|
-
ACCESS_TOKEN: {
|
|
81
|
-
INVALID_REQUEST: "invalid_request",
|
|
82
|
-
INVALID_CLIENT: "invalid_client",
|
|
83
|
-
INVALID_GRANT: "invalid_grant",
|
|
84
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
85
|
-
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
86
|
-
INVALID_SCOPE: "invalid_scope",
|
|
87
|
-
},
|
|
88
|
-
}
|
|
45
|
+
// src/errors.ts
|
|
46
|
+
var AuthSecurityError = class extends Error {
|
|
47
|
+
type = "AUTH_SECURITY_ERROR";
|
|
48
|
+
code;
|
|
49
|
+
constructor(code, message, options2) {
|
|
50
|
+
super(message, options2);
|
|
51
|
+
this.code = code;
|
|
52
|
+
this.name = new.target.name;
|
|
53
|
+
Error.captureStackTrace(this, new.target);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var isAuthSecurityError = (error) => {
|
|
57
|
+
return error instanceof AuthSecurityError;
|
|
58
|
+
};
|
|
89
59
|
|
|
90
60
|
// src/utils.ts
|
|
91
61
|
var equals = (a, b) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
var sanitizeURL = (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
path = path.replace(/\/+$/, "/")
|
|
117
|
-
} else if (path !== "/") {
|
|
118
|
-
path = path.replace(/\/+$/, "")
|
|
119
|
-
}
|
|
120
|
-
return protocol + domain + path
|
|
121
|
-
}
|
|
122
|
-
let sanitized = decodedURL
|
|
123
|
-
.replace(/\/\.\.\//g, "/")
|
|
124
|
-
.replace(/\/\.\.$/, "")
|
|
125
|
-
.replace(/\.{2,}/g, "")
|
|
126
|
-
.replace(/\/{2,}/g, "/")
|
|
127
|
-
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
128
|
-
sanitized = sanitized.replace(/\/+$/, "/")
|
|
129
|
-
} else if (sanitized !== "/") {
|
|
130
|
-
sanitized = sanitized.replace(/\/+$/, "")
|
|
131
|
-
}
|
|
132
|
-
return sanitized
|
|
133
|
-
} catch {
|
|
134
|
-
return url2.trim()
|
|
62
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
63
|
+
return a === b;
|
|
64
|
+
};
|
|
65
|
+
var sanitizeURL = (url) => {
|
|
66
|
+
try {
|
|
67
|
+
let decodedURL = decodeURIComponent(url).trim();
|
|
68
|
+
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
|
|
69
|
+
let protocol = "";
|
|
70
|
+
let rest = decodedURL;
|
|
71
|
+
if (protocolMatch) {
|
|
72
|
+
protocol = protocolMatch[1];
|
|
73
|
+
rest = decodedURL.slice(protocol.length);
|
|
74
|
+
const slashIndex = rest.indexOf("/");
|
|
75
|
+
if (slashIndex === -1) {
|
|
76
|
+
return protocol + rest;
|
|
77
|
+
}
|
|
78
|
+
const domain = rest.slice(0, slashIndex);
|
|
79
|
+
let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
80
|
+
if (path !== "/" && path.endsWith("/")) {
|
|
81
|
+
path = path.replace(/\/+$/, "/");
|
|
82
|
+
} else if (path !== "/") {
|
|
83
|
+
path = path.replace(/\/+$/, "");
|
|
84
|
+
}
|
|
85
|
+
return protocol + domain + path;
|
|
135
86
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
url2.search = ""
|
|
142
|
-
return `${url2.origin}${url2.pathname}`
|
|
143
|
-
} catch {
|
|
144
|
-
return sanitizeURL(path)
|
|
87
|
+
let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
88
|
+
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
89
|
+
sanitized = sanitized.replace(/\/+$/, "/");
|
|
90
|
+
} else if (sanitized !== "/") {
|
|
91
|
+
sanitized = sanitized.replace(/\/+$/, "");
|
|
145
92
|
}
|
|
146
|
-
|
|
93
|
+
return sanitized;
|
|
94
|
+
} catch {
|
|
95
|
+
return url.trim();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var getNormalizedOriginPath = (path) => {
|
|
99
|
+
try {
|
|
100
|
+
const url = new URL(path);
|
|
101
|
+
url.hash = "";
|
|
102
|
+
url.search = "";
|
|
103
|
+
return `${url.origin}${url.pathname}`;
|
|
104
|
+
} catch {
|
|
105
|
+
return sanitizeURL(path);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/assert.ts
|
|
110
|
+
var isValidURL = (value) => {
|
|
111
|
+
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
|
|
112
|
+
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
|
|
113
|
+
return regex.test(value);
|
|
114
|
+
};
|
|
115
|
+
var isJWTPayloadWithToken = (payload) => {
|
|
116
|
+
return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
|
|
117
|
+
};
|
|
147
118
|
|
|
148
119
|
// src/secure.ts
|
|
149
120
|
var verifyCSRF = async (jose, cookie, header) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
121
|
+
try {
|
|
122
|
+
const cookiePayload = await jose.verifyJWS(cookie);
|
|
123
|
+
const headerPayload = await jose.verifyJWS(header);
|
|
124
|
+
if (!isJWTPayloadWithToken(cookiePayload)) {
|
|
125
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
|
|
126
|
+
}
|
|
127
|
+
if (!isJWTPayloadWithToken(headerPayload)) {
|
|
128
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
|
|
129
|
+
}
|
|
130
|
+
const cookieBuffer = Buffer.from(cookiePayload.token);
|
|
131
|
+
const headerBuffer = Buffer.from(headerPayload.token);
|
|
132
|
+
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
133
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
134
|
+
}
|
|
135
|
+
if (!import_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
|
|
136
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
164
137
|
}
|
|
165
|
-
|
|
138
|
+
return true;
|
|
139
|
+
} catch {
|
|
140
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
166
143
|
|
|
167
144
|
// src/headers.ts
|
|
168
145
|
var cacheControl = {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
146
|
+
"Cache-Control": "no-store",
|
|
147
|
+
Pragma: "no-cache",
|
|
148
|
+
Expires: "0",
|
|
149
|
+
Vary: "Cookie"
|
|
150
|
+
};
|
|
174
151
|
|
|
175
|
-
// src/
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
152
|
+
// src/cookie.ts
|
|
153
|
+
var import_cookie = require("@aura-stack/router/cookie");
|
|
154
|
+
var defaultCookieOptions = {
|
|
155
|
+
httpOnly: true,
|
|
156
|
+
sameSite: "lax",
|
|
157
|
+
path: "/",
|
|
158
|
+
maxAge: 60 * 60 * 24 * 15
|
|
159
|
+
};
|
|
160
|
+
var oauthCookieOptions = {
|
|
161
|
+
httpOnly: true,
|
|
162
|
+
maxAge: 5 * 60,
|
|
163
|
+
sameSite: "lax",
|
|
164
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
165
|
+
};
|
|
166
|
+
var expiredCookieAttributes = {
|
|
167
|
+
...defaultCookieOptions,
|
|
168
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
169
|
+
maxAge: 0
|
|
170
|
+
};
|
|
192
171
|
|
|
193
172
|
// src/schemas.ts
|
|
194
|
-
var
|
|
195
|
-
var OAuthProviderConfigSchema = (0,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
})
|
|
173
|
+
var import_zod = require("zod");
|
|
174
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
175
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
176
|
+
accessToken: (0, import_zod.string)().url(),
|
|
177
|
+
scope: (0, import_zod.string)().optional(),
|
|
178
|
+
userInfo: (0, import_zod.string)().url(),
|
|
179
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
180
|
+
clientId: (0, import_zod.string)(),
|
|
181
|
+
clientSecret: (0, import_zod.string)()
|
|
182
|
+
});
|
|
204
183
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
})
|
|
210
|
-
var OAuthAuthorizationResponse = (0,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
})
|
|
214
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
})
|
|
184
|
+
redirectURI: (0, import_zod.string)(),
|
|
185
|
+
state: (0, import_zod.string)(),
|
|
186
|
+
codeChallenge: (0, import_zod.string)(),
|
|
187
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
188
|
+
});
|
|
189
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
190
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
191
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
192
|
+
});
|
|
193
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
194
|
+
error: (0, import_zod.enum)([
|
|
195
|
+
"invalid_request",
|
|
196
|
+
"unauthorized_client",
|
|
197
|
+
"access_denied",
|
|
198
|
+
"unsupported_response_type",
|
|
199
|
+
"invalid_scope",
|
|
200
|
+
"server_error",
|
|
201
|
+
"temporarily_unavailable"
|
|
202
|
+
]),
|
|
203
|
+
error_description: (0, import_zod.string)().optional(),
|
|
204
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
205
|
+
state: (0, import_zod.string)()
|
|
206
|
+
});
|
|
228
207
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
})
|
|
233
|
-
var OAuthAccessTokenResponse = (0,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
})
|
|
240
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
})
|
|
252
|
-
var OAuthErrorResponse = (0,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
})
|
|
208
|
+
redirectURI: (0, import_zod.string)(),
|
|
209
|
+
code: (0, import_zod.string)(),
|
|
210
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
211
|
+
});
|
|
212
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
213
|
+
access_token: (0, import_zod.string)(),
|
|
214
|
+
token_type: (0, import_zod.string)().optional(),
|
|
215
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
216
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
217
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
218
|
+
});
|
|
219
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
220
|
+
error: (0, import_zod.enum)([
|
|
221
|
+
"invalid_request",
|
|
222
|
+
"invalid_client",
|
|
223
|
+
"invalid_grant",
|
|
224
|
+
"unauthorized_client",
|
|
225
|
+
"unsupported_grant_type",
|
|
226
|
+
"invalid_scope"
|
|
227
|
+
]),
|
|
228
|
+
error_description: (0, import_zod.string)().optional(),
|
|
229
|
+
error_uri: (0, import_zod.string)().optional()
|
|
230
|
+
});
|
|
231
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
232
|
+
error: (0, import_zod.string)(),
|
|
233
|
+
error_description: (0, import_zod.string)().optional()
|
|
234
|
+
});
|
|
235
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
236
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
237
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
238
|
+
});
|
|
256
239
|
|
|
257
240
|
// src/actions/signIn/authorization.ts
|
|
258
241
|
var getOriginURL = (request, trustedProxyHeaders) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
} else {
|
|
269
|
-
return new URL(getNormalizedOriginPath(request.url))
|
|
270
|
-
}
|
|
271
|
-
}
|
|
242
|
+
const headers = request.headers;
|
|
243
|
+
if (trustedProxyHeaders) {
|
|
244
|
+
const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
|
|
245
|
+
const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
|
|
246
|
+
return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
|
|
247
|
+
} else {
|
|
248
|
+
return new URL(getNormalizedOriginPath(request.url));
|
|
249
|
+
}
|
|
250
|
+
};
|
|
272
251
|
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
291
|
-
throw new AuthError(
|
|
292
|
-
ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
|
|
293
|
-
"The referer of the request does not match the hosted origin."
|
|
294
|
-
)
|
|
295
|
-
}
|
|
296
|
-
return sanitizeURL(refererURL.pathname)
|
|
297
|
-
}
|
|
298
|
-
if (origin) {
|
|
299
|
-
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)))
|
|
300
|
-
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
301
|
-
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
302
|
-
}
|
|
303
|
-
return sanitizeURL(originURL.pathname)
|
|
304
|
-
}
|
|
305
|
-
return "/"
|
|
306
|
-
} catch (error) {
|
|
307
|
-
if (isAuthError(error)) {
|
|
308
|
-
throw error
|
|
309
|
-
}
|
|
310
|
-
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// src/cookie.ts
|
|
315
|
-
var import_cookie = require("cookie")
|
|
316
|
-
var import_cookie2 = require("cookie")
|
|
317
|
-
var COOKIE_NAME = "aura-auth"
|
|
318
|
-
var defaultCookieOptions = {
|
|
319
|
-
httpOnly: true,
|
|
320
|
-
sameSite: "lax",
|
|
321
|
-
path: "/",
|
|
322
|
-
maxAge: 60 * 60 * 24 * 15,
|
|
323
|
-
}
|
|
324
|
-
var defaultStandardCookieConfig = {
|
|
325
|
-
secure: false,
|
|
326
|
-
httpOnly: true,
|
|
327
|
-
prefix: "",
|
|
328
|
-
}
|
|
329
|
-
var defaultSecureCookieConfig = {
|
|
330
|
-
secure: true,
|
|
331
|
-
prefix: "__Secure-",
|
|
332
|
-
}
|
|
333
|
-
var defaultHostCookieConfig = {
|
|
334
|
-
secure: true,
|
|
335
|
-
prefix: "__Host-",
|
|
336
|
-
path: "/",
|
|
337
|
-
domain: void 0,
|
|
338
|
-
}
|
|
339
|
-
var expiredCookieOptions = {
|
|
340
|
-
...defaultCookieOptions,
|
|
341
|
-
expires: /* @__PURE__ */ new Date(0),
|
|
342
|
-
maxAge: 0,
|
|
343
|
-
}
|
|
344
|
-
var defineDefaultCookieOptions = (options2) => {
|
|
345
|
-
return {
|
|
346
|
-
name: options2?.name ?? COOKIE_NAME,
|
|
347
|
-
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
348
|
-
...defaultCookieOptions,
|
|
349
|
-
...options2,
|
|
252
|
+
try {
|
|
253
|
+
const headers = request.headers;
|
|
254
|
+
const origin = headers.get("Origin");
|
|
255
|
+
const referer = headers.get("Referer");
|
|
256
|
+
let hostedURL = getOriginURL(request, trustedProxyHeaders);
|
|
257
|
+
if (redirectTo) {
|
|
258
|
+
if (redirectTo.startsWith("/")) {
|
|
259
|
+
return sanitizeURL(redirectTo);
|
|
260
|
+
}
|
|
261
|
+
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
262
|
+
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
263
|
+
throw new AuthSecurityError(
|
|
264
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
265
|
+
"The redirectTo parameter does not match the hosted origin."
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
return sanitizeURL(redirectToURL.pathname);
|
|
350
269
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
var getCookie = (petition, cookie, options2, optional = false) => {
|
|
361
|
-
const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ")
|
|
362
|
-
if (!cookies) {
|
|
363
|
-
if (optional) {
|
|
364
|
-
return ""
|
|
365
|
-
}
|
|
366
|
-
throw new AuthError("invalid_request", "No cookies found. There is no active session")
|
|
270
|
+
if (referer) {
|
|
271
|
+
const refererURL = new URL(sanitizeURL(referer));
|
|
272
|
+
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
273
|
+
throw new AuthSecurityError(
|
|
274
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
275
|
+
"The referer of the request does not match the hosted origin."
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
return sanitizeURL(refererURL.pathname);
|
|
367
279
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`)
|
|
280
|
+
if (origin) {
|
|
281
|
+
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
282
|
+
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
283
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
284
|
+
}
|
|
285
|
+
return sanitizeURL(originURL.pathname);
|
|
376
286
|
}
|
|
377
|
-
return
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const isSecure = trustedProxyHeaders
|
|
382
|
-
? request.url.startsWith("https://") ||
|
|
383
|
-
request.headers.get("X-Forwarded-Proto") === "https" ||
|
|
384
|
-
request.headers.get("Forwarded")?.includes("proto=https")
|
|
385
|
-
: request.url.startsWith("https://")
|
|
386
|
-
if (!cookieOptions.options?.httpOnly) {
|
|
387
|
-
console.warn(
|
|
388
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
389
|
-
)
|
|
287
|
+
return "/";
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (isAuthSecurityError(error)) {
|
|
290
|
+
throw error;
|
|
390
291
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (!isSecure) {
|
|
395
|
-
const options2 = cookieOptions.options
|
|
396
|
-
if (options2?.secure) {
|
|
397
|
-
console.warn(
|
|
398
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
399
|
-
)
|
|
400
|
-
}
|
|
401
|
-
if (options2?.sameSite == "none") {
|
|
402
|
-
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.")
|
|
403
|
-
}
|
|
404
|
-
if (process.env.NODE_ENV === "production") {
|
|
405
|
-
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.")
|
|
406
|
-
}
|
|
407
|
-
return {
|
|
408
|
-
...defaultCookieOptions,
|
|
409
|
-
...cookieOptions.options,
|
|
410
|
-
sameSite: options2?.sameSite === "none" ? "lax" : (options2?.sameSite ?? "lax"),
|
|
411
|
-
...defaultStandardCookieConfig,
|
|
412
|
-
name,
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
return cookieOptions.strategy === "host"
|
|
416
|
-
? {
|
|
417
|
-
...defaultCookieOptions,
|
|
418
|
-
...cookieOptions.options,
|
|
419
|
-
...defaultHostCookieConfig,
|
|
420
|
-
name,
|
|
421
|
-
}
|
|
422
|
-
: { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name }
|
|
423
|
-
}
|
|
424
|
-
var expireCookie = (name, options2) => {
|
|
425
|
-
return setCookie(name, "", { ...options2, ...expiredCookieOptions })
|
|
426
|
-
}
|
|
292
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
293
|
+
}
|
|
294
|
+
};
|
|
427
295
|
|
|
428
296
|
// src/actions/signOut/signOut.ts
|
|
429
297
|
var config = (0, import_router2.createEndpointConfig)({
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
})
|
|
298
|
+
schemas: {
|
|
299
|
+
searchParams: import_zod2.z.object({
|
|
300
|
+
token_type_hint: import_zod2.z.literal("session_token"),
|
|
301
|
+
redirectTo: import_zod2.z.string().optional()
|
|
302
|
+
})
|
|
303
|
+
}
|
|
304
|
+
});
|
|
437
305
|
var signOutAction = (0, import_router2.createEndpoint)(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
responseHeaders.append("Location", location)
|
|
474
|
-
return Response.json(
|
|
475
|
-
{ message: "Signed out successfully" },
|
|
476
|
-
{ status: import_router2.statusCode.ACCEPTED, headers: responseHeaders }
|
|
477
|
-
)
|
|
478
|
-
} catch (error) {
|
|
479
|
-
if (error instanceof InvalidCsrfTokenError) {
|
|
480
|
-
return AuraResponse.json(
|
|
481
|
-
{
|
|
482
|
-
error: "invalid_csrf_token",
|
|
483
|
-
error_description: "The provided CSRF token is invalid or has expired",
|
|
484
|
-
},
|
|
485
|
-
{ status: import_router2.statusCode.UNAUTHORIZED }
|
|
486
|
-
)
|
|
487
|
-
}
|
|
488
|
-
if (error instanceof InvalidRedirectToError) {
|
|
489
|
-
const { type, message } = error
|
|
490
|
-
return AuraResponse.json(
|
|
491
|
-
{
|
|
492
|
-
error: type,
|
|
493
|
-
error_description: message,
|
|
494
|
-
},
|
|
495
|
-
{ status: import_router2.statusCode.BAD_REQUEST }
|
|
496
|
-
)
|
|
497
|
-
}
|
|
498
|
-
return AuraResponse.json(
|
|
499
|
-
{
|
|
500
|
-
error: "invalid_session_token",
|
|
501
|
-
error_description: "The provided sessionToken is invalid or has already expired",
|
|
502
|
-
},
|
|
503
|
-
{ status: import_router2.statusCode.UNAUTHORIZED }
|
|
504
|
-
)
|
|
505
|
-
}
|
|
506
|
-
},
|
|
507
|
-
config
|
|
508
|
-
)
|
|
306
|
+
"POST",
|
|
307
|
+
"/signOut",
|
|
308
|
+
async (ctx) => {
|
|
309
|
+
const {
|
|
310
|
+
request,
|
|
311
|
+
headers,
|
|
312
|
+
searchParams: { redirectTo },
|
|
313
|
+
context: { jose, cookies }
|
|
314
|
+
} = ctx;
|
|
315
|
+
const session = headers.getCookie(cookies.sessionToken.name);
|
|
316
|
+
const csrfToken = headers.getCookie(cookies.csrfToken.name);
|
|
317
|
+
const header = headers.getHeader("X-CSRF-Token");
|
|
318
|
+
if (!session) {
|
|
319
|
+
throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
|
|
320
|
+
}
|
|
321
|
+
if (!csrfToken) {
|
|
322
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
|
|
323
|
+
}
|
|
324
|
+
if (!header) {
|
|
325
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF header is missing.");
|
|
326
|
+
}
|
|
327
|
+
await verifyCSRF(jose, csrfToken, header);
|
|
328
|
+
await jose.decodeJWT(session);
|
|
329
|
+
const normalizedOriginPath = getNormalizedOriginPath(request.url);
|
|
330
|
+
const location = createRedirectTo(
|
|
331
|
+
new Request(normalizedOriginPath, {
|
|
332
|
+
headers: headers.toHeaders()
|
|
333
|
+
}),
|
|
334
|
+
redirectTo
|
|
335
|
+
);
|
|
336
|
+
const headersList = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", location).setCookie(cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
337
|
+
return Response.json({ message: "Signed out successfully" }, { status: import_router2.statusCode.ACCEPTED, headers: headersList });
|
|
338
|
+
},
|
|
339
|
+
config
|
|
340
|
+
);
|
|
509
341
|
// Annotate the CommonJS export names for ESM import in node:
|
|
510
|
-
0 &&
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
})
|
|
342
|
+
0 && (module.exports = {
|
|
343
|
+
signOutAction
|
|
344
|
+
});
|