@aura-stack/auth 0.1.0-rc.8 → 0.1.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.
- 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 +6 -6
- package/dist/@types/utility.js +1 -1
- package/dist/actions/callback/access-token.cjs +143 -143
- package/dist/actions/callback/access-token.d.ts +15 -20
- package/dist/actions/callback/access-token.js +8 -4
- package/dist/actions/callback/callback.cjs +437 -455
- package/dist/actions/callback/callback.d.ts +10 -12
- package/dist/actions/callback/callback.js +16 -12
- package/dist/actions/callback/userinfo.cjs +131 -134
- package/dist/actions/callback/userinfo.d.ts +9 -9
- package/dist/actions/callback/userinfo.js +10 -6
- package/dist/actions/csrfToken/csrfToken.cjs +162 -171
- package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
- package/dist/actions/csrfToken/csrfToken.js +12 -8
- package/dist/actions/index.cjs +746 -773
- package/dist/actions/index.d.ts +13 -13
- package/dist/actions/index.js +34 -18
- package/dist/actions/session/session.cjs +149 -155
- package/dist/actions/session/session.d.ts +3 -3
- package/dist/actions/session/session.js +11 -7
- package/dist/actions/signIn/authorization.cjs +231 -249
- package/dist/actions/signIn/authorization.d.ts +12 -18
- package/dist/actions/signIn/authorization.js +16 -6
- package/dist/actions/signIn/signIn.cjs +396 -423
- package/dist/actions/signIn/signIn.d.ts +10 -10
- package/dist/actions/signIn/signIn.js +14 -10
- package/dist/actions/signOut/signOut.cjs +417 -440
- package/dist/actions/signOut/signOut.d.ts +3 -3
- package/dist/actions/signOut/signOut.js +15 -11
- package/dist/assert.cjs +35 -36
- package/dist/assert.d.ts +4 -4
- package/dist/assert.js +10 -2
- package/dist/chunk-256KIVJL.js +85 -96
- package/dist/chunk-42XB3YCW.js +19 -17
- package/dist/chunk-6SM22VVJ.js +13 -10
- package/dist/chunk-CAKJT3KS.js +84 -69
- package/dist/chunk-E3OXBRYF.js +19 -17
- package/dist/chunk-EBPE35JT.js +28 -26
- package/dist/chunk-FIPU4MLT.js +18 -16
- package/dist/chunk-FJUDBLCP.js +50 -43
- package/dist/chunk-FKRDCWBF.js +19 -17
- package/dist/chunk-GZU3RBTB.js +51 -40
- package/dist/chunk-HGJ4TXY4.js +132 -100
- package/dist/chunk-HMRKN75I.js +63 -63
- package/dist/chunk-IKHPGFCW.js +11 -9
- package/dist/chunk-JAPMIE6S.js +7 -5
- package/dist/chunk-KRNOMBXQ.js +19 -17
- package/dist/chunk-LLR722CL.js +91 -70
- package/dist/chunk-RLT4RFKV.js +39 -30
- package/dist/chunk-SJPDVKUS.js +107 -88
- package/dist/chunk-SMQO5WD7.js +26 -16
- package/dist/chunk-STHEPPUZ.js +8 -6
- package/dist/chunk-UJJ7R56J.js +47 -37
- package/dist/chunk-UTDLUEEG.js +27 -21
- package/dist/chunk-VFTYH33W.js +54 -37
- package/dist/chunk-XXJKNKGQ.js +33 -23
- package/dist/chunk-ZV4BH47P.js +132 -134
- package/dist/cookie.cjs +169 -175
- package/dist/cookie.d.ts +23 -51
- package/dist/cookie.js +34 -34
- package/dist/error.cjs +75 -75
- package/dist/error.d.ts +30 -30
- package/dist/error.js +15 -8
- package/dist/headers.cjs +28 -28
- package/dist/headers.d.ts +2 -2
- package/dist/headers.js +6 -2
- package/dist/index-DpfbvTZ_.d.ts +249 -298
- package/dist/index.cjs +936 -969
- package/dist/index.d.ts +10 -31
- package/dist/index.js +70 -50
- package/dist/jose.cjs +61 -64
- package/dist/jose.d.ts +8 -8
- package/dist/jose.js +9 -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 +48 -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 +180 -180
- package/dist/oauth/index.d.ts +7 -26
- package/dist/oauth/index.js +36 -9
- 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/x.cjs +39 -39
- package/dist/oauth/x.d.ts +7 -7
- package/dist/oauth/x.js +6 -2
- package/dist/response.cjs +27 -27
- package/dist/response.d.ts +2 -2
- package/dist/response.js +6 -2
- package/dist/schemas.cjs +91 -91
- package/dist/schemas.d.ts +93 -126
- package/dist/schemas.js +18 -18
- package/dist/secure.cjs +95 -98
- package/dist/secure.d.ts +17 -17
- package/dist/secure.js +18 -4
- package/dist/utils.cjs +119 -132
- package/dist/utils.d.ts +11 -26
- package/dist/utils.js +21 -21
- package/package.json +2 -2
|
@@ -1,496 +1,469 @@
|
|
|
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/signIn/signIn.ts
|
|
33
|
-
var signIn_exports = {}
|
|
31
|
+
var signIn_exports = {};
|
|
34
32
|
__export(signIn_exports, {
|
|
35
|
-
|
|
36
|
-
})
|
|
37
|
-
module.exports = __toCommonJS(signIn_exports)
|
|
38
|
-
var import_zod = __toESM(require("zod"), 1)
|
|
39
|
-
var import_router2 = require("@aura-stack/router")
|
|
33
|
+
signInAction: () => signInAction
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(signIn_exports);
|
|
36
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
37
|
+
var import_router2 = require("@aura-stack/router");
|
|
40
38
|
|
|
41
39
|
// src/response.ts
|
|
42
40
|
var AuraResponse = class extends Response {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
41
|
+
static json(body, init) {
|
|
42
|
+
return Response.json(body, init);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
47
45
|
|
|
48
46
|
// src/secure.ts
|
|
49
|
-
var import_node_crypto = __toESM(require("crypto"), 1)
|
|
47
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
50
48
|
|
|
51
49
|
// src/utils.ts
|
|
52
|
-
var import_router = require("@aura-stack/router")
|
|
50
|
+
var import_router = require("@aura-stack/router");
|
|
53
51
|
|
|
54
52
|
// src/error.ts
|
|
55
53
|
var AuthError = class extends Error {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
54
|
+
constructor(type, message) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.type = type;
|
|
57
|
+
this.name = "AuthError";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
62
60
|
var InvalidRedirectToError = class extends AuthError {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
61
|
+
constructor(message = "The redirectTo parameter does not match the hosted origin.") {
|
|
62
|
+
super("invalid_redirect_to", message);
|
|
63
|
+
this.name = "InvalidRedirectToError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
68
66
|
var isAuthError = (error) => {
|
|
69
|
-
|
|
70
|
-
}
|
|
67
|
+
return error instanceof AuthError;
|
|
68
|
+
};
|
|
71
69
|
var ERROR_RESPONSE = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
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
|
+
}
|
|
87
|
+
};
|
|
90
88
|
|
|
91
89
|
// src/utils.ts
|
|
92
90
|
var toSnakeCase = (str) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
96
|
-
.toLowerCase()
|
|
97
|
-
.replace(/^_+/, "")
|
|
98
|
-
}
|
|
91
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
|
|
92
|
+
};
|
|
99
93
|
var toUpperCase = (str) => {
|
|
100
|
-
|
|
101
|
-
}
|
|
94
|
+
return str.toUpperCase();
|
|
95
|
+
};
|
|
102
96
|
var toCastCase = (obj, type = "snake") => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
97
|
+
return Object.entries(obj).reduce((previous, [key, value]) => {
|
|
98
|
+
const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
|
|
99
|
+
return { ...previous, [newKey]: value };
|
|
100
|
+
}, {});
|
|
101
|
+
};
|
|
108
102
|
var equals = (a, b) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
103
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
104
|
+
return a === b;
|
|
105
|
+
};
|
|
112
106
|
var sanitizeURL = (url2) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
path = path.replace(/\/+$/, "/")
|
|
134
|
-
} else if (path !== "/") {
|
|
135
|
-
path = path.replace(/\/+$/, "")
|
|
136
|
-
}
|
|
137
|
-
return protocol + domain + path
|
|
138
|
-
}
|
|
139
|
-
let sanitized = decodedURL
|
|
140
|
-
.replace(/\/\.\.\//g, "/")
|
|
141
|
-
.replace(/\/\.\.$/, "")
|
|
142
|
-
.replace(/\.{2,}/g, "")
|
|
143
|
-
.replace(/\/{2,}/g, "/")
|
|
144
|
-
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
145
|
-
sanitized = sanitized.replace(/\/+$/, "/")
|
|
146
|
-
} else if (sanitized !== "/") {
|
|
147
|
-
sanitized = sanitized.replace(/\/+$/, "")
|
|
148
|
-
}
|
|
149
|
-
return sanitized
|
|
150
|
-
} catch {
|
|
151
|
-
return url2.trim()
|
|
107
|
+
try {
|
|
108
|
+
let decodedURL = decodeURIComponent(url2).trim();
|
|
109
|
+
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
|
|
110
|
+
let protocol = "";
|
|
111
|
+
let rest = decodedURL;
|
|
112
|
+
if (protocolMatch) {
|
|
113
|
+
protocol = protocolMatch[1];
|
|
114
|
+
rest = decodedURL.slice(protocol.length);
|
|
115
|
+
const slashIndex = rest.indexOf("/");
|
|
116
|
+
if (slashIndex === -1) {
|
|
117
|
+
return protocol + rest;
|
|
118
|
+
}
|
|
119
|
+
const domain = rest.slice(0, slashIndex);
|
|
120
|
+
let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
121
|
+
if (path !== "/" && path.endsWith("/")) {
|
|
122
|
+
path = path.replace(/\/+$/, "/");
|
|
123
|
+
} else if (path !== "/") {
|
|
124
|
+
path = path.replace(/\/+$/, "");
|
|
125
|
+
}
|
|
126
|
+
return protocol + domain + path;
|
|
152
127
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
url2.search = ""
|
|
159
|
-
return `${url2.origin}${url2.pathname}`
|
|
160
|
-
} catch {
|
|
161
|
-
return sanitizeURL(path)
|
|
128
|
+
let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
129
|
+
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
130
|
+
sanitized = sanitized.replace(/\/+$/, "/");
|
|
131
|
+
} else if (sanitized !== "/") {
|
|
132
|
+
sanitized = sanitized.replace(/\/+$/, "");
|
|
162
133
|
}
|
|
163
|
-
|
|
134
|
+
return sanitized;
|
|
135
|
+
} catch {
|
|
136
|
+
return url2.trim();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var getNormalizedOriginPath = (path) => {
|
|
140
|
+
try {
|
|
141
|
+
const url2 = new URL(path);
|
|
142
|
+
url2.hash = "";
|
|
143
|
+
url2.search = "";
|
|
144
|
+
return `${url2.origin}${url2.pathname}`;
|
|
145
|
+
} catch {
|
|
146
|
+
return sanitizeURL(path);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
164
149
|
|
|
165
150
|
// src/secure.ts
|
|
166
151
|
var generateSecure = (length = 32) => {
|
|
167
|
-
|
|
168
|
-
}
|
|
152
|
+
return import_node_crypto.default.randomBytes(length).toString("base64url");
|
|
153
|
+
};
|
|
169
154
|
var createHash = (data, base = "hex") => {
|
|
170
|
-
|
|
171
|
-
}
|
|
155
|
+
return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base);
|
|
156
|
+
};
|
|
172
157
|
var createPKCE = async (verifier) => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
158
|
+
const codeVerifier = verifier ?? generateSecure(86);
|
|
159
|
+
const codeChallenge = createHash(codeVerifier, "base64url");
|
|
160
|
+
return { codeVerifier, codeChallenge, method: "S256" };
|
|
161
|
+
};
|
|
177
162
|
|
|
178
163
|
// src/cookie.ts
|
|
179
|
-
var import_cookie = require("cookie")
|
|
164
|
+
var import_cookie = require("cookie");
|
|
180
165
|
|
|
181
166
|
// src/assert.ts
|
|
182
167
|
var isValidURL = (value) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
168
|
+
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
|
|
169
|
+
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
|
|
170
|
+
return regex.test(value);
|
|
171
|
+
};
|
|
188
172
|
|
|
189
173
|
// src/cookie.ts
|
|
190
|
-
var import_cookie2 = require("cookie")
|
|
191
|
-
var COOKIE_NAME = "aura-auth"
|
|
174
|
+
var import_cookie2 = require("cookie");
|
|
175
|
+
var COOKIE_NAME = "aura-auth";
|
|
192
176
|
var defaultCookieOptions = {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
177
|
+
httpOnly: true,
|
|
178
|
+
sameSite: "lax",
|
|
179
|
+
path: "/",
|
|
180
|
+
maxAge: 60 * 60 * 24 * 15
|
|
181
|
+
};
|
|
198
182
|
var defaultStandardCookieConfig = {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
183
|
+
secure: false,
|
|
184
|
+
httpOnly: true,
|
|
185
|
+
prefix: ""
|
|
186
|
+
};
|
|
203
187
|
var defaultSecureCookieConfig = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
188
|
+
secure: true,
|
|
189
|
+
prefix: "__Secure-"
|
|
190
|
+
};
|
|
207
191
|
var defaultHostCookieConfig = {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
192
|
+
secure: true,
|
|
193
|
+
prefix: "__Host-",
|
|
194
|
+
path: "/",
|
|
195
|
+
domain: void 0
|
|
196
|
+
};
|
|
213
197
|
var expiredCookieOptions = {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
198
|
+
...defaultCookieOptions,
|
|
199
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
200
|
+
maxAge: 0
|
|
201
|
+
};
|
|
218
202
|
var defineDefaultCookieOptions = (options2) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
203
|
+
return {
|
|
204
|
+
name: options2?.name ?? COOKIE_NAME,
|
|
205
|
+
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
206
|
+
...defaultCookieOptions,
|
|
207
|
+
...options2
|
|
208
|
+
};
|
|
209
|
+
};
|
|
226
210
|
var setCookie = (cookieName, value, options2) => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
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
|
+
});
|
|
217
|
+
};
|
|
234
218
|
var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
219
|
+
const name = cookieOptions.name ?? COOKIE_NAME;
|
|
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
|
+
);
|
|
245
235
|
}
|
|
246
|
-
if (
|
|
247
|
-
|
|
236
|
+
if (options2?.sameSite == "none") {
|
|
237
|
+
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
|
|
248
238
|
}
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
if (options2?.secure) {
|
|
252
|
-
console.warn(
|
|
253
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
254
|
-
)
|
|
255
|
-
}
|
|
256
|
-
if (options2?.sameSite == "none") {
|
|
257
|
-
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.")
|
|
258
|
-
}
|
|
259
|
-
if (process.env.NODE_ENV === "production") {
|
|
260
|
-
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.")
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
...defaultCookieOptions,
|
|
264
|
-
...cookieOptions.options,
|
|
265
|
-
sameSite: options2?.sameSite === "none" ? "lax" : (options2?.sameSite ?? "lax"),
|
|
266
|
-
...defaultStandardCookieConfig,
|
|
267
|
-
name,
|
|
268
|
-
}
|
|
239
|
+
if (process.env.NODE_ENV === "production") {
|
|
240
|
+
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
|
|
269
241
|
}
|
|
270
|
-
return cookieOptions.strategy === "host"
|
|
271
|
-
? {
|
|
272
|
-
...defaultCookieOptions,
|
|
273
|
-
...cookieOptions.options,
|
|
274
|
-
...defaultHostCookieConfig,
|
|
275
|
-
name,
|
|
276
|
-
}
|
|
277
|
-
: { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name }
|
|
278
|
-
}
|
|
279
|
-
var oauthCookie = (options2) => {
|
|
280
242
|
return {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
}
|
|
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 };
|
|
256
|
+
};
|
|
257
|
+
var oauthCookie = (options2) => {
|
|
258
|
+
return {
|
|
259
|
+
...options2,
|
|
260
|
+
secure: options2.secure,
|
|
261
|
+
httpOnly: options2.httpOnly,
|
|
262
|
+
maxAge: 5 * 60,
|
|
263
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
264
|
+
};
|
|
265
|
+
};
|
|
288
266
|
|
|
289
267
|
// src/schemas.ts
|
|
290
|
-
var import_v4 = require("zod/v4")
|
|
268
|
+
var import_v4 = require("zod/v4");
|
|
291
269
|
var OAuthProviderConfigSchema = (0, import_v4.object)({
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
})
|
|
270
|
+
authorizeURL: (0, import_v4.url)(),
|
|
271
|
+
accessToken: (0, import_v4.url)(),
|
|
272
|
+
scope: (0, import_v4.string)().optional(),
|
|
273
|
+
userInfo: (0, import_v4.url)(),
|
|
274
|
+
responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
|
|
275
|
+
clientId: (0, import_v4.string)(),
|
|
276
|
+
clientSecret: (0, import_v4.string)()
|
|
277
|
+
});
|
|
300
278
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
})
|
|
279
|
+
redirectURI: (0, import_v4.string)(),
|
|
280
|
+
state: (0, import_v4.string)(),
|
|
281
|
+
codeChallenge: (0, import_v4.string)(),
|
|
282
|
+
codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
|
|
283
|
+
});
|
|
306
284
|
var OAuthAuthorizationResponse = (0, import_v4.object)({
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
})
|
|
285
|
+
state: (0, import_v4.string)(),
|
|
286
|
+
code: (0, import_v4.string)()
|
|
287
|
+
});
|
|
310
288
|
var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
})
|
|
289
|
+
error: (0, import_v4.enum)([
|
|
290
|
+
"invalid_request",
|
|
291
|
+
"unauthorized_client",
|
|
292
|
+
"access_denied",
|
|
293
|
+
"unsupported_response_type",
|
|
294
|
+
"invalid_scope",
|
|
295
|
+
"server_error",
|
|
296
|
+
"temporarily_unavailable"
|
|
297
|
+
]),
|
|
298
|
+
error_description: (0, import_v4.string)().optional(),
|
|
299
|
+
error_uri: (0, import_v4.string)().optional(),
|
|
300
|
+
state: (0, import_v4.string)()
|
|
301
|
+
});
|
|
324
302
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
})
|
|
303
|
+
redirectURI: (0, import_v4.string)(),
|
|
304
|
+
code: (0, import_v4.string)(),
|
|
305
|
+
codeVerifier: (0, import_v4.string)().min(43).max(128)
|
|
306
|
+
});
|
|
329
307
|
var OAuthAccessTokenResponse = (0, import_v4.object)({
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
})
|
|
308
|
+
access_token: (0, import_v4.string)(),
|
|
309
|
+
token_type: (0, import_v4.string)(),
|
|
310
|
+
expires_in: (0, import_v4.number)().optional(),
|
|
311
|
+
refresh_token: (0, import_v4.string)().optional(),
|
|
312
|
+
scope: (0, import_v4.string)().optional()
|
|
313
|
+
});
|
|
336
314
|
var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
})
|
|
315
|
+
error: (0, import_v4.enum)([
|
|
316
|
+
"invalid_request",
|
|
317
|
+
"invalid_client",
|
|
318
|
+
"invalid_grant",
|
|
319
|
+
"unauthorized_client",
|
|
320
|
+
"unsupported_grant_type",
|
|
321
|
+
"invalid_scope"
|
|
322
|
+
]),
|
|
323
|
+
error_description: (0, import_v4.string)().optional(),
|
|
324
|
+
error_uri: (0, import_v4.string)().optional()
|
|
325
|
+
});
|
|
348
326
|
var OAuthErrorResponse = (0, import_v4.object)({
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
})
|
|
327
|
+
error: (0, import_v4.string)(),
|
|
328
|
+
error_description: (0, import_v4.string)().optional()
|
|
329
|
+
});
|
|
352
330
|
|
|
353
331
|
// src/actions/signIn/authorization.ts
|
|
354
332
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
333
|
+
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
334
|
+
if (!parsed.success) {
|
|
335
|
+
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration");
|
|
336
|
+
}
|
|
337
|
+
const { authorizeURL, ...options2 } = parsed.data;
|
|
338
|
+
const { userInfo, accessToken, clientSecret, ...required } = options2;
|
|
339
|
+
const searchParams = new URLSearchParams(toCastCase(required));
|
|
340
|
+
return `${authorizeURL}?${searchParams}`;
|
|
341
|
+
};
|
|
364
342
|
var getOriginURL = (request, trustedProxyHeaders) => {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
} else {
|
|
375
|
-
return new URL(getNormalizedOriginPath(request.url))
|
|
376
|
-
}
|
|
377
|
-
}
|
|
343
|
+
const headers = request.headers;
|
|
344
|
+
if (trustedProxyHeaders) {
|
|
345
|
+
const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
|
|
346
|
+
const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
|
|
347
|
+
return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
|
|
348
|
+
} else {
|
|
349
|
+
return new URL(getNormalizedOriginPath(request.url));
|
|
350
|
+
}
|
|
351
|
+
};
|
|
378
352
|
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
353
|
+
const url2 = getOriginURL(request, trustedProxyHeaders);
|
|
354
|
+
return `${url2.origin}${basePath}/callback/${oauth}`;
|
|
355
|
+
};
|
|
382
356
|
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
return "/"
|
|
416
|
-
} catch (error) {
|
|
417
|
-
if (isAuthError(error)) {
|
|
418
|
-
throw error
|
|
419
|
-
}
|
|
420
|
-
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
357
|
+
try {
|
|
358
|
+
const headers = request.headers;
|
|
359
|
+
const origin = headers.get("Origin");
|
|
360
|
+
const referer = headers.get("Referer");
|
|
361
|
+
let hostedURL = getOriginURL(request, trustedProxyHeaders);
|
|
362
|
+
if (redirectTo) {
|
|
363
|
+
if (redirectTo.startsWith("/")) {
|
|
364
|
+
return sanitizeURL(redirectTo);
|
|
365
|
+
}
|
|
366
|
+
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
367
|
+
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
368
|
+
throw new InvalidRedirectToError();
|
|
369
|
+
}
|
|
370
|
+
return sanitizeURL(redirectToURL.pathname);
|
|
371
|
+
}
|
|
372
|
+
if (referer) {
|
|
373
|
+
const refererURL = new URL(sanitizeURL(referer));
|
|
374
|
+
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
375
|
+
throw new AuthError(
|
|
376
|
+
ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
|
|
377
|
+
"The referer of the request does not match the hosted origin."
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
return sanitizeURL(refererURL.pathname);
|
|
381
|
+
}
|
|
382
|
+
if (origin) {
|
|
383
|
+
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
384
|
+
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
385
|
+
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
|
|
386
|
+
}
|
|
387
|
+
return sanitizeURL(originURL.pathname);
|
|
421
388
|
}
|
|
422
|
-
|
|
389
|
+
return "/";
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (isAuthError(error)) {
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
|
|
395
|
+
}
|
|
396
|
+
};
|
|
423
397
|
|
|
424
398
|
// src/actions/signIn/signIn.ts
|
|
425
399
|
var signInConfig = (oauth) => {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
400
|
+
return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
|
|
401
|
+
schemas: {
|
|
402
|
+
params: import_zod.default.object({
|
|
403
|
+
oauth: import_zod.default.enum(Object.keys(oauth)),
|
|
404
|
+
redirectTo: import_zod.default.string().optional()
|
|
405
|
+
})
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
};
|
|
435
409
|
var signInAction = (oauth) => {
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
}
|
|
410
|
+
return (0, import_router2.createEndpoint)(
|
|
411
|
+
"GET",
|
|
412
|
+
"/signIn/:oauth",
|
|
413
|
+
async (ctx) => {
|
|
414
|
+
const {
|
|
415
|
+
request,
|
|
416
|
+
params: { oauth: oauth2, redirectTo },
|
|
417
|
+
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
418
|
+
} = ctx;
|
|
419
|
+
try {
|
|
420
|
+
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
|
|
421
|
+
const state = generateSecure();
|
|
422
|
+
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
|
|
423
|
+
const stateCookie = setCookie("state", state, oauthCookie(cookieOptions));
|
|
424
|
+
const redirectURICookie = setCookie("redirect_uri", redirectURI, oauthCookie(cookieOptions));
|
|
425
|
+
const redirectToCookie = setCookie(
|
|
426
|
+
"redirect_to",
|
|
427
|
+
createRedirectTo(request, redirectTo, trustedProxyHeaders),
|
|
428
|
+
oauthCookie(cookieOptions)
|
|
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
|
+
);
|
|
453
|
+
}
|
|
454
|
+
return AuraResponse.json(
|
|
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
|
+
}
|
|
462
|
+
},
|
|
463
|
+
signInConfig(oauth)
|
|
464
|
+
);
|
|
465
|
+
};
|
|
492
466
|
// Annotate the CommonJS export names for ESM import in node:
|
|
493
|
-
0 &&
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
})
|
|
467
|
+
0 && (module.exports = {
|
|
468
|
+
signInAction
|
|
469
|
+
});
|