@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,496 +1,360 @@
|
|
|
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
|
|
39
|
-
var import_router2 = require("@aura-stack/router")
|
|
33
|
+
signInAction: () => signInAction
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(signIn_exports);
|
|
36
|
+
var import_zod2 = require("zod");
|
|
37
|
+
var import_router2 = require("@aura-stack/router");
|
|
40
38
|
|
|
41
|
-
// src/
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
// src/headers.ts
|
|
40
|
+
var cacheControl = {
|
|
41
|
+
"Cache-Control": "no-store",
|
|
42
|
+
Pragma: "no-cache",
|
|
43
|
+
Expires: "0",
|
|
44
|
+
Vary: "Cookie"
|
|
45
|
+
};
|
|
47
46
|
|
|
48
47
|
// src/secure.ts
|
|
49
|
-
var
|
|
48
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
50
49
|
|
|
51
50
|
// src/utils.ts
|
|
52
|
-
var import_router = require("@aura-stack/router")
|
|
51
|
+
var import_router = require("@aura-stack/router");
|
|
53
52
|
|
|
54
|
-
// src/
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
SERVER_ERROR: "server_error",
|
|
79
|
-
TEMPORARILY_UNAVAILABLE: "temporarily_unavailable",
|
|
80
|
-
},
|
|
81
|
-
ACCESS_TOKEN: {
|
|
82
|
-
INVALID_REQUEST: "invalid_request",
|
|
83
|
-
INVALID_CLIENT: "invalid_client",
|
|
84
|
-
INVALID_GRANT: "invalid_grant",
|
|
85
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
86
|
-
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
87
|
-
INVALID_SCOPE: "invalid_scope",
|
|
88
|
-
},
|
|
89
|
-
}
|
|
53
|
+
// src/errors.ts
|
|
54
|
+
var AuthInternalError = class extends Error {
|
|
55
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
56
|
+
code;
|
|
57
|
+
constructor(code, message, options2) {
|
|
58
|
+
super(message, options2);
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.name = new.target.name;
|
|
61
|
+
Error.captureStackTrace(this, new.target);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var AuthSecurityError = class extends Error {
|
|
65
|
+
type = "AUTH_SECURITY_ERROR";
|
|
66
|
+
code;
|
|
67
|
+
constructor(code, message, options2) {
|
|
68
|
+
super(message, options2);
|
|
69
|
+
this.code = code;
|
|
70
|
+
this.name = new.target.name;
|
|
71
|
+
Error.captureStackTrace(this, new.target);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var isAuthSecurityError = (error) => {
|
|
75
|
+
return error instanceof AuthSecurityError;
|
|
76
|
+
};
|
|
90
77
|
|
|
91
78
|
// src/utils.ts
|
|
92
79
|
var toSnakeCase = (str) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
96
|
-
.toLowerCase()
|
|
97
|
-
.replace(/^_+/, "")
|
|
98
|
-
}
|
|
80
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
|
|
81
|
+
};
|
|
99
82
|
var toUpperCase = (str) => {
|
|
100
|
-
|
|
101
|
-
}
|
|
83
|
+
return str.toUpperCase();
|
|
84
|
+
};
|
|
102
85
|
var toCastCase = (obj, type = "snake") => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
86
|
+
return Object.entries(obj).reduce((previous, [key, value]) => {
|
|
87
|
+
const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
|
|
88
|
+
return { ...previous, [newKey]: value };
|
|
89
|
+
}, {});
|
|
90
|
+
};
|
|
108
91
|
var equals = (a, b) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
var sanitizeURL = (
|
|
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()
|
|
92
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
93
|
+
return a === b;
|
|
94
|
+
};
|
|
95
|
+
var sanitizeURL = (url) => {
|
|
96
|
+
try {
|
|
97
|
+
let decodedURL = decodeURIComponent(url).trim();
|
|
98
|
+
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
|
|
99
|
+
let protocol = "";
|
|
100
|
+
let rest = decodedURL;
|
|
101
|
+
if (protocolMatch) {
|
|
102
|
+
protocol = protocolMatch[1];
|
|
103
|
+
rest = decodedURL.slice(protocol.length);
|
|
104
|
+
const slashIndex = rest.indexOf("/");
|
|
105
|
+
if (slashIndex === -1) {
|
|
106
|
+
return protocol + rest;
|
|
107
|
+
}
|
|
108
|
+
const domain = rest.slice(0, slashIndex);
|
|
109
|
+
let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
110
|
+
if (path !== "/" && path.endsWith("/")) {
|
|
111
|
+
path = path.replace(/\/+$/, "/");
|
|
112
|
+
} else if (path !== "/") {
|
|
113
|
+
path = path.replace(/\/+$/, "");
|
|
114
|
+
}
|
|
115
|
+
return protocol + domain + path;
|
|
152
116
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
url2.search = ""
|
|
159
|
-
return `${url2.origin}${url2.pathname}`
|
|
160
|
-
} catch {
|
|
161
|
-
return sanitizeURL(path)
|
|
117
|
+
let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
118
|
+
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
119
|
+
sanitized = sanitized.replace(/\/+$/, "/");
|
|
120
|
+
} else if (sanitized !== "/") {
|
|
121
|
+
sanitized = sanitized.replace(/\/+$/, "");
|
|
162
122
|
}
|
|
163
|
-
|
|
123
|
+
return sanitized;
|
|
124
|
+
} catch {
|
|
125
|
+
return url.trim();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var getNormalizedOriginPath = (path) => {
|
|
129
|
+
try {
|
|
130
|
+
const url = new URL(path);
|
|
131
|
+
url.hash = "";
|
|
132
|
+
url.search = "";
|
|
133
|
+
return `${url.origin}${url.pathname}`;
|
|
134
|
+
} catch {
|
|
135
|
+
return sanitizeURL(path);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var formatZodError = (error) => {
|
|
139
|
+
if (!error.issues || error.issues.length === 0) {
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
return error.issues.reduce((previous, issue) => {
|
|
143
|
+
const key = issue.path.join(".");
|
|
144
|
+
return {
|
|
145
|
+
...previous,
|
|
146
|
+
[key]: {
|
|
147
|
+
code: issue.code,
|
|
148
|
+
message: issue.message
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}, {});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/assert.ts
|
|
155
|
+
var isValidURL = (value) => {
|
|
156
|
+
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
|
|
157
|
+
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
|
|
158
|
+
return regex.test(value);
|
|
159
|
+
};
|
|
164
160
|
|
|
165
161
|
// src/secure.ts
|
|
166
162
|
var generateSecure = (length = 32) => {
|
|
167
|
-
|
|
168
|
-
}
|
|
163
|
+
return import_crypto.default.randomBytes(length).toString("base64url");
|
|
164
|
+
};
|
|
169
165
|
var createHash = (data, base = "hex") => {
|
|
170
|
-
|
|
171
|
-
}
|
|
166
|
+
return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
|
|
167
|
+
};
|
|
172
168
|
var createPKCE = async (verifier) => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/cookie.ts
|
|
179
|
-
var import_cookie = require("cookie")
|
|
180
|
-
|
|
181
|
-
// src/assert.ts
|
|
182
|
-
var isValidURL = (value) => {
|
|
183
|
-
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false
|
|
184
|
-
const regex =
|
|
185
|
-
/^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
|
|
186
|
-
return regex.test(value)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// src/cookie.ts
|
|
190
|
-
var import_cookie2 = require("cookie")
|
|
191
|
-
var COOKIE_NAME = "aura-auth"
|
|
192
|
-
var defaultCookieOptions = {
|
|
193
|
-
httpOnly: true,
|
|
194
|
-
sameSite: "lax",
|
|
195
|
-
path: "/",
|
|
196
|
-
maxAge: 60 * 60 * 24 * 15,
|
|
197
|
-
}
|
|
198
|
-
var defaultStandardCookieConfig = {
|
|
199
|
-
secure: false,
|
|
200
|
-
httpOnly: true,
|
|
201
|
-
prefix: "",
|
|
202
|
-
}
|
|
203
|
-
var defaultSecureCookieConfig = {
|
|
204
|
-
secure: true,
|
|
205
|
-
prefix: "__Secure-",
|
|
206
|
-
}
|
|
207
|
-
var defaultHostCookieConfig = {
|
|
208
|
-
secure: true,
|
|
209
|
-
prefix: "__Host-",
|
|
210
|
-
path: "/",
|
|
211
|
-
domain: void 0,
|
|
212
|
-
}
|
|
213
|
-
var expiredCookieOptions = {
|
|
214
|
-
...defaultCookieOptions,
|
|
215
|
-
expires: /* @__PURE__ */ new Date(0),
|
|
216
|
-
maxAge: 0,
|
|
217
|
-
}
|
|
218
|
-
var defineDefaultCookieOptions = (options2) => {
|
|
219
|
-
return {
|
|
220
|
-
name: options2?.name ?? COOKIE_NAME,
|
|
221
|
-
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
222
|
-
...defaultCookieOptions,
|
|
223
|
-
...options2,
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
var setCookie = (cookieName, value, options2) => {
|
|
227
|
-
const { prefix, name } = defineDefaultCookieOptions(options2)
|
|
228
|
-
const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`
|
|
229
|
-
return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
|
|
230
|
-
...defaultCookieOptions,
|
|
231
|
-
...options2,
|
|
232
|
-
})
|
|
233
|
-
}
|
|
234
|
-
var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
|
|
235
|
-
const name = cookieOptions.name ?? COOKIE_NAME
|
|
236
|
-
const isSecure = trustedProxyHeaders
|
|
237
|
-
? request.url.startsWith("https://") ||
|
|
238
|
-
request.headers.get("X-Forwarded-Proto") === "https" ||
|
|
239
|
-
request.headers.get("Forwarded")?.includes("proto=https")
|
|
240
|
-
: request.url.startsWith("https://")
|
|
241
|
-
if (!cookieOptions.options?.httpOnly) {
|
|
242
|
-
console.warn(
|
|
243
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
244
|
-
)
|
|
245
|
-
}
|
|
246
|
-
if (cookieOptions.options?.domain === "*") {
|
|
247
|
-
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.")
|
|
248
|
-
}
|
|
249
|
-
if (!isSecure) {
|
|
250
|
-
const options2 = cookieOptions.options
|
|
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
|
-
}
|
|
269
|
-
}
|
|
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
|
-
return {
|
|
281
|
-
...options2,
|
|
282
|
-
secure: options2.secure,
|
|
283
|
-
httpOnly: options2.httpOnly,
|
|
284
|
-
maxAge: 5 * 60,
|
|
285
|
-
expires: new Date(Date.now() + 5 * 60 * 1e3),
|
|
286
|
-
}
|
|
287
|
-
}
|
|
169
|
+
const codeVerifier = verifier ?? generateSecure(86);
|
|
170
|
+
const codeChallenge = createHash(codeVerifier, "base64url");
|
|
171
|
+
return { codeVerifier, codeChallenge, method: "S256" };
|
|
172
|
+
};
|
|
288
173
|
|
|
289
174
|
// src/schemas.ts
|
|
290
|
-
var
|
|
291
|
-
var OAuthProviderConfigSchema = (0,
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
})
|
|
175
|
+
var import_zod = require("zod");
|
|
176
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
177
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
178
|
+
accessToken: (0, import_zod.string)().url(),
|
|
179
|
+
scope: (0, import_zod.string)().optional(),
|
|
180
|
+
userInfo: (0, import_zod.string)().url(),
|
|
181
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
182
|
+
clientId: (0, import_zod.string)(),
|
|
183
|
+
clientSecret: (0, import_zod.string)()
|
|
184
|
+
});
|
|
300
185
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
})
|
|
306
|
-
var OAuthAuthorizationResponse = (0,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
})
|
|
310
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
})
|
|
186
|
+
redirectURI: (0, import_zod.string)(),
|
|
187
|
+
state: (0, import_zod.string)(),
|
|
188
|
+
codeChallenge: (0, import_zod.string)(),
|
|
189
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
190
|
+
});
|
|
191
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
192
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
193
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
194
|
+
});
|
|
195
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
196
|
+
error: (0, import_zod.enum)([
|
|
197
|
+
"invalid_request",
|
|
198
|
+
"unauthorized_client",
|
|
199
|
+
"access_denied",
|
|
200
|
+
"unsupported_response_type",
|
|
201
|
+
"invalid_scope",
|
|
202
|
+
"server_error",
|
|
203
|
+
"temporarily_unavailable"
|
|
204
|
+
]),
|
|
205
|
+
error_description: (0, import_zod.string)().optional(),
|
|
206
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
207
|
+
state: (0, import_zod.string)()
|
|
208
|
+
});
|
|
324
209
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
})
|
|
329
|
-
var OAuthAccessTokenResponse = (0,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
})
|
|
336
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
})
|
|
348
|
-
var OAuthErrorResponse = (0,
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
})
|
|
210
|
+
redirectURI: (0, import_zod.string)(),
|
|
211
|
+
code: (0, import_zod.string)(),
|
|
212
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
213
|
+
});
|
|
214
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
215
|
+
access_token: (0, import_zod.string)(),
|
|
216
|
+
token_type: (0, import_zod.string)().optional(),
|
|
217
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
218
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
219
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
220
|
+
});
|
|
221
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
222
|
+
error: (0, import_zod.enum)([
|
|
223
|
+
"invalid_request",
|
|
224
|
+
"invalid_client",
|
|
225
|
+
"invalid_grant",
|
|
226
|
+
"unauthorized_client",
|
|
227
|
+
"unsupported_grant_type",
|
|
228
|
+
"invalid_scope"
|
|
229
|
+
]),
|
|
230
|
+
error_description: (0, import_zod.string)().optional(),
|
|
231
|
+
error_uri: (0, import_zod.string)().optional()
|
|
232
|
+
});
|
|
233
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
234
|
+
error: (0, import_zod.string)(),
|
|
235
|
+
error_description: (0, import_zod.string)().optional()
|
|
236
|
+
});
|
|
237
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
238
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
239
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
240
|
+
});
|
|
352
241
|
|
|
353
242
|
// src/actions/signIn/authorization.ts
|
|
354
243
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
244
|
+
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
245
|
+
if (!parsed.success) {
|
|
246
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
247
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
248
|
+
}
|
|
249
|
+
const { authorizeURL, ...options2 } = parsed.data;
|
|
250
|
+
const { userInfo, accessToken, clientSecret, ...required } = options2;
|
|
251
|
+
const searchParams = new URLSearchParams(toCastCase(required));
|
|
252
|
+
return `${authorizeURL}?${searchParams}`;
|
|
253
|
+
};
|
|
364
254
|
var getOriginURL = (request, trustedProxyHeaders) => {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
} else {
|
|
375
|
-
return new URL(getNormalizedOriginPath(request.url))
|
|
376
|
-
}
|
|
377
|
-
}
|
|
255
|
+
const headers = request.headers;
|
|
256
|
+
if (trustedProxyHeaders) {
|
|
257
|
+
const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
|
|
258
|
+
const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
|
|
259
|
+
return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
|
|
260
|
+
} else {
|
|
261
|
+
return new URL(getNormalizedOriginPath(request.url));
|
|
262
|
+
}
|
|
263
|
+
};
|
|
378
264
|
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
265
|
+
const url = getOriginURL(request, trustedProxyHeaders);
|
|
266
|
+
return `${url.origin}${basePath}/callback/${oauth}`;
|
|
267
|
+
};
|
|
382
268
|
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
|
-
|
|
416
|
-
|
|
417
|
-
if (isAuthError(error)) {
|
|
418
|
-
throw error
|
|
419
|
-
}
|
|
420
|
-
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
269
|
+
try {
|
|
270
|
+
const headers = request.headers;
|
|
271
|
+
const origin = headers.get("Origin");
|
|
272
|
+
const referer = headers.get("Referer");
|
|
273
|
+
let hostedURL = getOriginURL(request, trustedProxyHeaders);
|
|
274
|
+
if (redirectTo) {
|
|
275
|
+
if (redirectTo.startsWith("/")) {
|
|
276
|
+
return sanitizeURL(redirectTo);
|
|
277
|
+
}
|
|
278
|
+
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
279
|
+
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
280
|
+
throw new AuthSecurityError(
|
|
281
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
282
|
+
"The redirectTo parameter does not match the hosted origin."
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
return sanitizeURL(redirectToURL.pathname);
|
|
286
|
+
}
|
|
287
|
+
if (referer) {
|
|
288
|
+
const refererURL = new URL(sanitizeURL(referer));
|
|
289
|
+
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
290
|
+
throw new AuthSecurityError(
|
|
291
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
292
|
+
"The referer of the request does not match the hosted origin."
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
return sanitizeURL(refererURL.pathname);
|
|
296
|
+
}
|
|
297
|
+
if (origin) {
|
|
298
|
+
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
299
|
+
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
300
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
301
|
+
}
|
|
302
|
+
return sanitizeURL(originURL.pathname);
|
|
421
303
|
}
|
|
422
|
-
|
|
304
|
+
return "/";
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (isAuthSecurityError(error)) {
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
310
|
+
}
|
|
311
|
+
};
|
|
423
312
|
|
|
424
313
|
// src/actions/signIn/signIn.ts
|
|
425
314
|
var signInConfig = (oauth) => {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
315
|
+
return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
|
|
316
|
+
schemas: {
|
|
317
|
+
params: import_zod2.z.object({
|
|
318
|
+
oauth: import_zod2.z.enum(
|
|
319
|
+
Object.keys(oauth),
|
|
320
|
+
"The OAuth provider is not supported or invalid."
|
|
321
|
+
)
|
|
322
|
+
}),
|
|
323
|
+
searchParams: import_zod2.z.object({
|
|
324
|
+
redirectTo: import_zod2.z.string().optional()
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
};
|
|
435
329
|
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
|
-
headers.append("Set-Cookie", redirectToCookie)
|
|
464
|
-
headers.append("Set-Cookie", codeVerifierCookie)
|
|
465
|
-
return Response.json(
|
|
466
|
-
{ oauth: oauth2 },
|
|
467
|
-
{
|
|
468
|
-
status: 302,
|
|
469
|
-
headers,
|
|
470
|
-
}
|
|
471
|
-
)
|
|
472
|
-
} catch (error) {
|
|
473
|
-
if (isAuthError(error)) {
|
|
474
|
-
const { type, message } = error
|
|
475
|
-
return AuraResponse.json(
|
|
476
|
-
{ error: type, error_description: message },
|
|
477
|
-
{ status: import_router2.statusCode.BAD_REQUEST }
|
|
478
|
-
)
|
|
479
|
-
}
|
|
480
|
-
return AuraResponse.json(
|
|
481
|
-
{
|
|
482
|
-
error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
|
|
483
|
-
error_description: "An unexpected error occurred",
|
|
484
|
-
},
|
|
485
|
-
{ status: import_router2.statusCode.INTERNAL_SERVER_ERROR }
|
|
486
|
-
)
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
signInConfig(oauth)
|
|
490
|
-
)
|
|
491
|
-
}
|
|
330
|
+
return (0, import_router2.createEndpoint)(
|
|
331
|
+
"GET",
|
|
332
|
+
"/signIn/:oauth",
|
|
333
|
+
async (ctx) => {
|
|
334
|
+
const {
|
|
335
|
+
request,
|
|
336
|
+
params: { oauth: oauth2 },
|
|
337
|
+
searchParams: { redirectTo },
|
|
338
|
+
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
339
|
+
} = ctx;
|
|
340
|
+
const state = generateSecure();
|
|
341
|
+
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
|
|
342
|
+
const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
|
|
343
|
+
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
344
|
+
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
345
|
+
const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirectURI.name, redirectURI, cookies.redirectURI.attributes).setCookie(cookies.redirectTo.name, redirectToValue, cookies.redirectTo.attributes).setCookie(cookies.codeVerifier.name, codeVerifier, cookies.codeVerifier.attributes).toHeaders();
|
|
346
|
+
return Response.json(
|
|
347
|
+
{ oauth: oauth2 },
|
|
348
|
+
{
|
|
349
|
+
status: 302,
|
|
350
|
+
headers
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
},
|
|
354
|
+
signInConfig(oauth)
|
|
355
|
+
);
|
|
356
|
+
};
|
|
492
357
|
// Annotate the CommonJS export names for ESM import in node:
|
|
493
|
-
0 &&
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
})
|
|
358
|
+
0 && (module.exports = {
|
|
359
|
+
signInAction
|
|
360
|
+
});
|