@aura-stack/auth 0.4.0-rc.5 → 0.5.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.d.ts +8 -3
- package/dist/@types/router.d.cjs +0 -17
- package/dist/@types/router.d.d.ts +7 -2
- package/dist/@types/router.d.js +0 -1
- package/dist/actions/callback/access-token.cjs +130 -71
- package/dist/actions/callback/access-token.d.ts +9 -4
- package/dist/actions/callback/access-token.js +3 -4
- package/dist/actions/callback/callback.cjs +428 -152
- package/dist/actions/callback/callback.d.ts +11 -3
- package/dist/actions/callback/callback.js +12 -10
- package/dist/actions/callback/userinfo.cjs +159 -65
- package/dist/actions/callback/userinfo.d.ts +8 -3
- package/dist/actions/callback/userinfo.js +7 -6
- package/dist/actions/csrfToken/csrfToken.cjs +70 -19
- package/dist/actions/csrfToken/csrfToken.js +8 -7
- package/dist/actions/index.cjs +780 -348
- package/dist/actions/index.d.ts +6 -2
- package/dist/actions/index.js +23 -18
- package/dist/actions/session/session.cjs +107 -26
- package/dist/actions/session/session.js +7 -5
- package/dist/actions/signIn/authorization-url.cjs +288 -0
- package/dist/actions/signIn/authorization-url.d.ts +31 -0
- package/dist/actions/signIn/authorization-url.js +16 -0
- package/dist/actions/signIn/authorization.cjs +209 -211
- package/dist/actions/signIn/authorization.d.ts +32 -21
- package/dist/actions/signIn/authorization.js +12 -9
- package/dist/actions/signIn/signIn.cjs +470 -235
- package/dist/actions/signIn/signIn.d.ts +12 -3
- package/dist/actions/signIn/signIn.js +11 -8
- package/dist/actions/signOut/signOut.cjs +376 -228
- package/dist/actions/signOut/signOut.d.ts +1 -1
- package/dist/actions/signOut/signOut.js +10 -9
- package/dist/api/createApi.cjs +750 -0
- package/dist/api/createApi.d.ts +12 -0
- package/dist/api/createApi.js +19 -0
- package/dist/api/getSession.cjs +141 -0
- package/dist/api/getSession.d.ts +16 -0
- package/dist/api/getSession.js +10 -0
- package/dist/api/signIn.cjs +549 -0
- package/dist/api/signIn.d.ts +26 -0
- package/dist/api/signIn.js +15 -0
- package/dist/api/signOut.cjs +279 -0
- package/dist/api/signOut.d.ts +16 -0
- package/dist/api/signOut.js +13 -0
- package/dist/assert.cjs +150 -5
- package/dist/assert.d.ts +26 -3
- package/dist/assert.js +17 -3
- package/dist/{chunk-YRCB5FLE.js → chunk-2A5B7GWR.js} +52 -6
- package/dist/chunk-2GQLSIJ2.js +40 -0
- package/dist/chunk-2IR674WX.js +44 -0
- package/dist/chunk-3J5TUH2I.js +50 -0
- package/dist/chunk-4RWSYUKX.js +98 -0
- package/dist/chunk-4YHJ4IEQ.js +25 -0
- package/dist/chunk-54CZPKR4.js +25 -0
- package/dist/chunk-5LZ7TOM3.js +25 -0
- package/dist/chunk-7BE46WWS.js +88 -0
- package/dist/chunk-7YYXFKLR.js +35 -0
- package/dist/chunk-C3A37LQC.js +33 -0
- package/dist/chunk-CITNGXDA.js +31 -0
- package/dist/chunk-CWX724AG.js +78 -0
- package/dist/chunk-D2CSIUKP.js +74 -0
- package/dist/chunk-E6G5YCI6.js +25 -0
- package/dist/chunk-EBAMFRB7.js +34 -0
- package/dist/chunk-EEE7UM5T.js +25 -0
- package/dist/{chunk-HT4YLL7N.js → chunk-FPCVZUVG.js} +10 -8
- package/dist/chunk-FW4W3REU.js +25 -0
- package/dist/chunk-GNNBM2WJ.js +83 -0
- package/dist/chunk-IPKO6UQN.js +25 -0
- package/dist/chunk-JOCGX3RP.js +59 -0
- package/dist/chunk-KBXWTD6E.js +94 -0
- package/dist/chunk-KMMAZFSJ.js +25 -0
- package/dist/chunk-LATR3NIV.js +117 -0
- package/dist/chunk-LAYPUDQF.js +39 -0
- package/dist/chunk-LDU7A2JE.js +25 -0
- package/dist/chunk-LX3TJ2TJ.js +294 -0
- package/dist/chunk-NHZBQNRR.js +143 -0
- package/dist/chunk-OVHNRULD.js +33 -0
- package/dist/chunk-PDP3PHB3.js +127 -0
- package/dist/chunk-PHYNROD4.js +47 -0
- package/dist/chunk-QQEKY4XP.js +29 -0
- package/dist/chunk-U4RK4LKJ.js +348 -0
- package/dist/{chunk-RRLIF4PQ.js → chunk-U5663F2U.js} +16 -1
- package/dist/chunk-UN7X6SU5.js +53 -0
- package/dist/chunk-UZQJJD6A.js +100 -0
- package/dist/chunk-V6LLEAR4.js +80 -0
- package/dist/chunk-WHNDRO3N.js +50 -0
- package/dist/{chunk-W6LG7BFW.js → chunk-XY5R3EHH.js} +30 -23
- package/dist/client/client.cjs +135 -0
- package/dist/client/client.d.ts +85 -0
- package/dist/client/client.js +9 -0
- package/dist/client/index.cjs +135 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.js +10 -0
- package/dist/context.cjs +1237 -0
- package/dist/context.d.ts +16 -0
- package/dist/context.js +28 -0
- package/dist/cookie.cjs +57 -22
- package/dist/cookie.d.ts +11 -6
- package/dist/cookie.js +3 -2
- package/dist/createAuth.cjs +2320 -0
- package/dist/createAuth.d.ts +12 -0
- package/dist/createAuth.js +48 -0
- package/dist/env.cjs +78 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +12 -0
- package/dist/errors.cjs +17 -0
- package/dist/errors.d.ts +15 -4
- package/dist/errors.js +5 -1
- package/dist/headers.cjs +28 -2
- package/dist/headers.d.ts +25 -1
- package/dist/headers.js +9 -3
- package/dist/index-_aXtxb_s.d.ts +1377 -0
- package/dist/index.cjs +1843 -610
- package/dist/index.d.ts +11 -92
- package/dist/index.js +53 -85
- package/dist/jose.cjs +113 -38
- package/dist/jose.d.ts +12 -23
- package/dist/jose.js +17 -7
- package/dist/logger.cjs +424 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.js +17 -0
- package/dist/oauth/atlassian.cjs +57 -0
- package/dist/oauth/atlassian.d.ts +12 -0
- package/dist/oauth/atlassian.js +6 -0
- package/dist/oauth/bitbucket.cjs +19 -15
- package/dist/oauth/bitbucket.d.ts +7 -2
- package/dist/oauth/bitbucket.js +1 -1
- package/dist/oauth/discord.cjs +27 -24
- package/dist/oauth/discord.d.ts +7 -2
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/dropbox.cjs +53 -0
- package/dist/oauth/dropbox.d.ts +12 -0
- package/dist/oauth/dropbox.js +6 -0
- package/dist/oauth/figma.cjs +19 -16
- package/dist/oauth/figma.d.ts +7 -2
- package/dist/oauth/figma.js +1 -1
- package/dist/oauth/github.cjs +19 -8
- package/dist/oauth/github.d.ts +7 -2
- package/dist/oauth/github.js +1 -1
- package/dist/oauth/gitlab.cjs +19 -16
- package/dist/oauth/gitlab.d.ts +7 -2
- package/dist/oauth/gitlab.js +1 -1
- package/dist/oauth/index.cjs +529 -239
- package/dist/oauth/index.d.ts +7 -2
- package/dist/oauth/index.js +39 -22
- package/dist/oauth/mailchimp.cjs +19 -16
- package/dist/oauth/mailchimp.d.ts +7 -2
- package/dist/oauth/mailchimp.js +1 -1
- package/dist/oauth/notion.cjs +131 -0
- package/dist/oauth/notion.d.ts +12 -0
- package/dist/oauth/notion.js +9 -0
- package/dist/oauth/pinterest.cjs +19 -16
- package/dist/oauth/pinterest.d.ts +7 -2
- package/dist/oauth/pinterest.js +1 -1
- package/dist/oauth/spotify.cjs +19 -16
- package/dist/oauth/spotify.d.ts +7 -2
- package/dist/oauth/spotify.js +1 -1
- package/dist/oauth/strava.cjs +19 -16
- package/dist/oauth/strava.d.ts +7 -2
- package/dist/oauth/strava.js +1 -1
- package/dist/oauth/twitch.cjs +95 -0
- package/dist/oauth/twitch.d.ts +12 -0
- package/dist/oauth/twitch.js +7 -0
- package/dist/oauth/x.cjs +19 -16
- package/dist/oauth/x.d.ts +7 -2
- package/dist/oauth/x.js +1 -1
- package/dist/schemas.cjs +89 -42
- package/dist/schemas.d.ts +114 -18
- package/dist/schemas.js +5 -3
- package/dist/secure.cjs +73 -31
- package/dist/secure.d.ts +11 -11
- package/dist/secure.js +7 -6
- package/dist/utils.cjs +203 -90
- package/dist/utils.d.ts +21 -40
- package/dist/utils.js +21 -12
- package/package.json +9 -6
- package/dist/chunk-3EUWD5BB.js +0 -63
- package/dist/chunk-42XB3YCW.js +0 -22
- package/dist/chunk-6R2YZ4AC.js +0 -22
- package/dist/chunk-A3N4PVAT.js +0 -70
- package/dist/chunk-B737EUJV.js +0 -22
- package/dist/chunk-CXLATHS5.js +0 -143
- package/dist/chunk-E3OXBRYF.js +0 -22
- package/dist/chunk-EIL2FPSS.js +0 -22
- package/dist/chunk-EMKJA2GJ.js +0 -89
- package/dist/chunk-FIPU4MLT.js +0 -21
- package/dist/chunk-FKRDCWBF.js +0 -22
- package/dist/chunk-GA2SMTJO.js +0 -58
- package/dist/chunk-HP34YGGJ.js +0 -22
- package/dist/chunk-IKHPGFCW.js +0 -14
- package/dist/chunk-IUYZQTJV.js +0 -30
- package/dist/chunk-IVET23KF.js +0 -58
- package/dist/chunk-JVFTCTTE.js +0 -33
- package/dist/chunk-KRNOMBXQ.js +0 -22
- package/dist/chunk-KSWLO5ZU.js +0 -102
- package/dist/chunk-N2APGLXA.js +0 -71
- package/dist/chunk-N4SX7TZT.js +0 -96
- package/dist/chunk-STHEPPUZ.js +0 -11
- package/dist/chunk-TLE4PXY3.js +0 -39
- package/dist/index-B8jeIElf.d.ts +0 -679
- /package/dist/{chunk-DIVDFNAP.js → chunk-5X7JZMEF.js} +0 -0
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/actions/callback/callback.ts
|
|
@@ -33,12 +23,9 @@ __export(callback_exports, {
|
|
|
33
23
|
callbackAction: () => callbackAction
|
|
34
24
|
});
|
|
35
25
|
module.exports = __toCommonJS(callback_exports);
|
|
36
|
-
var
|
|
26
|
+
var import_v42 = require("zod/v4");
|
|
37
27
|
var import_router2 = require("@aura-stack/router");
|
|
38
28
|
|
|
39
|
-
// src/secure.ts
|
|
40
|
-
var import_crypto = __toESM(require("crypto"), 1);
|
|
41
|
-
|
|
42
29
|
// src/utils.ts
|
|
43
30
|
var import_router = require("@aura-stack/router");
|
|
44
31
|
|
|
@@ -82,77 +69,164 @@ var isOAuthProtocolError = (error) => {
|
|
|
82
69
|
return error instanceof OAuthProtocolError;
|
|
83
70
|
};
|
|
84
71
|
|
|
85
|
-
// src/
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (protocolMatch) {
|
|
97
|
-
protocol = protocolMatch[1];
|
|
98
|
-
rest = decodedURL.slice(protocol.length);
|
|
99
|
-
const slashIndex = rest.indexOf("/");
|
|
100
|
-
if (slashIndex === -1) {
|
|
101
|
-
return protocol + rest;
|
|
72
|
+
// src/env.ts
|
|
73
|
+
var import_meta = {};
|
|
74
|
+
var env = new Proxy({}, {
|
|
75
|
+
get(_, prop) {
|
|
76
|
+
if (typeof prop !== "string") return void 0;
|
|
77
|
+
const hasProperty = (process2) => {
|
|
78
|
+
return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
|
|
79
|
+
};
|
|
80
|
+
try {
|
|
81
|
+
if (typeof process !== "undefined" && hasProperty(process.env)) {
|
|
82
|
+
return process.env[prop];
|
|
102
83
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (path !== "/" && path.endsWith("/")) {
|
|
106
|
-
path = path.replace(/\/+$/, "/");
|
|
107
|
-
} else if (path !== "/") {
|
|
108
|
-
path = path.replace(/\/+$/, "");
|
|
84
|
+
if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
|
|
85
|
+
return import_meta.env[prop];
|
|
109
86
|
}
|
|
110
|
-
|
|
87
|
+
if (typeof Deno !== "undefined" && Deno.env?.get) {
|
|
88
|
+
return Deno.env.get(prop);
|
|
89
|
+
}
|
|
90
|
+
if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
|
|
91
|
+
return Bun.env[prop];
|
|
92
|
+
}
|
|
93
|
+
const globalValue = globalThis[prop];
|
|
94
|
+
return typeof globalValue === "string" ? globalValue : void 0;
|
|
95
|
+
} catch {
|
|
96
|
+
return void 0;
|
|
111
97
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
var getEnv = (key) => {
|
|
101
|
+
const keys = [`AURA_AUTH_${key.toUpperCase()}`, `AURA_${key.toUpperCase()}`, `AUTH_${key.toUpperCase()}`, key.toUpperCase()];
|
|
102
|
+
return env[keys.find((k) => env[k]) ?? ""];
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/assert.ts
|
|
106
|
+
var import_crypto = require("@aura-stack/jose/crypto");
|
|
107
|
+
var unsafeChars = [
|
|
108
|
+
"<",
|
|
109
|
+
">",
|
|
110
|
+
'"',
|
|
111
|
+
"`",
|
|
112
|
+
" ",
|
|
113
|
+
"\r",
|
|
114
|
+
"\n",
|
|
115
|
+
" ",
|
|
116
|
+
"\\",
|
|
117
|
+
"%2F",
|
|
118
|
+
"%5C",
|
|
119
|
+
"%2f",
|
|
120
|
+
"%5c",
|
|
121
|
+
"\r\n",
|
|
122
|
+
"%0A",
|
|
123
|
+
"%0D",
|
|
124
|
+
"%0a",
|
|
125
|
+
"%0d",
|
|
126
|
+
"..",
|
|
127
|
+
"//",
|
|
128
|
+
"///",
|
|
129
|
+
"...",
|
|
130
|
+
"%20",
|
|
131
|
+
"\0"
|
|
132
|
+
];
|
|
133
|
+
var isValidURL = (value) => {
|
|
134
|
+
if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
const match = value.match(/^(https?:\/\/)(.*)$/);
|
|
138
|
+
if (!match) return false;
|
|
139
|
+
const rest = match[2];
|
|
140
|
+
for (const char of unsafeChars) {
|
|
141
|
+
if (rest.includes(char)) return false;
|
|
142
|
+
}
|
|
143
|
+
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
|
|
144
|
+
return regex.test(match[0]);
|
|
145
|
+
};
|
|
146
|
+
var isRelativeURL = (value) => {
|
|
147
|
+
if (value.length > 100) return false;
|
|
148
|
+
for (const char of unsafeChars) {
|
|
149
|
+
if (value.includes(char)) return false;
|
|
150
|
+
}
|
|
151
|
+
const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
|
|
152
|
+
return regex.test(value);
|
|
153
|
+
};
|
|
154
|
+
var isSameOrigin = (origin, expected) => {
|
|
155
|
+
const originURL = new URL(origin);
|
|
156
|
+
const expectedURL = new URL(expected);
|
|
157
|
+
return equals(originURL.origin, expectedURL.origin);
|
|
158
|
+
};
|
|
159
|
+
var patternToRegex = (pattern) => {
|
|
160
|
+
try {
|
|
161
|
+
if (pattern.length > 2048) return null;
|
|
162
|
+
pattern = pattern.replace(/\\/g, "");
|
|
163
|
+
const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
|
|
164
|
+
if (!match) return null;
|
|
165
|
+
const [, protocol, host, port] = match;
|
|
166
|
+
const hasWildcard = host.includes("*");
|
|
167
|
+
if (hasWildcard && !host.startsWith("*.")) return null;
|
|
168
|
+
if (hasWildcard && host.slice(2).includes("*")) return null;
|
|
169
|
+
const domain = hasWildcard ? host.slice(2) : host;
|
|
170
|
+
const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
171
|
+
const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
|
|
172
|
+
const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
|
|
173
|
+
return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var isTrustedOrigin = (url, trustedOrigins) => {
|
|
179
|
+
if (!isValidURL(url) || trustedOrigins.length === 0) return false;
|
|
180
|
+
try {
|
|
181
|
+
const urlOrigin = new URL(url).origin;
|
|
182
|
+
for (const pattern of trustedOrigins) {
|
|
183
|
+
const regex = patternToRegex(pattern);
|
|
184
|
+
if (regex?.test(urlOrigin)) return true;
|
|
185
|
+
try {
|
|
186
|
+
if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
117
189
|
}
|
|
118
|
-
return sanitized;
|
|
119
190
|
} catch {
|
|
120
|
-
return url.trim();
|
|
121
191
|
}
|
|
192
|
+
return false;
|
|
122
193
|
};
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
131
|
-
var formatZodError = (error) => {
|
|
132
|
-
if (!error.issues || error.issues.length === 0) {
|
|
133
|
-
return {};
|
|
194
|
+
var timingSafeEqual = (a, b) => {
|
|
195
|
+
const bufferA = import_crypto.encoder.encode(a);
|
|
196
|
+
const bufferB = import_crypto.encoder.encode(b);
|
|
197
|
+
const len = Math.max(bufferA.length, bufferB.length);
|
|
198
|
+
let diff = 0;
|
|
199
|
+
for (let i = 0; i < len; i++) {
|
|
200
|
+
diff |= (bufferA[i] ?? 0) ^ (bufferB[i] ?? 0);
|
|
134
201
|
}
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
202
|
+
return diff === 0 && bufferA.length === bufferB.length;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/utils.ts
|
|
206
|
+
var AURA_AUTH_VERSION = "0.4.0";
|
|
207
|
+
var equals = (a, b) => {
|
|
208
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
209
|
+
return a === b;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// src/jose.ts
|
|
213
|
+
var import_jose = require("@aura-stack/jose");
|
|
214
|
+
var import_jose2 = require("@aura-stack/jose/jose");
|
|
215
|
+
var import_crypto2 = require("@aura-stack/jose/crypto");
|
|
216
|
+
var jwtVerificationOptions = {
|
|
217
|
+
algorithms: ["HS256"],
|
|
218
|
+
typ: "JWT"
|
|
145
219
|
};
|
|
146
220
|
|
|
147
221
|
// src/secure.ts
|
|
148
222
|
var generateSecure = (length = 32) => {
|
|
149
|
-
return
|
|
223
|
+
return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
|
|
150
224
|
};
|
|
151
225
|
var createCSRF = async (jose, csrfCookie) => {
|
|
152
226
|
try {
|
|
153
227
|
const token = generateSecure(32);
|
|
154
228
|
if (csrfCookie) {
|
|
155
|
-
await jose.verifyJWS(csrfCookie);
|
|
229
|
+
await jose.verifyJWS(csrfCookie, jwtVerificationOptions);
|
|
156
230
|
return csrfCookie;
|
|
157
231
|
}
|
|
158
232
|
return jose.signJWS({ token });
|
|
@@ -169,6 +243,26 @@ var cacheControl = {
|
|
|
169
243
|
Expires: "0",
|
|
170
244
|
Vary: "Cookie"
|
|
171
245
|
};
|
|
246
|
+
var contentSecurityPolicy = {
|
|
247
|
+
"Content-Security-Policy": [
|
|
248
|
+
"default-src 'none'",
|
|
249
|
+
"script-src 'self'",
|
|
250
|
+
"frame-src 'none'",
|
|
251
|
+
"object-src 'none'",
|
|
252
|
+
"frame-ancestors 'none'",
|
|
253
|
+
"base-uri 'none'"
|
|
254
|
+
].join("; ")
|
|
255
|
+
};
|
|
256
|
+
var secureHeaders = {
|
|
257
|
+
"X-Content-Type-Options": "nosniff",
|
|
258
|
+
"X-Frame-Options": "DENY",
|
|
259
|
+
"Referrer-Policy": "strict-origin-when-cross-origin"
|
|
260
|
+
};
|
|
261
|
+
var secureApiHeaders = {
|
|
262
|
+
...cacheControl,
|
|
263
|
+
...contentSecurityPolicy,
|
|
264
|
+
...secureHeaders
|
|
265
|
+
};
|
|
172
266
|
|
|
173
267
|
// src/request.ts
|
|
174
268
|
var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
|
|
@@ -182,28 +276,73 @@ var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
|
|
|
182
276
|
};
|
|
183
277
|
|
|
184
278
|
// src/schemas.ts
|
|
185
|
-
var
|
|
186
|
-
var
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
279
|
+
var import_v4 = require("zod/v4");
|
|
280
|
+
var AuthorizeConfigSchema = import_v4.z.union([
|
|
281
|
+
(0, import_v4.string)().url(),
|
|
282
|
+
(0, import_v4.object)({
|
|
283
|
+
url: (0, import_v4.string)().url(),
|
|
284
|
+
params: (0, import_v4.object)({
|
|
285
|
+
responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
|
|
286
|
+
scope: (0, import_v4.string)().optional()
|
|
287
|
+
})
|
|
288
|
+
})
|
|
289
|
+
]);
|
|
290
|
+
var AccessTokenConfigSchema = import_v4.z.union([
|
|
291
|
+
(0, import_v4.string)().url(),
|
|
292
|
+
(0, import_v4.object)({
|
|
293
|
+
url: (0, import_v4.string)().url(),
|
|
294
|
+
headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional()
|
|
295
|
+
})
|
|
296
|
+
]);
|
|
297
|
+
var UserInfoConfigSchema = import_v4.z.union([
|
|
298
|
+
(0, import_v4.string)().url(),
|
|
299
|
+
(0, import_v4.object)({
|
|
300
|
+
url: (0, import_v4.string)().url(),
|
|
301
|
+
headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional(),
|
|
302
|
+
method: (0, import_v4.string)().optional()
|
|
303
|
+
})
|
|
304
|
+
]);
|
|
305
|
+
var OAuthProviderCredentialsSchema = (0, import_v4.object)({
|
|
306
|
+
id: (0, import_v4.string)(),
|
|
307
|
+
name: (0, import_v4.string)(),
|
|
308
|
+
authorize: AuthorizeConfigSchema.optional(),
|
|
309
|
+
/** @deprecated */
|
|
310
|
+
authorizeURL: (0, import_v4.string)().url().optional(),
|
|
311
|
+
accessToken: AccessTokenConfigSchema,
|
|
312
|
+
/** @deprecated */
|
|
313
|
+
scope: (0, import_v4.string)().optional(),
|
|
314
|
+
userInfo: UserInfoConfigSchema,
|
|
315
|
+
/** @deprecated */
|
|
316
|
+
responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
|
|
317
|
+
clientId: (0, import_v4.string)(),
|
|
318
|
+
clientSecret: (0, import_v4.string)(),
|
|
319
|
+
profile: import_v4.z.function().optional()
|
|
320
|
+
});
|
|
321
|
+
var OAuthProviderConfigSchema = (0, import_v4.object)({
|
|
322
|
+
authorize: AuthorizeConfigSchema.optional(),
|
|
323
|
+
/** @deprecated */
|
|
324
|
+
authorizeURL: (0, import_v4.string)().url().optional(),
|
|
325
|
+
accessToken: AccessTokenConfigSchema,
|
|
326
|
+
/** @deprecated */
|
|
327
|
+
scope: (0, import_v4.string)().optional(),
|
|
328
|
+
userInfo: UserInfoConfigSchema,
|
|
329
|
+
/** @deprecated */
|
|
330
|
+
responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
|
|
331
|
+
clientId: (0, import_v4.string)(),
|
|
332
|
+
clientSecret: (0, import_v4.string)()
|
|
194
333
|
});
|
|
195
334
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
196
|
-
redirectURI: (0,
|
|
197
|
-
state: (0,
|
|
198
|
-
codeChallenge: (0,
|
|
199
|
-
codeChallengeMethod: (0,
|
|
335
|
+
redirectURI: (0, import_v4.string)(),
|
|
336
|
+
state: (0, import_v4.string)(),
|
|
337
|
+
codeChallenge: (0, import_v4.string)(),
|
|
338
|
+
codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
|
|
200
339
|
});
|
|
201
|
-
var OAuthAuthorizationResponse = (0,
|
|
202
|
-
state: (0,
|
|
203
|
-
code: (0,
|
|
340
|
+
var OAuthAuthorizationResponse = (0, import_v4.object)({
|
|
341
|
+
state: (0, import_v4.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
342
|
+
code: (0, import_v4.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
204
343
|
});
|
|
205
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
206
|
-
error: (0,
|
|
344
|
+
var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
345
|
+
error: (0, import_v4.enum)([
|
|
207
346
|
"invalid_request",
|
|
208
347
|
"unauthorized_client",
|
|
209
348
|
"access_denied",
|
|
@@ -212,24 +351,24 @@ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
|
212
351
|
"server_error",
|
|
213
352
|
"temporarily_unavailable"
|
|
214
353
|
]),
|
|
215
|
-
error_description: (0,
|
|
216
|
-
error_uri: (0,
|
|
217
|
-
state: (0,
|
|
354
|
+
error_description: (0, import_v4.string)().optional(),
|
|
355
|
+
error_uri: (0, import_v4.string)().optional(),
|
|
356
|
+
state: (0, import_v4.string)()
|
|
218
357
|
});
|
|
219
358
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
220
|
-
redirectURI: (0,
|
|
221
|
-
code: (0,
|
|
222
|
-
codeVerifier: (0,
|
|
359
|
+
redirectURI: (0, import_v4.string)(),
|
|
360
|
+
code: (0, import_v4.string)(),
|
|
361
|
+
codeVerifier: (0, import_v4.string)().min(43).max(128)
|
|
223
362
|
});
|
|
224
|
-
var OAuthAccessTokenResponse = (0,
|
|
225
|
-
access_token: (0,
|
|
226
|
-
token_type: (0,
|
|
227
|
-
expires_in: (0,
|
|
228
|
-
refresh_token: (0,
|
|
229
|
-
scope: (0,
|
|
363
|
+
var OAuthAccessTokenResponse = (0, import_v4.object)({
|
|
364
|
+
access_token: (0, import_v4.string)(),
|
|
365
|
+
token_type: (0, import_v4.string)().optional(),
|
|
366
|
+
expires_in: (0, import_v4.number)().optional(),
|
|
367
|
+
refresh_token: (0, import_v4.string)().optional(),
|
|
368
|
+
scope: (0, import_v4.union)([(0, import_v4.string)().optional().or((0, import_v4.null)()), (0, import_v4.array)((0, import_v4.string)()).optional()])
|
|
230
369
|
});
|
|
231
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
232
|
-
error: (0,
|
|
370
|
+
var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
371
|
+
error: (0, import_v4.enum)([
|
|
233
372
|
"invalid_request",
|
|
234
373
|
"invalid_client",
|
|
235
374
|
"invalid_grant",
|
|
@@ -237,16 +376,16 @@ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
|
237
376
|
"unsupported_grant_type",
|
|
238
377
|
"invalid_scope"
|
|
239
378
|
]),
|
|
240
|
-
error_description: (0,
|
|
241
|
-
error_uri: (0,
|
|
379
|
+
error_description: (0, import_v4.string)().optional(),
|
|
380
|
+
error_uri: (0, import_v4.string)().optional()
|
|
242
381
|
});
|
|
243
|
-
var OAuthErrorResponse = (0,
|
|
244
|
-
error: (0,
|
|
245
|
-
error_description: (0,
|
|
382
|
+
var OAuthErrorResponse = (0, import_v4.object)({
|
|
383
|
+
error: (0, import_v4.string)(),
|
|
384
|
+
error_description: (0, import_v4.string)().optional()
|
|
246
385
|
});
|
|
247
|
-
var OAuthEnvSchema = (0,
|
|
248
|
-
clientId:
|
|
249
|
-
clientSecret:
|
|
386
|
+
var OAuthEnvSchema = (0, import_v4.object)({
|
|
387
|
+
clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
388
|
+
clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
250
389
|
});
|
|
251
390
|
|
|
252
391
|
// src/actions/callback/userinfo.ts
|
|
@@ -259,71 +398,171 @@ var getDefaultUserInfo = (profile) => {
|
|
|
259
398
|
image: profile?.image ?? profile?.picture
|
|
260
399
|
};
|
|
261
400
|
};
|
|
262
|
-
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
263
|
-
const
|
|
401
|
+
var getUserInfo = async (oauthConfig, accessToken, logger) => {
|
|
402
|
+
const userInfoConfig = oauthConfig.userInfo;
|
|
403
|
+
const userinfoURL = typeof userInfoConfig === "string" ? userInfoConfig : userInfoConfig.url;
|
|
404
|
+
const extraHeaders = typeof userInfoConfig === "string" ? void 0 : userInfoConfig.headers;
|
|
405
|
+
const method = typeof userInfoConfig === "string" ? "GET" : (userInfoConfig.method ?? "GET").toUpperCase();
|
|
264
406
|
try {
|
|
265
|
-
|
|
266
|
-
|
|
407
|
+
logger?.log("OAUTH_USERINFO_REQUEST_INITIATED", {
|
|
408
|
+
structuredData: {
|
|
409
|
+
endpoint: userinfoURL
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
const response = await fetchAsync(userinfoURL, {
|
|
413
|
+
method,
|
|
267
414
|
headers: {
|
|
415
|
+
"User-Agent": `Aura Auth/${AURA_AUTH_VERSION}`,
|
|
268
416
|
Accept: "application/json",
|
|
269
|
-
Authorization: `Bearer ${accessToken}
|
|
417
|
+
Authorization: `Bearer ${accessToken}`,
|
|
418
|
+
...extraHeaders ?? {}
|
|
270
419
|
}
|
|
271
420
|
});
|
|
421
|
+
if (!response.ok) {
|
|
422
|
+
logger?.log("OAUTH_USERINFO_INVALID_RESPONSE");
|
|
423
|
+
throw new OAuthProtocolError("INVALID_REQUEST", "Invalid userinfo response format");
|
|
424
|
+
}
|
|
272
425
|
const json = await response.json();
|
|
273
426
|
const { success, data } = OAuthErrorResponse.safeParse(json);
|
|
274
427
|
if (success) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
428
|
+
logger?.log("OAUTH_USERINFO_ERROR", {
|
|
429
|
+
message: "Error response received from OAuth userinfo endpoint",
|
|
430
|
+
structuredData: {
|
|
431
|
+
error: data.error,
|
|
432
|
+
error_description: data.error_description ?? ""
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
throw new OAuthProtocolError("INVALID_REQUEST", "An error was received from the OAuth userinfo endpoint.");
|
|
279
436
|
}
|
|
437
|
+
logger?.log("OAUTH_USERINFO_SUCCESS");
|
|
280
438
|
return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
|
|
281
439
|
} catch (error) {
|
|
282
440
|
if (isOAuthProtocolError(error)) {
|
|
283
441
|
throw error;
|
|
284
442
|
}
|
|
443
|
+
logger?.log("OAUTH_USERINFO_REQUEST_FAILED");
|
|
285
444
|
if (isNativeError(error)) {
|
|
286
|
-
throw new OAuthProtocolError("
|
|
445
|
+
throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information from OAuth provider", "", {
|
|
446
|
+
cause: error
|
|
447
|
+
});
|
|
287
448
|
}
|
|
288
|
-
throw new OAuthProtocolError("
|
|
449
|
+
throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information", "", { cause: error });
|
|
289
450
|
}
|
|
290
451
|
};
|
|
291
452
|
|
|
453
|
+
// src/actions/signIn/authorization.ts
|
|
454
|
+
var getTrustedOrigins = async (request, trustedOrigins) => {
|
|
455
|
+
if (!trustedOrigins) return [];
|
|
456
|
+
const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
|
|
457
|
+
return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
|
|
458
|
+
};
|
|
459
|
+
var getBaseURL = async ({
|
|
460
|
+
ctx,
|
|
461
|
+
request,
|
|
462
|
+
headers: headersInit
|
|
463
|
+
}) => {
|
|
464
|
+
const origin = getEnv("BASE_URL") || ctx?.baseURL;
|
|
465
|
+
if (origin && origin !== "/") return origin;
|
|
466
|
+
if (ctx?.trustedProxyHeaders) {
|
|
467
|
+
const headers = headersInit && new Headers(headersInit) || request?.headers;
|
|
468
|
+
const protocol = headers?.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Proto") ?? "http";
|
|
469
|
+
const host = headers?.get("Host") ?? headers?.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Host") ?? null;
|
|
470
|
+
if (host) return `${protocol}://${host}`;
|
|
471
|
+
throw new AuthInternalError(
|
|
472
|
+
"INVALID_OAUTH_CONFIGURATION",
|
|
473
|
+
"The URL cannot be constructed. Please set the BASE_URL environment variable or provide trusted proxy host headers."
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
return new URL(request?.url ?? "not-found").origin;
|
|
478
|
+
} catch (error) {
|
|
479
|
+
throw new AuthInternalError(
|
|
480
|
+
"INVALID_OAUTH_CONFIGURATION",
|
|
481
|
+
"The URL cannot be constructed. Please set the BASE_URL environment variable or enable trustedProxyHeaders.",
|
|
482
|
+
{ cause: error }
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
var getOriginURL = async (request, context) => {
|
|
487
|
+
const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
|
|
488
|
+
trustedOrigins.push(new URL(request.url).origin);
|
|
489
|
+
const origin = await getBaseURL({ request, ctx: context });
|
|
490
|
+
if (!isTrustedOrigin(origin, trustedOrigins)) {
|
|
491
|
+
context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
|
|
492
|
+
throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
|
|
493
|
+
}
|
|
494
|
+
return origin;
|
|
495
|
+
};
|
|
496
|
+
|
|
292
497
|
// src/actions/callback/access-token.ts
|
|
293
|
-
var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
|
|
294
|
-
const
|
|
295
|
-
if (!
|
|
296
|
-
|
|
297
|
-
|
|
498
|
+
var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier, logger) => {
|
|
499
|
+
const { accessToken, clientId, clientSecret } = oauthConfig;
|
|
500
|
+
if (!clientId || !clientSecret || !redirectURI || !code || !codeVerifier || !accessToken) {
|
|
501
|
+
logger?.log("INVALID_OAUTH_CONFIGURATION", {
|
|
502
|
+
structuredData: {
|
|
503
|
+
has_client_id: Boolean(clientId),
|
|
504
|
+
has_client_secret: Boolean(clientSecret),
|
|
505
|
+
has_access_token: Boolean(accessToken),
|
|
506
|
+
has_redirect_uri: Boolean(redirectURI),
|
|
507
|
+
has_code: Boolean(code),
|
|
508
|
+
has_code_verifier: Boolean(codeVerifier)
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "The OAuth provider configuration is invalid.");
|
|
298
512
|
}
|
|
299
|
-
const
|
|
513
|
+
const tokenURL = typeof accessToken === "string" ? accessToken : accessToken.url;
|
|
514
|
+
const extraHeaders = typeof accessToken === "string" ? void 0 : accessToken.headers;
|
|
300
515
|
try {
|
|
301
|
-
|
|
516
|
+
logger?.log("OAUTH_ACCESS_TOKEN_REQUEST_INITIATED", {
|
|
517
|
+
structuredData: {
|
|
518
|
+
has_client_id: Boolean(clientId),
|
|
519
|
+
redirect_uri: redirectURI,
|
|
520
|
+
grant_type: "authorization_code"
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
const response = await fetchAsync(tokenURL, {
|
|
302
524
|
method: "POST",
|
|
303
525
|
headers: {
|
|
526
|
+
...extraHeaders ?? {},
|
|
304
527
|
Accept: "application/json",
|
|
305
528
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
306
529
|
},
|
|
307
530
|
body: new URLSearchParams({
|
|
308
531
|
client_id: clientId,
|
|
309
532
|
client_secret: clientSecret,
|
|
310
|
-
code
|
|
311
|
-
redirect_uri:
|
|
533
|
+
code,
|
|
534
|
+
redirect_uri: redirectURI,
|
|
312
535
|
grant_type: "authorization_code",
|
|
313
536
|
code_verifier: codeVerifier
|
|
314
537
|
}).toString()
|
|
315
538
|
});
|
|
539
|
+
if (!response.ok) {
|
|
540
|
+
logger?.log("INVALID_OAUTH_ACCESS_TOKEN_RESPONSE");
|
|
541
|
+
throw new OAuthProtocolError("invalid_request", "Invalid access token response");
|
|
542
|
+
}
|
|
316
543
|
const json = await response.json();
|
|
317
544
|
const token = OAuthAccessTokenResponse.safeParse(json);
|
|
318
545
|
if (!token.success) {
|
|
319
546
|
const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
|
|
320
547
|
if (!success) {
|
|
321
|
-
|
|
548
|
+
logger?.log("INVALID_OAUTH_ACCESS_TOKEN_RESPONSE");
|
|
549
|
+
throw new OAuthProtocolError("invalid_request", "Invalid access token response format");
|
|
322
550
|
}
|
|
323
|
-
|
|
551
|
+
logger?.log("OAUTH_ACCESS_TOKEN_ERROR", {
|
|
552
|
+
structuredData: {
|
|
553
|
+
error: data.error,
|
|
554
|
+
error_description: data.error_description ?? ""
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
throw new OAuthProtocolError("INVALID_ACCESS_TOKEN", "Failed to retrieve access token");
|
|
324
558
|
}
|
|
559
|
+
logger?.log("OAUTH_ACCESS_TOKEN_SUCCESS");
|
|
325
560
|
return token.data;
|
|
326
561
|
} catch (error) {
|
|
562
|
+
logger?.log("OAUTH_ACCESS_TOKEN_REQUEST_FAILED");
|
|
563
|
+
if (error instanceof Error) {
|
|
564
|
+
throw new OAuthProtocolError("server_error", "Failed to communicate with OAuth provider", "", { cause: error });
|
|
565
|
+
}
|
|
327
566
|
throw error;
|
|
328
567
|
}
|
|
329
568
|
};
|
|
@@ -345,10 +584,11 @@ var oauthCookieOptions = {
|
|
|
345
584
|
var expiredCookieAttributes = {
|
|
346
585
|
...defaultCookieOptions,
|
|
347
586
|
expires: /* @__PURE__ */ new Date(0),
|
|
348
|
-
maxAge: 0
|
|
587
|
+
maxAge: 0,
|
|
588
|
+
secure: true
|
|
349
589
|
};
|
|
350
590
|
var getCookie = (request, cookieName) => {
|
|
351
|
-
const cookies = request.headers.get("Cookie");
|
|
591
|
+
const cookies = request instanceof Request ? request.headers.get("Cookie") : request.get("Cookie");
|
|
352
592
|
if (!cookies) {
|
|
353
593
|
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
|
|
354
594
|
}
|
|
@@ -371,23 +611,36 @@ var createSessionCookie = async (jose, session) => {
|
|
|
371
611
|
var callbackConfig = (oauth) => {
|
|
372
612
|
return (0, import_router2.createEndpointConfig)("/callback/:oauth", {
|
|
373
613
|
schemas: {
|
|
374
|
-
params:
|
|
375
|
-
oauth:
|
|
614
|
+
params: import_v42.z.object({
|
|
615
|
+
oauth: import_v42.z.enum(
|
|
376
616
|
Object.keys(oauth),
|
|
377
617
|
"The OAuth provider is not supported or invalid."
|
|
378
618
|
)
|
|
379
619
|
}),
|
|
380
|
-
searchParams:
|
|
381
|
-
code:
|
|
382
|
-
state:
|
|
620
|
+
searchParams: import_v42.z.object({
|
|
621
|
+
code: import_v42.z.string("Missing code parameter in the OAuth authorization response."),
|
|
622
|
+
state: import_v42.z.string("Missing state parameter in the OAuth authorization response.")
|
|
383
623
|
})
|
|
384
624
|
},
|
|
385
|
-
|
|
625
|
+
use: [
|
|
386
626
|
(ctx) => {
|
|
387
|
-
const
|
|
627
|
+
const {
|
|
628
|
+
searchParams,
|
|
629
|
+
context: { logger }
|
|
630
|
+
} = ctx;
|
|
631
|
+
const response = OAuthAuthorizationErrorResponse.safeParse(searchParams);
|
|
388
632
|
if (response.success) {
|
|
389
633
|
const { error, error_description } = response.data;
|
|
390
|
-
|
|
634
|
+
const criticalAuthErrors = ["access_denied", "server_error"];
|
|
635
|
+
const severity = criticalAuthErrors.includes(error.toLowerCase()) ? "critical" : "warning";
|
|
636
|
+
logger?.log("OAUTH_AUTHORIZATION_ERROR", {
|
|
637
|
+
severity,
|
|
638
|
+
structuredData: {
|
|
639
|
+
error,
|
|
640
|
+
error_description: error_description ?? ""
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
throw new OAuthProtocolError(error, error_description || "OAuth Authorization Error");
|
|
391
644
|
}
|
|
392
645
|
return ctx;
|
|
393
646
|
}
|
|
@@ -403,31 +656,54 @@ var callbackAction = (oauth) => {
|
|
|
403
656
|
request,
|
|
404
657
|
params: { oauth: oauth2 },
|
|
405
658
|
searchParams: { code, state },
|
|
406
|
-
context
|
|
659
|
+
context
|
|
407
660
|
} = ctx;
|
|
661
|
+
const { oauth: providers, cookies, jose, logger, trustedOrigins } = context;
|
|
408
662
|
const oauthConfig = providers[oauth2];
|
|
409
663
|
const cookieState = getCookie(request, cookies.state.name);
|
|
664
|
+
const codeVerifier = getCookie(request, cookies.codeVerifier.name);
|
|
410
665
|
const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
|
|
411
666
|
const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
|
|
412
|
-
|
|
413
|
-
|
|
667
|
+
if (!timingSafeEqual(cookieState, state)) {
|
|
668
|
+
logger?.log("MISMATCHING_STATE", {
|
|
669
|
+
structuredData: {
|
|
670
|
+
oauth_provider: oauth2
|
|
671
|
+
}
|
|
672
|
+
});
|
|
414
673
|
throw new AuthSecurityError(
|
|
415
674
|
"MISMATCHING_STATE",
|
|
416
675
|
"The provided state passed in the OAuth response does not match the stored state."
|
|
417
676
|
);
|
|
418
677
|
}
|
|
419
|
-
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier);
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
678
|
+
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier, logger);
|
|
679
|
+
const origins = await getTrustedOrigins(request, trustedOrigins);
|
|
680
|
+
const requestOrigin = await getOriginURL(request, context);
|
|
681
|
+
if (!isRelativeURL(cookieRedirectTo)) {
|
|
682
|
+
const isValid = origins.length > 0 ? isTrustedOrigin(cookieRedirectTo, origins) : isSameOrigin(cookieRedirectTo, requestOrigin);
|
|
683
|
+
if (!isValid) {
|
|
684
|
+
logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", {
|
|
685
|
+
structuredData: {
|
|
686
|
+
redirect_path: cookieRedirectTo,
|
|
687
|
+
provider: oauth2,
|
|
688
|
+
has_trusted_origins: origins.length > 0,
|
|
689
|
+
request_origin: requestOrigin
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
throw new AuthSecurityError(
|
|
693
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
694
|
+
"Invalid redirect path. Potential open redirect attack detected."
|
|
695
|
+
);
|
|
696
|
+
}
|
|
426
697
|
}
|
|
427
|
-
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
698
|
+
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token, logger);
|
|
428
699
|
const sessionCookie = await createSessionCookie(jose, userInfo);
|
|
429
700
|
const csrfToken = await createCSRF(jose);
|
|
430
|
-
|
|
701
|
+
logger?.log("OAUTH_CALLBACK_SUCCESS", {
|
|
702
|
+
structuredData: {
|
|
703
|
+
provider: oauth2
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", cookieRedirectTo).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirectURI.name, "", expiredCookieAttributes).setCookie(cookies.redirectTo.name, "", expiredCookieAttributes).setCookie(cookies.codeVerifier.name, "", expiredCookieAttributes).toHeaders();
|
|
431
707
|
return Response.json({ oauth: oauth2 }, { status: 302, headers });
|
|
432
708
|
},
|
|
433
709
|
callbackConfig(oauth)
|