@fonderie/auth 1.3.2 → 2.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/brain/signatures.md +1 -0
- package/dist/index.cjs +42 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -59
- package/dist/index.js.map +1 -1
- package/dist/middlewares/index.d.cts +1 -1
- package/dist/middlewares/index.d.ts +1 -1
- package/dist/{session-DbtCnbiG.d.cts → session-BoJjRB7t.d.cts} +6 -0
- package/dist/{session-DbtCnbiG.d.ts → session-BoJjRB7t.d.ts} +6 -0
- package/package.json +4 -4
package/brain/signatures.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -212,14 +212,19 @@ function tokenPairCookies(accessToken, refreshToken, config) {
|
|
|
212
212
|
return [
|
|
213
213
|
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/${secure}`,
|
|
214
214
|
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh${secure}`
|
|
215
|
-
]
|
|
215
|
+
];
|
|
216
216
|
}
|
|
217
217
|
function clearedTokenCookies(config) {
|
|
218
218
|
const secure = secureAttr(config);
|
|
219
219
|
return [
|
|
220
220
|
`access_token=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0${secure}`,
|
|
221
221
|
`refresh_token=; HttpOnly; SameSite=Strict; Path=/auth/refresh; Max-Age=0${secure}`
|
|
222
|
-
]
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
function cookieHeaders(cookies) {
|
|
225
|
+
const headers = new Headers();
|
|
226
|
+
for (const c of cookies) headers.append("Set-Cookie", c);
|
|
227
|
+
return headers;
|
|
223
228
|
}
|
|
224
229
|
|
|
225
230
|
// src/controllers/mfa.controller.ts
|
|
@@ -816,9 +821,7 @@ function mfaController(store, config, issuer, bus) {
|
|
|
816
821
|
},
|
|
817
822
|
{
|
|
818
823
|
status: 200,
|
|
819
|
-
headers:
|
|
820
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
821
|
-
}
|
|
824
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
822
825
|
}
|
|
823
826
|
);
|
|
824
827
|
},
|
|
@@ -1150,9 +1153,7 @@ function authController(store, config, bus) {
|
|
|
1150
1153
|
},
|
|
1151
1154
|
{
|
|
1152
1155
|
status: 201,
|
|
1153
|
-
headers:
|
|
1154
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1155
|
-
}
|
|
1156
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
1156
1157
|
}
|
|
1157
1158
|
);
|
|
1158
1159
|
}
|
|
@@ -1212,9 +1213,7 @@ function authController(store, config, bus) {
|
|
|
1212
1213
|
},
|
|
1213
1214
|
{
|
|
1214
1215
|
status: 202,
|
|
1215
|
-
headers:
|
|
1216
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1217
|
-
}
|
|
1216
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
1218
1217
|
}
|
|
1219
1218
|
);
|
|
1220
1219
|
}
|
|
@@ -1271,9 +1270,7 @@ function authController(store, config, bus) {
|
|
|
1271
1270
|
},
|
|
1272
1271
|
{
|
|
1273
1272
|
status: 200,
|
|
1274
|
-
headers:
|
|
1275
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1276
|
-
}
|
|
1273
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
1277
1274
|
}
|
|
1278
1275
|
);
|
|
1279
1276
|
}
|
|
@@ -1314,9 +1311,7 @@ function authController(store, config, bus) {
|
|
|
1314
1311
|
},
|
|
1315
1312
|
{
|
|
1316
1313
|
status: 202,
|
|
1317
|
-
headers:
|
|
1318
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1319
|
-
}
|
|
1314
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
1320
1315
|
}
|
|
1321
1316
|
);
|
|
1322
1317
|
}
|
|
@@ -1335,9 +1330,7 @@ function authController(store, config, bus) {
|
|
|
1335
1330
|
{ reason: "USER_LOGOUT", explanation: "Logged out successfully." },
|
|
1336
1331
|
{
|
|
1337
1332
|
status: 200,
|
|
1338
|
-
headers:
|
|
1339
|
-
"Set-Cookie": clearedTokenCookies(config)
|
|
1340
|
-
}
|
|
1333
|
+
headers: cookieHeaders(clearedTokenCookies(config))
|
|
1341
1334
|
}
|
|
1342
1335
|
);
|
|
1343
1336
|
},
|
|
@@ -1376,9 +1369,7 @@ function authController(store, config, bus) {
|
|
|
1376
1369
|
},
|
|
1377
1370
|
{
|
|
1378
1371
|
status: 200,
|
|
1379
|
-
headers:
|
|
1380
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1381
|
-
}
|
|
1372
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
1382
1373
|
}
|
|
1383
1374
|
);
|
|
1384
1375
|
},
|
|
@@ -1525,9 +1516,7 @@ function authController(store, config, bus) {
|
|
|
1525
1516
|
},
|
|
1526
1517
|
{
|
|
1527
1518
|
status: 200,
|
|
1528
|
-
headers:
|
|
1529
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1530
|
-
}
|
|
1519
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
1531
1520
|
}
|
|
1532
1521
|
);
|
|
1533
1522
|
}
|
|
@@ -1831,9 +1820,7 @@ function userController(store, config, bus) {
|
|
|
1831
1820
|
{ reason: "ACCOUNT_DELETED", explanation: "Account successfully deleted." },
|
|
1832
1821
|
{
|
|
1833
1822
|
status: 200,
|
|
1834
|
-
headers:
|
|
1835
|
-
"Set-Cookie": clearedTokenCookies(config)
|
|
1836
|
-
}
|
|
1823
|
+
headers: cookieHeaders(clearedTokenCookies(config))
|
|
1837
1824
|
}
|
|
1838
1825
|
);
|
|
1839
1826
|
}
|
|
@@ -1935,9 +1922,7 @@ function oauthController(store, config) {
|
|
|
1935
1922
|
},
|
|
1936
1923
|
{
|
|
1937
1924
|
status: 200,
|
|
1938
|
-
headers:
|
|
1939
|
-
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1940
|
-
}
|
|
1925
|
+
headers: cookieHeaders(tokenPairCookies(accessToken, refreshToken, config))
|
|
1941
1926
|
}
|
|
1942
1927
|
);
|
|
1943
1928
|
}
|
|
@@ -1954,44 +1939,42 @@ function buildAuthRoutes(store, config, bus) {
|
|
|
1954
1939
|
const passthrough = (_ctx, next) => next();
|
|
1955
1940
|
const ipLimit = (route) => buildAuthIpLimiter(route, store, config.rateLimit) ?? passthrough;
|
|
1956
1941
|
const acctLimit = (route) => buildAuthAccountLimiter(route, store, config.rateLimit) ?? passthrough;
|
|
1942
|
+
const R = (id, method, path, ...handlers) => {
|
|
1943
|
+
const o = config.routes?.[id];
|
|
1944
|
+
if (!o) return [method, path, ...handlers];
|
|
1945
|
+
if (typeof o === "string") return [method, o, ...handlers];
|
|
1946
|
+
return [o.method ?? method, o.path ?? path, ...handlers];
|
|
1947
|
+
};
|
|
1957
1948
|
const routes = [
|
|
1958
1949
|
// Registration & Login (Public)
|
|
1959
|
-
|
|
1960
|
-
|
|
1950
|
+
R("register", "POST", "/auth/register", ipLimit("register"), (0, import_middlewares.validate)(registerSchema), auth.register),
|
|
1951
|
+
R("login", "POST", "/auth/login", ipLimit("login"), (0, import_middlewares.validate)(loginSchema), acctLimit("login"), auth.login),
|
|
1961
1952
|
// Token Management (Public)
|
|
1962
|
-
|
|
1953
|
+
R("refresh", "POST", "/auth/refresh", (0, import_middlewares.validate)(refreshSchema), auth.refresh),
|
|
1963
1954
|
// Email — Password Recovery (Public)
|
|
1964
|
-
|
|
1965
|
-
|
|
1955
|
+
R("forgotPassword", "POST", "/auth/email/forgot", ipLimit("forgot"), (0, import_middlewares.validate)(forgotPasswordSchema), acctLimit("forgot"), auth.forgotPassword),
|
|
1956
|
+
R("resetPassword", "POST", "/auth/email/reset", (0, import_middlewares.validate)(resetPasswordSchema), auth.resetPassword),
|
|
1966
1957
|
// Verification (Protected — email or phone, determined by loginMethod)
|
|
1967
|
-
|
|
1968
|
-
|
|
1958
|
+
R("verifyEmail", "POST", "/auth/verify", import_middlewares2.requireAuth, (0, import_middlewares.validate)(verifySchema), auth.verify),
|
|
1959
|
+
R("sendVerification", "GET", "/auth/send-verification", import_middlewares2.requireAuth, auth.sendVerification),
|
|
1969
1960
|
// Account Management (Protected)
|
|
1970
|
-
|
|
1961
|
+
R("logout", "POST", "/auth/logout", import_middlewares2.requireAuth, (0, import_middlewares.validate)(refreshSchema), auth.logout),
|
|
1971
1962
|
// User Profile (Protected; writes also gate on requireVerification)
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1963
|
+
R("me", "GET", "/users", import_middlewares2.requireAuth, user.me),
|
|
1964
|
+
R("updateProfile", "PUT", "/users/profile", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updateProfileSchema), user.updateProfile),
|
|
1965
|
+
R("updatePreferences", "PUT", "/users/preferences", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updatePreferencesSchema), user.updatePreferences),
|
|
1966
|
+
R("updateEmail", "PUT", "/users/email", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updateEmailSchema), user.updateEmail),
|
|
1967
|
+
R("updatePhone", "PUT", "/users/phone", import_middlewares2.requireAuth, verifyGate, (0, import_middlewares.validate)(updatePhoneSchema), user.updatePhone),
|
|
1968
|
+
R("changePassword", "PUT", "/users/password", import_middlewares2.requireAuth, (0, import_middlewares.validate)(changePasswordSchema), user.changePassword),
|
|
1969
|
+
R("deleteMe", "DELETE", "/users", import_middlewares2.requireAuth, verifyGate, user.deleteMe),
|
|
1979
1970
|
// MFA (email sessions only — requireVerified is always enforced here
|
|
1980
1971
|
// because MFA is a security feature and email verification is meaningful)
|
|
1981
|
-
|
|
1972
|
+
R("mfaSetup", "POST", "/auth/mfa/setup", import_middlewares2.requireAuth, requireEmailLogin, import_middlewares2.requireVerified, mfa.setup),
|
|
1982
1973
|
// /auth/mfa/verify accepts both mfaPending tokens (TOTP/backup-code login)
|
|
1983
1974
|
// and full tokens (setup confirmation), so requireAnyAuth is used here.
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
"POST",
|
|
1988
|
-
"/auth/mfa/backup-codes",
|
|
1989
|
-
import_middlewares2.requireAuth,
|
|
1990
|
-
requireEmailLogin,
|
|
1991
|
-
import_middlewares2.requireVerified,
|
|
1992
|
-
(0, import_middlewares.validate)(mfaTokenSchema),
|
|
1993
|
-
mfa.regenerateBackupCodes
|
|
1994
|
-
]
|
|
1975
|
+
R("mfaVerify", "POST", "/auth/mfa/verify", ipLimit("mfaVerify"), import_middlewares2.requireAnyAuth, requireEmailLogin, import_middlewares2.requireVerified, (0, import_middlewares.validate)(mfaTokenSchema), mfa.verify),
|
|
1976
|
+
R("mfaDisable", "POST", "/auth/mfa/disable", import_middlewares2.requireAuth, requireEmailLogin, import_middlewares2.requireVerified, (0, import_middlewares.validate)(mfaTokenSchema), mfa.disable),
|
|
1977
|
+
R("mfaBackupCodes", "POST", "/auth/mfa/backup-codes", import_middlewares2.requireAuth, requireEmailLogin, import_middlewares2.requireVerified, (0, import_middlewares.validate)(mfaTokenSchema), mfa.regenerateBackupCodes)
|
|
1995
1978
|
];
|
|
1996
1979
|
if (config.providers.includes("google")) {
|
|
1997
1980
|
routes.push(
|