faire-auth 1.0.3 → 1.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/{adapter-factory-lKIOf2OR.mjs → adapter-factory-qPVW8x9-.mjs} +34 -36
- package/dist/{adapter-factory-D1I7joki.cjs → adapter-factory-u8r3oTez.cjs} +66 -68
- package/dist/adapters/drizzle-adapter/index.cjs +34 -40
- package/dist/adapters/drizzle-adapter/index.d.cts +4 -9
- package/dist/adapters/drizzle-adapter/index.d.mts +4 -9
- package/dist/adapters/drizzle-adapter/index.mjs +20 -26
- package/dist/adapters/index.cjs +11 -16
- package/dist/adapters/index.d.cts +11 -37
- package/dist/adapters/index.d.mts +11 -37
- package/dist/adapters/index.mjs +4 -13
- package/dist/adapters/kysely-adapter/index.cjs +270 -11
- package/dist/adapters/kysely-adapter/index.d.cts +9 -19
- package/dist/adapters/kysely-adapter/index.d.mts +9 -19
- package/dist/adapters/kysely-adapter/index.mjs +267 -9
- package/dist/adapters/memory-adapter/index.cjs +146 -9
- package/dist/adapters/memory-adapter/index.d.cts +4 -10
- package/dist/adapters/memory-adapter/index.d.mts +4 -10
- package/dist/adapters/memory-adapter/index.mjs +145 -9
- package/dist/adapters/mongodb-adapter/index.cjs +13 -21
- package/dist/adapters/mongodb-adapter/index.d.cts +3 -8
- package/dist/adapters/mongodb-adapter/index.d.mts +4 -9
- package/dist/adapters/mongodb-adapter/index.mjs +12 -20
- package/dist/adapters/prisma-adapter/index.cjs +12 -20
- package/dist/adapters/prisma-adapter/index.d.cts +4 -8
- package/dist/adapters/prisma-adapter/index.d.mts +4 -8
- package/dist/adapters/prisma-adapter/index.mjs +5 -13
- package/dist/adapters/test.cjs +86 -69
- package/dist/adapters/test.d.cts +7 -11
- package/dist/adapters/test.d.mts +7 -11
- package/dist/adapters/test.mjs +83 -66
- package/dist/api/index.cjs +3 -20
- package/dist/api/index.d.cts +2 -3
- package/dist/api/index.d.mts +2 -3
- package/dist/api/index.mjs +1 -20
- package/dist/api/middleware/index.cjs +4 -11
- package/dist/api/middleware/index.d.cts +3 -9
- package/dist/api/middleware/index.d.mts +3 -9
- package/dist/api/middleware/index.mjs +3 -11
- package/dist/{api-B4RDwBty.mjs → api-0f-F-Fi2.mjs} +292 -189
- package/dist/{api-CaRC1Gio.cjs → api-LjfH6hQi.cjs} +557 -452
- package/dist/{test-utils/bun-sqlite-dialect-BZBvHchL.cjs → bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
- package/dist/{test-utils/bun-sqlite-dialect-BSWhhKNs.mjs → bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
- package/dist/client/index.cjs +8 -15
- package/dist/client/index.d.cts +9 -14
- package/dist/client/index.d.mts +9 -14
- package/dist/client/index.mjs +7 -15
- package/dist/client/lynx/index.cjs +10 -18
- package/dist/client/lynx/index.d.cts +402 -71
- package/dist/client/lynx/index.d.mts +402 -71
- package/dist/client/lynx/index.mjs +5 -13
- package/dist/client/plugins/index.cjs +3 -5
- package/dist/client/plugins/index.d.cts +5 -10
- package/dist/client/plugins/index.d.mts +5 -10
- package/dist/client/plugins/index.mjs +2 -4
- package/dist/client/react/index.cjs +6 -14
- package/dist/client/react/index.d.cts +402 -71
- package/dist/client/react/index.d.mts +402 -71
- package/dist/client/react/index.mjs +5 -13
- package/dist/client/solid/index.cjs +6 -14
- package/dist/client/solid/index.d.cts +393 -57
- package/dist/client/solid/index.d.mts +393 -57
- package/dist/client/solid/index.mjs +5 -13
- package/dist/client/svelte/index.cjs +5 -10
- package/dist/client/svelte/index.d.cts +400 -67
- package/dist/client/svelte/index.d.mts +400 -67
- package/dist/client/svelte/index.mjs +4 -10
- package/dist/client/vue/index.cjs +6 -14
- package/dist/client/vue/index.d.cts +401 -68
- package/dist/client/vue/index.d.mts +401 -68
- package/dist/client/vue/index.mjs +5 -13
- package/dist/{cookies-BTs1o992.mjs → cookies-D9aY_gJh.mjs} +25 -21
- package/dist/{cookies-BTl72THv.cjs → cookies-DQ52rcOy.cjs} +119 -115
- package/dist/crypto/index.cjs +10 -8
- package/dist/crypto/index.d.cts +5 -13
- package/dist/crypto/index.d.mts +5 -13
- package/dist/crypto/index.mjs +2 -5
- package/dist/{crypto-DH2Aa7jN.mjs → crypto-BH-hD0lJ.mjs} +7 -10
- package/dist/{crypto-DpSCnrTp.cjs → crypto-BITfWVwD.cjs} +24 -27
- package/dist/db/index.cjs +1135 -29
- package/dist/db/index.d.cts +1 -2
- package/dist/db/index.d.mts +1 -2
- package/dist/db/index.mjs +1115 -16
- package/dist/defu-D2h4S3X-.mjs +87 -0
- package/dist/defu-DWS5RPWt.cjs +134 -0
- package/dist/{email-verification-DI_0H4JC.cjs → email-verification-DOPnSgbI.cjs} +65 -71
- package/dist/{email-verification-C_lBu_JY.mjs → email-verification-YSR5n5lb.mjs} +23 -29
- package/dist/{hono-CO-zsqI-.mjs → hono-BAV2wQkK.mjs} +16 -33
- package/dist/hono-SVQuc5Ru.mjs +4 -0
- package/dist/hono-pgK4H_U1.cjs +9 -0
- package/dist/{hono-DnW5crl1.cjs → hono-tyFFJFdS.cjs} +42 -60
- package/dist/index-B86Cy0dE.d.cts +2 -0
- package/dist/index-B86Cy0dE.d.mts +2 -0
- package/dist/index.cjs +115 -150
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +46 -81
- package/dist/integrations/next-js.cjs +5 -9
- package/dist/integrations/next-js.d.cts +6 -14
- package/dist/integrations/next-js.d.mts +6 -14
- package/dist/integrations/next-js.mjs +4 -9
- package/dist/integrations/node.cjs +16 -14
- package/dist/integrations/node.d.cts +6 -14
- package/dist/integrations/node.d.mts +6 -14
- package/dist/integrations/node.mjs +15 -13
- package/dist/integrations/react-start.cjs +7 -11
- package/dist/integrations/react-start.d.cts +5 -13
- package/dist/integrations/react-start.d.mts +5 -13
- package/dist/integrations/react-start.mjs +6 -11
- package/dist/integrations/solid-start.cjs +3 -5
- package/dist/integrations/solid-start.d.cts +2 -5
- package/dist/integrations/solid-start.d.mts +2 -5
- package/dist/integrations/solid-start.mjs +2 -4
- package/dist/integrations/svelte-kit.cjs +6 -10
- package/dist/integrations/svelte-kit.d.cts +11 -23
- package/dist/integrations/svelte-kit.d.mts +11 -23
- package/dist/integrations/svelte-kit.mjs +5 -10
- package/dist/{ip-BjNYspCH.mjs → ip-6Lv2o42m.mjs} +4 -9
- package/dist/{ip-C17Qdq-G.cjs → ip-DPydExzV.cjs} +21 -27
- package/dist/{json--tl7Grvs.cjs → json-D3aq-nH2.cjs} +9 -13
- package/dist/{json-B1v2qRTQ.mjs → json-DooGMtnJ.mjs} +2 -5
- package/dist/{logged-CyGfp8_H.mjs → logged-B83SzMnJ.mjs} +6 -10
- package/dist/{logged-Dv3st5qc.cjs → logged-BIpCpnVY.cjs} +13 -18
- package/dist/{middleware-CE6OhDkq.mjs → middleware-Cakg4e1D.mjs} +2 -4
- package/dist/{middleware-CWvRH4EW.cjs → middleware-Cd-VkNxB.cjs} +17 -20
- package/dist/{node-sqlite-dialect-w4DAg0PH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
- package/dist/{test-utils/node-sqlite-dialect-BgJqjBOu.cjs → node-sqlite-dialect-D3QPFROH.cjs} +5 -9
- package/dist/oauth2/index.cjs +166 -22
- package/dist/oauth2/index.d.cts +5 -17
- package/dist/oauth2/index.d.mts +5 -17
- package/dist/oauth2/index.mjs +156 -16
- package/dist/{origin-check-DjLTuZQ8.cjs → origin-check-BflGhEEN.cjs} +34 -38
- package/dist/{origin-check-8Gajklvh.mjs → origin-check-CRgs1M7k.mjs} +13 -16
- package/dist/{parser-B25ylT5u.mjs → parser-CqwvpF6l.cjs} +12 -10
- package/dist/{parser-B_wxvaAr.cjs → parser-DcKDjjHO.mjs} +7 -22
- package/dist/plugins/access/index.cjs +38 -4
- package/dist/plugins/access/index.d.cts +36 -2
- package/dist/plugins/access/index.d.mts +36 -2
- package/dist/plugins/access/index.mjs +36 -3
- package/dist/plugins/bearer/index.cjs +52 -7
- package/dist/plugins/bearer/index.d.cts +27 -4
- package/dist/plugins/bearer/index.d.mts +27 -4
- package/dist/plugins/bearer/index.mjs +51 -7
- package/dist/plugins/index.cjs +1385 -842
- package/dist/plugins/index.d.cts +489 -7566
- package/dist/plugins/index.d.mts +489 -7566
- package/dist/plugins/index.mjs +1118 -576
- package/dist/plugins/passkey/index.cjs +551 -15
- package/dist/plugins/passkey/index.d.cts +123 -4
- package/dist/plugins/passkey/index.d.mts +123 -4
- package/dist/plugins/passkey/index.mjs +547 -15
- package/dist/{chunk-BFnQceUY.mjs → rolldown-runtime-BKpuH2hG.mjs} +6 -7
- package/dist/{chunk-fPmz2rbM.cjs → rolldown-runtime-C_Pgydhf.cjs} +22 -24
- package/dist/{schema-DTIwLLmf.mjs → schema-CFCpv0tK.mjs} +3 -6
- package/dist/{schema-CirKflVs.cjs → schema-b-lKhMkG.cjs} +51 -55
- package/dist/{session-CM3rmOYF.mjs → session-BGjJgihS.mjs} +51 -74
- package/dist/{session-Cwrj4GfV.cjs → session-CzZSMmQC.cjs} +197 -219
- package/dist/shared.d.cts +1581 -0
- package/dist/shared.d.mts +1581 -0
- package/dist/social-providers/index.cjs +9 -9
- package/dist/social-providers/index.d.cts +1 -1
- package/dist/social-providers/index.d.mts +1 -1
- package/dist/social-providers/index.mjs +3 -5
- package/dist/social-providers-CjPww-qf.mjs +6 -0
- package/dist/social-providers-D7w_7Ym8.cjs +10 -0
- package/dist/{state-CvSihlVT.cjs → state-2OrNjOO-.cjs} +24 -24
- package/dist/{state-CQghgH9I.mjs → state-Dooeisfq.mjs} +17 -17
- package/dist/{bun-sqlite-dialect-DPgTzc0w.cjs → test-utils/bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
- package/dist/{bun-sqlite-dialect-6NqeV3px.mjs → test-utils/bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
- package/dist/test-utils/index.cjs +8831 -7941
- package/dist/test-utils/index.d.cts +310 -12440
- package/dist/test-utils/index.d.mts +313 -12440
- package/dist/test-utils/index.mjs +8591 -7701
- package/dist/test-utils/{node-sqlite-dialect-DAQXiobH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
- package/dist/{node-sqlite-dialect-DP11CB0y.cjs → test-utils/node-sqlite-dialect-D3QPFROH.cjs} +5 -9
- package/dist/types/index.d.cts +2 -3
- package/dist/types/index.d.mts +2 -3
- package/dist/types/index.mjs +1 -1
- package/dist/{url-BoUuoIwZ.mjs → url-CJtdrrUu.mjs} +12 -13
- package/dist/{url-Ce7CVaQD.cjs → url-DjCmCUHS.cjs} +42 -44
- package/dist/utils/cookies.cjs +29 -30
- package/dist/utils/cookies.d.cts +21 -25
- package/dist/utils/cookies.d.mts +20 -24
- package/dist/utils/cookies.mjs +2 -7
- package/dist/utils-C7OHyfHa.mjs +4 -0
- package/dist/utils-iX0Vy_UL.cjs +3 -0
- package/package.json +40 -30
- package/dist/access-BZ7-AbTM.cjs +0 -51
- package/dist/access-D0DRqUKC.mjs +0 -39
- package/dist/bearer-DDzrp5M7.cjs +0 -60
- package/dist/bearer-WZcs7gxL.mjs +0 -54
- package/dist/db-4tUsQJXd.mjs +0 -1119
- package/dist/db-ChMbb_U-.cjs +0 -1180
- package/dist/defu-BmOYq4PU.cjs +0 -34
- package/dist/defu-D9ZTXqlo.mjs +0 -28
- package/dist/hono-C14rpOEa.cjs +0 -13
- package/dist/hono-CoKYWnXA.mjs +0 -7
- package/dist/hono-D0VqxVy1.d.mts +0 -18
- package/dist/hono-DOM31WQz.d.cts +0 -18
- package/dist/index-BCTFWP_o.d.mts +0 -992
- package/dist/index-BDhhaE6Y.d.cts +0 -3
- package/dist/index-BVRfQy6L.d.mts +0 -992
- package/dist/index-Baarsq5J.d.mts +0 -33
- package/dist/index-By364WbF.d.cts +0 -992
- package/dist/index-BzWwMgxr.d.cts +0 -992
- package/dist/index-CF9iq55a.d.mts +0 -3
- package/dist/index-CJD2yB-W.d.cts +0 -33
- package/dist/index-CRt_fppq.d.mts +0 -41
- package/dist/index-CdLyn7qP.d.cts +0 -41
- package/dist/index-CsWF3f7U.d.cts +0 -13350
- package/dist/index-CzidsAyA.d.mts +0 -13350
- package/dist/index-DvW-GCcI.d.cts +0 -33
- package/dist/index-f-5OJ9yV.d.cts +0 -13350
- package/dist/index-rFv8Hxld.d.mts +0 -13350
- package/dist/index-ztVZPQdV.d.mts +0 -33
- package/dist/kysely-adapter-CtIdoHa8.mjs +0 -270
- package/dist/kysely-adapter-QZTx077T.cjs +0 -288
- package/dist/memory-adapter-17RZd5df.cjs +0 -154
- package/dist/memory-adapter-Dp4XdCZK.mjs +0 -148
- package/dist/oauth2-5RL4cVNS.cjs +0 -177
- package/dist/oauth2-C56wz-n9.mjs +0 -159
- package/dist/passkey-BTT-v5c-.cjs +0 -512
- package/dist/passkey-CzY_W2us.mjs +0 -505
- package/dist/request-1NL_1lyJ.mjs +0 -58
- package/dist/request-CPNlp-DK.cjs +0 -100
- package/dist/social-providers-B8RK5yqI.mjs +0 -9
- package/dist/social-providers-BmFOIIPk.cjs +0 -13
- package/dist/utils-44aDDP8f.cjs +0 -2
- package/dist/utils-D4vZd1-9.mjs +0 -4
package/dist/{test-utils/node-sqlite-dialect-BgJqjBOu.cjs → node-sqlite-dialect-D3QPFROH.cjs}
RENAMED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
const require_index = require('./index.cjs');
|
|
2
1
|
let kysely = require("kysely");
|
|
3
|
-
|
|
4
|
-
//#region src/adapters/kysely-adapter/node-sqlite-dialect.ts
|
|
2
|
+
// src/adapters/kysely-adapter/node-sqlite-dialect.ts
|
|
5
3
|
var NodeSqliteAdapter = class {
|
|
6
4
|
get supportsCreateIfNotExists() {
|
|
7
5
|
return true;
|
|
@@ -57,8 +55,8 @@ var NodeSqliteConnection = class {
|
|
|
57
55
|
this.#db = db;
|
|
58
56
|
}
|
|
59
57
|
executeQuery(compiledQuery) {
|
|
60
|
-
const { sql
|
|
61
|
-
const rows = this.#db.prepare(sql
|
|
58
|
+
const { sql, parameters } = compiledQuery;
|
|
59
|
+
const rows = this.#db.prepare(sql).all(...parameters);
|
|
62
60
|
return Promise.resolve({ rows });
|
|
63
61
|
}
|
|
64
62
|
async *streamQuery() {
|
|
@@ -69,7 +67,7 @@ var ConnectionMutex = class {
|
|
|
69
67
|
#promise;
|
|
70
68
|
#resolve;
|
|
71
69
|
async lock() {
|
|
72
|
-
while (this.#promise) await this.#promise;
|
|
70
|
+
while (this.#promise !== void 0) await this.#promise;
|
|
73
71
|
this.#promise = new Promise((resolve) => {
|
|
74
72
|
this.#resolve = resolve;
|
|
75
73
|
});
|
|
@@ -151,6 +149,4 @@ var NodeSqliteDialect = class {
|
|
|
151
149
|
return new NodeSqliteIntrospector(db);
|
|
152
150
|
}
|
|
153
151
|
};
|
|
154
|
-
|
|
155
|
-
//#endregion
|
|
156
|
-
exports.NodeSqliteDialect = NodeSqliteDialect;
|
|
152
|
+
exports.NodeSqliteDialect = NodeSqliteDialect;
|
package/dist/oauth2/index.cjs
CHANGED
|
@@ -1,25 +1,169 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
require(
|
|
4
|
-
require(
|
|
5
|
-
require(
|
|
6
|
-
require(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_crypto = require("../crypto-BITfWVwD.cjs");
|
|
3
|
+
const require_state = require("../state-2OrNjOO-.cjs");
|
|
4
|
+
const require_email_verification = require("../email-verification-DOPnSgbI.cjs");
|
|
5
|
+
let _faire_auth_core_env = require("@faire-auth/core/env");
|
|
6
|
+
let _faire_auth_core_error = require("@faire-auth/core/error");
|
|
7
|
+
// src/oauth2/utils.ts
|
|
8
|
+
const decryptOAuthToken = (token, ctx, options) => {
|
|
9
|
+
if (!token) return token;
|
|
10
|
+
if (options.account?.encryptOAuthTokens) return (0, require_crypto.crypto_exports.symmetricDecrypt)({
|
|
11
|
+
key: ctx.get("context").secret,
|
|
12
|
+
data: token
|
|
13
|
+
});
|
|
14
|
+
return token;
|
|
15
|
+
};
|
|
16
|
+
const setTokenUtil = (token, ctx, options) => {
|
|
17
|
+
if (options.account?.encryptOAuthTokens && token) return (0, require_crypto.crypto_exports.symmetricEncrypt)({
|
|
18
|
+
key: ctx.get("context").secret,
|
|
19
|
+
data: token
|
|
20
|
+
});
|
|
21
|
+
return token;
|
|
22
|
+
};
|
|
23
|
+
// src/oauth2/link-account.ts
|
|
24
|
+
const handleOAuthUserInfo = async (ctx, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }, options) => {
|
|
25
|
+
const context = ctx.get("context");
|
|
26
|
+
const redirectOnError = (reason) => {
|
|
27
|
+
const errorURL = options.onAPIError?.errorURL ?? `${context.baseURL}/error`;
|
|
28
|
+
return {
|
|
29
|
+
type: "redirect",
|
|
30
|
+
response: ctx.redirect(`${errorURL}?error=${reason}`, 302)
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const dbUser = await context.internalAdapter.findOAuthUser(userInfo.email.toLowerCase(), account.accountId, account.providerId).catch((e) => {
|
|
34
|
+
_faire_auth_core_env.logger.error("Better auth was unable to query your database.\nError: ", e);
|
|
35
|
+
return "error";
|
|
36
|
+
});
|
|
37
|
+
if (dbUser === "error") return redirectOnError("internal_server_error");
|
|
38
|
+
let user = dbUser?.user ?? null;
|
|
39
|
+
const isRegister = user == null;
|
|
40
|
+
if (dbUser) {
|
|
41
|
+
const hasBeenLinked = dbUser.accounts.find((a) => a.providerId === account.providerId && a.accountId === account.accountId);
|
|
42
|
+
if (!hasBeenLinked) {
|
|
43
|
+
if (!(options.account?.accountLinking?.trustedProviders)?.includes(account.providerId) && !userInfo.emailVerified || options.account?.accountLinking?.enabled === false) {
|
|
44
|
+
if ((0, _faire_auth_core_env.isDevelopment)()) _faire_auth_core_env.logger.warn(`User already exist but account isn't linked to ${account.providerId}. To read more about how account linking works in Faire Auth see https://www.faire-auth.com/docs/concepts/users-accounts#account-linking.`);
|
|
45
|
+
return {
|
|
46
|
+
type: "error",
|
|
47
|
+
reason: "account_not_linked"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await context.internalAdapter.linkAccount({
|
|
52
|
+
providerId: account.providerId,
|
|
53
|
+
accountId: userInfo.id.toString(),
|
|
54
|
+
userId: dbUser.user.id,
|
|
55
|
+
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
56
|
+
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
57
|
+
idToken: account.idToken,
|
|
58
|
+
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
59
|
+
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
60
|
+
scope: account.scope
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
_faire_auth_core_env.logger.error("Unable to link account", e);
|
|
64
|
+
return {
|
|
65
|
+
type: "error",
|
|
66
|
+
reason: "unable_to_link_account"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
70
|
+
} else {
|
|
71
|
+
if (options.account?.updateAccountOnSignIn !== false) {
|
|
72
|
+
const updateData = Object.fromEntries(Object.entries({
|
|
73
|
+
idToken: account.idToken,
|
|
74
|
+
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
75
|
+
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
76
|
+
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
77
|
+
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
78
|
+
scope: account.scope
|
|
79
|
+
}).filter(([, value]) => value !== void 0 && value !== ""));
|
|
80
|
+
if (Object.keys(updateData).length > 0) await context.internalAdapter.updateAccount(hasBeenLinked.id, updateData);
|
|
81
|
+
}
|
|
82
|
+
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
83
|
+
}
|
|
84
|
+
if (overrideUserInfo === true) {
|
|
85
|
+
const { id: _, ...restUserInfo } = userInfo;
|
|
86
|
+
await context.internalAdapter.updateUser(dbUser.user.id, {
|
|
87
|
+
...restUserInfo,
|
|
88
|
+
email: userInfo.email.toLowerCase(),
|
|
89
|
+
emailVerified: userInfo.email.toLowerCase() === dbUser.user.email ? dbUser.user.emailVerified || userInfo.emailVerified : userInfo.emailVerified
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (disableSignUp === true) return {
|
|
94
|
+
type: "error",
|
|
95
|
+
reason: "signup_disabled",
|
|
96
|
+
isRegister: false
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
const { id: _, ...restUserInfo } = userInfo;
|
|
100
|
+
user = await context.internalAdapter.createOAuthUser({
|
|
101
|
+
...restUserInfo,
|
|
102
|
+
email: userInfo.email.toLowerCase()
|
|
103
|
+
}, {
|
|
104
|
+
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
105
|
+
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
106
|
+
idToken: account.idToken,
|
|
107
|
+
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
108
|
+
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
109
|
+
scope: account.scope,
|
|
110
|
+
providerId: account.providerId,
|
|
111
|
+
accountId: userInfo.id.toString()
|
|
112
|
+
}).then((res) => res.user);
|
|
113
|
+
if (!userInfo.emailVerified && user && options.emailVerification?.sendOnSignUp === true) {
|
|
114
|
+
const token = await require_email_verification.createEmailVerificationToken(context.secret, user.email, void 0, options.emailVerification.expiresIn);
|
|
115
|
+
const url = `${context.baseURL}/verify-email?token=${token}${callbackURL ? `&callbackURL=${callbackURL}` : ""}`;
|
|
116
|
+
await options.emailVerification.sendVerificationEmail?.({
|
|
117
|
+
user,
|
|
118
|
+
url,
|
|
119
|
+
token
|
|
120
|
+
}, ctx);
|
|
121
|
+
}
|
|
122
|
+
} catch (e) {
|
|
123
|
+
_faire_auth_core_env.logger.error(e instanceof Error ? e.message : String(e), e);
|
|
124
|
+
if (e instanceof _faire_auth_core_error.APIError) return {
|
|
125
|
+
type: "error",
|
|
126
|
+
reason: e.message,
|
|
127
|
+
isRegister: false
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
type: "error",
|
|
131
|
+
reason: "unable_to_create_user",
|
|
132
|
+
isRegister: false
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!user) return {
|
|
137
|
+
type: "error",
|
|
138
|
+
reason: "unable_to_create_user",
|
|
139
|
+
isRegister: false
|
|
140
|
+
};
|
|
141
|
+
const session = await context.internalAdapter.createSession(user.id);
|
|
142
|
+
if (!session) return {
|
|
143
|
+
type: "error",
|
|
144
|
+
reason: "unable_to_create_session",
|
|
145
|
+
isRegister: false
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
type: "success",
|
|
149
|
+
data: {
|
|
150
|
+
session,
|
|
151
|
+
user
|
|
152
|
+
},
|
|
153
|
+
isRegister
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
exports.decryptOAuthToken = decryptOAuthToken;
|
|
15
157
|
exports.generateState = require_state.generateState;
|
|
16
|
-
exports.handleOAuthUserInfo =
|
|
158
|
+
exports.handleOAuthUserInfo = handleOAuthUserInfo;
|
|
17
159
|
exports.parseState = require_state.parseState;
|
|
18
|
-
exports.setTokenUtil =
|
|
19
|
-
var
|
|
20
|
-
Object.keys(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
160
|
+
exports.setTokenUtil = setTokenUtil;
|
|
161
|
+
var _faire_auth_core_oauth2 = require("@faire-auth/core/oauth2");
|
|
162
|
+
Object.keys(_faire_auth_core_oauth2).forEach(function(k) {
|
|
163
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
164
|
+
enumerable: true,
|
|
165
|
+
get: function() {
|
|
166
|
+
return _faire_auth_core_oauth2[k];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
25
169
|
});
|
package/dist/oauth2/index.d.cts
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as ContextVars } from "../hono-DOM31WQz.cjs";
|
|
1
|
+
import { P as ContextVars, ht as FaireAuthOptions$1, v as generateState, y as parseState } from "../shared.cjs";
|
|
3
2
|
import { ExK } from "@faire-auth/core/types";
|
|
4
3
|
import { Context, TypedResponse } from "hono";
|
|
5
4
|
import { Account, Session, User } from "@faire-auth/core/db";
|
|
6
5
|
export * from "@faire-auth/core/oauth2";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string>;
|
|
10
|
-
declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string> | null | undefined;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/oauth2/link-account.d.ts
|
|
6
|
+
export declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
|
|
7
|
+
export declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
|
|
13
8
|
type OAuthError = "account_not_linked" | "unable_to_link_account" | "unable_to_create_user" | "unable_to_create_session" | "internal_server_error" | "signup_disabled" | (string & {});
|
|
14
|
-
declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
|
|
15
|
-
userInfo,
|
|
16
|
-
account,
|
|
17
|
-
callbackURL,
|
|
18
|
-
disableSignUp,
|
|
19
|
-
overrideUserInfo
|
|
20
|
-
}: {
|
|
9
|
+
export declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }: {
|
|
21
10
|
userInfo: ExK<User, "createdAt" | "updatedAt">;
|
|
22
11
|
account: ExK<Account, "createdAt" | "id" | "updatedAt" | "userId">;
|
|
23
12
|
callbackURL?: string;
|
|
@@ -38,5 +27,4 @@ declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
|
|
|
38
27
|
reason: OAuthError;
|
|
39
28
|
isRegister?: false;
|
|
40
29
|
}>;
|
|
41
|
-
|
|
42
|
-
export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
|
|
30
|
+
export { generateState, parseState };
|
package/dist/oauth2/index.d.mts
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as ContextVars } from "../hono-D0VqxVy1.mjs";
|
|
1
|
+
import { A as generateState, gt as FaireAuthOptions$1, j as parseState, t as ContextVars } from "../shared.mjs";
|
|
3
2
|
import { Context, TypedResponse } from "hono";
|
|
4
3
|
import { Account, Session, User } from "@faire-auth/core/db";
|
|
5
4
|
import { ExK } from "@faire-auth/core/types";
|
|
6
5
|
export * from "@faire-auth/core/oauth2";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string>;
|
|
10
|
-
declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string> | null | undefined;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/oauth2/link-account.d.ts
|
|
6
|
+
export declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
|
|
7
|
+
export declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
|
|
13
8
|
type OAuthError = "account_not_linked" | "unable_to_link_account" | "unable_to_create_user" | "unable_to_create_session" | "internal_server_error" | "signup_disabled" | (string & {});
|
|
14
|
-
declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
|
|
15
|
-
userInfo,
|
|
16
|
-
account,
|
|
17
|
-
callbackURL,
|
|
18
|
-
disableSignUp,
|
|
19
|
-
overrideUserInfo
|
|
20
|
-
}: {
|
|
9
|
+
export declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }: {
|
|
21
10
|
userInfo: ExK<User, "createdAt" | "updatedAt">;
|
|
22
11
|
account: ExK<Account, "createdAt" | "id" | "updatedAt" | "userId">;
|
|
23
12
|
callbackURL?: string;
|
|
@@ -38,5 +27,4 @@ declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
|
|
|
38
27
|
reason: OAuthError;
|
|
39
28
|
isRegister?: false;
|
|
40
29
|
}>;
|
|
41
|
-
|
|
42
|
-
export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
|
|
30
|
+
export { generateState, parseState };
|
package/dist/oauth2/index.mjs
CHANGED
|
@@ -1,16 +1,156 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { n as crypto_exports } from "../crypto-BH-hD0lJ.mjs";
|
|
2
|
+
import { n as parseState, t as generateState } from "../state-Dooeisfq.mjs";
|
|
3
|
+
import { t as createEmailVerificationToken } from "../email-verification-YSR5n5lb.mjs";
|
|
4
|
+
import { isDevelopment, logger } from "@faire-auth/core/env";
|
|
5
|
+
import { APIError } from "@faire-auth/core/error";
|
|
6
|
+
export * from "@faire-auth/core/oauth2";
|
|
7
|
+
// src/oauth2/utils.ts
|
|
8
|
+
const decryptOAuthToken = (token, ctx, options) => {
|
|
9
|
+
if (!token) return token;
|
|
10
|
+
if (options.account?.encryptOAuthTokens) return (0, crypto_exports.symmetricDecrypt)({
|
|
11
|
+
key: ctx.get("context").secret,
|
|
12
|
+
data: token
|
|
13
|
+
});
|
|
14
|
+
return token;
|
|
15
|
+
};
|
|
16
|
+
const setTokenUtil = (token, ctx, options) => {
|
|
17
|
+
if (options.account?.encryptOAuthTokens && token) return (0, crypto_exports.symmetricEncrypt)({
|
|
18
|
+
key: ctx.get("context").secret,
|
|
19
|
+
data: token
|
|
20
|
+
});
|
|
21
|
+
return token;
|
|
22
|
+
};
|
|
23
|
+
// src/oauth2/link-account.ts
|
|
24
|
+
const handleOAuthUserInfo = async (ctx, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }, options) => {
|
|
25
|
+
const context = ctx.get("context");
|
|
26
|
+
const redirectOnError = (reason) => {
|
|
27
|
+
const errorURL = options.onAPIError?.errorURL ?? `${context.baseURL}/error`;
|
|
28
|
+
return {
|
|
29
|
+
type: "redirect",
|
|
30
|
+
response: ctx.redirect(`${errorURL}?error=${reason}`, 302)
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const dbUser = await context.internalAdapter.findOAuthUser(userInfo.email.toLowerCase(), account.accountId, account.providerId).catch((e) => {
|
|
34
|
+
logger.error("Better auth was unable to query your database.\nError: ", e);
|
|
35
|
+
return "error";
|
|
36
|
+
});
|
|
37
|
+
if (dbUser === "error") return redirectOnError("internal_server_error");
|
|
38
|
+
let user = dbUser?.user ?? null;
|
|
39
|
+
const isRegister = user == null;
|
|
40
|
+
if (dbUser) {
|
|
41
|
+
const hasBeenLinked = dbUser.accounts.find((a) => a.providerId === account.providerId && a.accountId === account.accountId);
|
|
42
|
+
if (!hasBeenLinked) {
|
|
43
|
+
if (!(options.account?.accountLinking?.trustedProviders)?.includes(account.providerId) && !userInfo.emailVerified || options.account?.accountLinking?.enabled === false) {
|
|
44
|
+
if (isDevelopment()) logger.warn(`User already exist but account isn't linked to ${account.providerId}. To read more about how account linking works in Faire Auth see https://www.faire-auth.com/docs/concepts/users-accounts#account-linking.`);
|
|
45
|
+
return {
|
|
46
|
+
type: "error",
|
|
47
|
+
reason: "account_not_linked"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await context.internalAdapter.linkAccount({
|
|
52
|
+
providerId: account.providerId,
|
|
53
|
+
accountId: userInfo.id.toString(),
|
|
54
|
+
userId: dbUser.user.id,
|
|
55
|
+
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
56
|
+
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
57
|
+
idToken: account.idToken,
|
|
58
|
+
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
59
|
+
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
60
|
+
scope: account.scope
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
logger.error("Unable to link account", e);
|
|
64
|
+
return {
|
|
65
|
+
type: "error",
|
|
66
|
+
reason: "unable_to_link_account"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
70
|
+
} else {
|
|
71
|
+
if (options.account?.updateAccountOnSignIn !== false) {
|
|
72
|
+
const updateData = Object.fromEntries(Object.entries({
|
|
73
|
+
idToken: account.idToken,
|
|
74
|
+
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
75
|
+
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
76
|
+
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
77
|
+
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
78
|
+
scope: account.scope
|
|
79
|
+
}).filter(([, value]) => value !== void 0 && value !== ""));
|
|
80
|
+
if (Object.keys(updateData).length > 0) await context.internalAdapter.updateAccount(hasBeenLinked.id, updateData);
|
|
81
|
+
}
|
|
82
|
+
if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
|
|
83
|
+
}
|
|
84
|
+
if (overrideUserInfo === true) {
|
|
85
|
+
const { id: _, ...restUserInfo } = userInfo;
|
|
86
|
+
await context.internalAdapter.updateUser(dbUser.user.id, {
|
|
87
|
+
...restUserInfo,
|
|
88
|
+
email: userInfo.email.toLowerCase(),
|
|
89
|
+
emailVerified: userInfo.email.toLowerCase() === dbUser.user.email ? dbUser.user.emailVerified || userInfo.emailVerified : userInfo.emailVerified
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (disableSignUp === true) return {
|
|
94
|
+
type: "error",
|
|
95
|
+
reason: "signup_disabled",
|
|
96
|
+
isRegister: false
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
const { id: _, ...restUserInfo } = userInfo;
|
|
100
|
+
user = await context.internalAdapter.createOAuthUser({
|
|
101
|
+
...restUserInfo,
|
|
102
|
+
email: userInfo.email.toLowerCase()
|
|
103
|
+
}, {
|
|
104
|
+
accessToken: await setTokenUtil(account.accessToken, ctx, options),
|
|
105
|
+
refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
|
|
106
|
+
idToken: account.idToken,
|
|
107
|
+
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
|
108
|
+
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
|
109
|
+
scope: account.scope,
|
|
110
|
+
providerId: account.providerId,
|
|
111
|
+
accountId: userInfo.id.toString()
|
|
112
|
+
}).then((res) => res.user);
|
|
113
|
+
if (!userInfo.emailVerified && user && options.emailVerification?.sendOnSignUp === true) {
|
|
114
|
+
const token = await createEmailVerificationToken(context.secret, user.email, void 0, options.emailVerification.expiresIn);
|
|
115
|
+
const url = `${context.baseURL}/verify-email?token=${token}${callbackURL ? `&callbackURL=${callbackURL}` : ""}`;
|
|
116
|
+
await options.emailVerification.sendVerificationEmail?.({
|
|
117
|
+
user,
|
|
118
|
+
url,
|
|
119
|
+
token
|
|
120
|
+
}, ctx);
|
|
121
|
+
}
|
|
122
|
+
} catch (e) {
|
|
123
|
+
logger.error(e instanceof Error ? e.message : String(e), e);
|
|
124
|
+
if (e instanceof APIError) return {
|
|
125
|
+
type: "error",
|
|
126
|
+
reason: e.message,
|
|
127
|
+
isRegister: false
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
type: "error",
|
|
131
|
+
reason: "unable_to_create_user",
|
|
132
|
+
isRegister: false
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!user) return {
|
|
137
|
+
type: "error",
|
|
138
|
+
reason: "unable_to_create_user",
|
|
139
|
+
isRegister: false
|
|
140
|
+
};
|
|
141
|
+
const session = await context.internalAdapter.createSession(user.id);
|
|
142
|
+
if (!session) return {
|
|
143
|
+
type: "error",
|
|
144
|
+
reason: "unable_to_create_session",
|
|
145
|
+
isRegister: false
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
type: "success",
|
|
149
|
+
data: {
|
|
150
|
+
session,
|
|
151
|
+
user
|
|
152
|
+
},
|
|
153
|
+
isRegister
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//#region src/utils/wildcard.ts
|
|
1
|
+
const require_url = require("./url-DjCmCUHS.cjs");
|
|
2
|
+
const require_middleware = require("./middleware-Cd-VkNxB.cjs");
|
|
3
|
+
let _faire_auth_core_env = require("@faire-auth/core/env");
|
|
4
|
+
let _faire_auth_core_static = require("@faire-auth/core/static");
|
|
5
|
+
// src/utils/wildcard.ts
|
|
8
6
|
/**
|
|
9
7
|
* Escapes a character if it has a special meaning in regular expressions
|
|
10
8
|
* and returns the character as is if it doesn't
|
|
@@ -51,9 +49,11 @@ const transform = (pattern, separator = true) => {
|
|
|
51
49
|
const nextSegment = segments[s + 1];
|
|
52
50
|
let currentSeparator = "";
|
|
53
51
|
if (segment == null && s > 0) continue;
|
|
54
|
-
if (truthySeparator)
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
if (truthySeparator) {
|
|
53
|
+
if (s === segments.length - 1) currentSeparator = optionalSeparator;
|
|
54
|
+
else if (nextSegment !== "**") currentSeparator = requiredSeparator;
|
|
55
|
+
else currentSeparator = "";
|
|
56
|
+
}
|
|
57
57
|
if (truthySeparator && segment === "**") {
|
|
58
58
|
if (currentSeparator) {
|
|
59
59
|
result += s === 0 ? "" : currentSeparator;
|
|
@@ -116,9 +116,7 @@ function wildcardMatch(pattern, options) {
|
|
|
116
116
|
fn.regexp = regexp;
|
|
117
117
|
return fn;
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
//#region src/api/middleware/origin-check.ts
|
|
119
|
+
// src/api/middleware/origin-check.ts
|
|
122
120
|
const RELATIVE_PATH_RE = /^\/(?!\/|\\|%2f|%5c)[\w\-.\+/@]*(?:\?[\w\-.\+/=&%@]*)?$/;
|
|
123
121
|
const matchesPattern = (url, pattern) => {
|
|
124
122
|
if (url.startsWith("/")) return false;
|
|
@@ -129,17 +127,17 @@ const matchesPattern = (url, pattern) => {
|
|
|
129
127
|
const protocol = require_url.getProtocol(url);
|
|
130
128
|
return protocol === "http:" || protocol === "https:" || !protocol ? pattern === require_url.getOrigin(url) : url.startsWith(pattern);
|
|
131
129
|
};
|
|
132
|
-
const validateURL = (url, label, trustedOrigins, logger
|
|
130
|
+
const validateURL = (url, label, trustedOrigins, logger, ctx) => {
|
|
133
131
|
if (url == null) return null;
|
|
134
132
|
let isTrustedOrigin = false;
|
|
135
133
|
trustedOrigins.forEach((origin) => {
|
|
136
134
|
if (isTrustedOrigin === false && (matchesPattern(url, origin) || url.startsWith("/") && label !== "origin" && RELATIVE_PATH_RE.test(url))) isTrustedOrigin = true;
|
|
137
135
|
});
|
|
138
136
|
if (!isTrustedOrigin) {
|
|
139
|
-
logger
|
|
140
|
-
logger
|
|
137
|
+
logger.error(`Invalid ${label}: ${url}`);
|
|
138
|
+
logger.info(`If it's a valid URL, please add ${url} to trustedOrigins in your auth config\n`, `Current list of trustedOrigins: ${[...trustedOrigins].join(", ")}`);
|
|
141
139
|
return ctx.json({
|
|
142
|
-
success:
|
|
140
|
+
success: _faire_auth_core_static.False,
|
|
143
141
|
message: `Invalid ${label}`
|
|
144
142
|
}, 403);
|
|
145
143
|
}
|
|
@@ -151,8 +149,8 @@ const validateURL = (url, label, trustedOrigins, logger$1, ctx) => {
|
|
|
151
149
|
*/
|
|
152
150
|
const initOriginCheckMiddleware = (options, context) => {
|
|
153
151
|
const log = {
|
|
154
|
-
info: (message, ...args) => options.logger?.log?.("info", message, ...args) ??
|
|
155
|
-
error: (message, ...args) => options.logger?.log?.("error", message, ...args) ??
|
|
152
|
+
info: (message, ...args) => options.logger?.log?.("info", message, ...args) ?? _faire_auth_core_env.logger.info,
|
|
153
|
+
error: (message, ...args) => options.logger?.log?.("error", message, ...args) ?? _faire_auth_core_env.logger.error
|
|
156
154
|
};
|
|
157
155
|
return require_middleware.createMiddleware()(async (ctx, next) => {
|
|
158
156
|
if (ctx.get("isServer") === true || ctx.req.method !== "POST") return await next();
|
|
@@ -213,7 +211,7 @@ const originCheck = (getValue) => {
|
|
|
213
211
|
if (ctx.get("isServer") === true) return await next();
|
|
214
212
|
const context = ctx.get("context");
|
|
215
213
|
let callbackURL = getValue(ctx);
|
|
216
|
-
if ((0,
|
|
214
|
+
if ((0, _faire_auth_core_static.isPromise)(callbackURL)) callbackURL = await callbackURL;
|
|
217
215
|
if (!callbackURL) return await next();
|
|
218
216
|
const callbacks = Array.isArray(callbackURL) ? callbackURL : [callbackURL];
|
|
219
217
|
let ret;
|
|
@@ -224,23 +222,21 @@ const originCheck = (getValue) => {
|
|
|
224
222
|
return await next();
|
|
225
223
|
});
|
|
226
224
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return initOriginCheckMiddleware;
|
|
233
|
-
}
|
|
225
|
+
Object.defineProperty(exports, "initOriginCheckMiddleware", {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
get: function() {
|
|
228
|
+
return initOriginCheckMiddleware;
|
|
229
|
+
}
|
|
234
230
|
});
|
|
235
|
-
Object.defineProperty(exports,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
231
|
+
Object.defineProperty(exports, "originCheck", {
|
|
232
|
+
enumerable: true,
|
|
233
|
+
get: function() {
|
|
234
|
+
return originCheck;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(exports, "wildcardMatch", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function() {
|
|
240
|
+
return wildcardMatch;
|
|
241
|
+
}
|
|
240
242
|
});
|
|
241
|
-
Object.defineProperty(exports, 'wildcardMatch', {
|
|
242
|
-
enumerable: true,
|
|
243
|
-
get: function () {
|
|
244
|
-
return wildcardMatch;
|
|
245
|
-
}
|
|
246
|
-
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { a as getTrustedOrigins, i as getProtocol, n as getHost, r as getOrigin } from "./url-
|
|
2
|
-
import { r as createMiddleware } from "./middleware-
|
|
1
|
+
import { a as getTrustedOrigins, i as getProtocol, n as getHost, r as getOrigin } from "./url-CJtdrrUu.mjs";
|
|
2
|
+
import { r as createMiddleware } from "./middleware-Cakg4e1D.mjs";
|
|
3
3
|
import { logger } from "@faire-auth/core/env";
|
|
4
4
|
import { False, isPromise } from "@faire-auth/core/static";
|
|
5
|
-
|
|
6
|
-
//#region src/utils/wildcard.ts
|
|
5
|
+
// src/utils/wildcard.ts
|
|
7
6
|
/**
|
|
8
7
|
* Escapes a character if it has a special meaning in regular expressions
|
|
9
8
|
* and returns the character as is if it doesn't
|
|
@@ -50,9 +49,11 @@ const transform = (pattern, separator = true) => {
|
|
|
50
49
|
const nextSegment = segments[s + 1];
|
|
51
50
|
let currentSeparator = "";
|
|
52
51
|
if (segment == null && s > 0) continue;
|
|
53
|
-
if (truthySeparator)
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
if (truthySeparator) {
|
|
53
|
+
if (s === segments.length - 1) currentSeparator = optionalSeparator;
|
|
54
|
+
else if (nextSegment !== "**") currentSeparator = requiredSeparator;
|
|
55
|
+
else currentSeparator = "";
|
|
56
|
+
}
|
|
56
57
|
if (truthySeparator && segment === "**") {
|
|
57
58
|
if (currentSeparator) {
|
|
58
59
|
result += s === 0 ? "" : currentSeparator;
|
|
@@ -115,9 +116,7 @@ function wildcardMatch(pattern, options) {
|
|
|
115
116
|
fn.regexp = regexp;
|
|
116
117
|
return fn;
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/api/middleware/origin-check.ts
|
|
119
|
+
// src/api/middleware/origin-check.ts
|
|
121
120
|
const RELATIVE_PATH_RE = /^\/(?!\/|\\|%2f|%5c)[\w\-.\+/@]*(?:\?[\w\-.\+/=&%@]*)?$/;
|
|
122
121
|
const matchesPattern = (url, pattern) => {
|
|
123
122
|
if (url.startsWith("/")) return false;
|
|
@@ -128,15 +127,15 @@ const matchesPattern = (url, pattern) => {
|
|
|
128
127
|
const protocol = getProtocol(url);
|
|
129
128
|
return protocol === "http:" || protocol === "https:" || !protocol ? pattern === getOrigin(url) : url.startsWith(pattern);
|
|
130
129
|
};
|
|
131
|
-
const validateURL = (url, label, trustedOrigins, logger
|
|
130
|
+
const validateURL = (url, label, trustedOrigins, logger, ctx) => {
|
|
132
131
|
if (url == null) return null;
|
|
133
132
|
let isTrustedOrigin = false;
|
|
134
133
|
trustedOrigins.forEach((origin) => {
|
|
135
134
|
if (isTrustedOrigin === false && (matchesPattern(url, origin) || url.startsWith("/") && label !== "origin" && RELATIVE_PATH_RE.test(url))) isTrustedOrigin = true;
|
|
136
135
|
});
|
|
137
136
|
if (!isTrustedOrigin) {
|
|
138
|
-
logger
|
|
139
|
-
logger
|
|
137
|
+
logger.error(`Invalid ${label}: ${url}`);
|
|
138
|
+
logger.info(`If it's a valid URL, please add ${url} to trustedOrigins in your auth config\n`, `Current list of trustedOrigins: ${[...trustedOrigins].join(", ")}`);
|
|
140
139
|
return ctx.json({
|
|
141
140
|
success: False,
|
|
142
141
|
message: `Invalid ${label}`
|
|
@@ -223,6 +222,4 @@ const originCheck = (getValue) => {
|
|
|
223
222
|
return await next();
|
|
224
223
|
});
|
|
225
224
|
};
|
|
226
|
-
|
|
227
|
-
//#endregion
|
|
228
|
-
export { originCheck as n, wildcardMatch as r, initOriginCheckMiddleware as t };
|
|
225
|
+
export { originCheck as n, wildcardMatch as r, initOriginCheckMiddleware as t };
|