@fonderie/auth 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +35 -48
- 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 +35 -48
- 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-CLD1WPJs.d.cts → session-BGjjwz5_.d.cts} +1 -0
- package/dist/{session-CLD1WPJs.d.ts → session-BGjjwz5_.d.ts} +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -151,6 +151,26 @@ var changePasswordSchema = import_zod.z.object({
|
|
|
151
151
|
});
|
|
152
152
|
var mfaTokenSchema = import_zod.z.object({ token: import_zod.z.string().trim().min(6).max(64) });
|
|
153
153
|
|
|
154
|
+
// src/services/cookies.ts
|
|
155
|
+
function secureAttr(config) {
|
|
156
|
+
const secure = config.secureCookies ?? process.env["NODE_ENV"] === "production";
|
|
157
|
+
return secure ? "; Secure" : "";
|
|
158
|
+
}
|
|
159
|
+
function tokenPairCookies(accessToken, refreshToken, config) {
|
|
160
|
+
const secure = secureAttr(config);
|
|
161
|
+
return [
|
|
162
|
+
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/${secure}`,
|
|
163
|
+
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh${secure}`
|
|
164
|
+
].join(", ");
|
|
165
|
+
}
|
|
166
|
+
function clearedTokenCookies(config) {
|
|
167
|
+
const secure = secureAttr(config);
|
|
168
|
+
return [
|
|
169
|
+
`access_token=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0${secure}`,
|
|
170
|
+
`refresh_token=; HttpOnly; SameSite=Strict; Path=/auth/refresh; Max-Age=0${secure}`
|
|
171
|
+
].join(", ");
|
|
172
|
+
}
|
|
173
|
+
|
|
154
174
|
// src/controllers/mfa.controller.ts
|
|
155
175
|
var import_qrcode = __toESM(require("qrcode"), 1);
|
|
156
176
|
var import_core3 = require("@fonderie/core");
|
|
@@ -735,10 +755,7 @@ function mfaController(store, config, issuer, bus) {
|
|
|
735
755
|
{
|
|
736
756
|
status: 200,
|
|
737
757
|
headers: {
|
|
738
|
-
"Set-Cookie":
|
|
739
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
740
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
741
|
-
].join(", ")
|
|
758
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
742
759
|
}
|
|
743
760
|
}
|
|
744
761
|
);
|
|
@@ -1072,10 +1089,7 @@ function authController(store, config, bus) {
|
|
|
1072
1089
|
{
|
|
1073
1090
|
status: 201,
|
|
1074
1091
|
headers: {
|
|
1075
|
-
"Set-Cookie":
|
|
1076
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
1077
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
1078
|
-
].join(", ")
|
|
1092
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1079
1093
|
}
|
|
1080
1094
|
}
|
|
1081
1095
|
);
|
|
@@ -1137,10 +1151,7 @@ function authController(store, config, bus) {
|
|
|
1137
1151
|
{
|
|
1138
1152
|
status: 202,
|
|
1139
1153
|
headers: {
|
|
1140
|
-
"Set-Cookie":
|
|
1141
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
1142
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
1143
|
-
].join(", ")
|
|
1154
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1144
1155
|
}
|
|
1145
1156
|
}
|
|
1146
1157
|
);
|
|
@@ -1199,10 +1210,7 @@ function authController(store, config, bus) {
|
|
|
1199
1210
|
{
|
|
1200
1211
|
status: 200,
|
|
1201
1212
|
headers: {
|
|
1202
|
-
"Set-Cookie":
|
|
1203
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
1204
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
1205
|
-
].join(", ")
|
|
1213
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1206
1214
|
}
|
|
1207
1215
|
}
|
|
1208
1216
|
);
|
|
@@ -1245,10 +1253,7 @@ function authController(store, config, bus) {
|
|
|
1245
1253
|
{
|
|
1246
1254
|
status: 202,
|
|
1247
1255
|
headers: {
|
|
1248
|
-
"Set-Cookie":
|
|
1249
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
1250
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
1251
|
-
].join(", ")
|
|
1256
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1252
1257
|
}
|
|
1253
1258
|
}
|
|
1254
1259
|
);
|
|
@@ -1269,10 +1274,7 @@ function authController(store, config, bus) {
|
|
|
1269
1274
|
{
|
|
1270
1275
|
status: 200,
|
|
1271
1276
|
headers: {
|
|
1272
|
-
"Set-Cookie":
|
|
1273
|
-
"access_token=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0",
|
|
1274
|
-
"refresh_token=; HttpOnly; SameSite=Strict; Path=/auth/refresh; Max-Age=0"
|
|
1275
|
-
].join(", ")
|
|
1277
|
+
"Set-Cookie": clearedTokenCookies(config)
|
|
1276
1278
|
}
|
|
1277
1279
|
}
|
|
1278
1280
|
);
|
|
@@ -1313,10 +1315,7 @@ function authController(store, config, bus) {
|
|
|
1313
1315
|
{
|
|
1314
1316
|
status: 200,
|
|
1315
1317
|
headers: {
|
|
1316
|
-
"Set-Cookie":
|
|
1317
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
1318
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
1319
|
-
].join(", ")
|
|
1318
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1320
1319
|
}
|
|
1321
1320
|
}
|
|
1322
1321
|
);
|
|
@@ -1344,12 +1343,9 @@ function authController(store, config, bus) {
|
|
|
1344
1343
|
const remaining = checkCooldown(await passwordReset.findLastSentAt(user.id), cooldown);
|
|
1345
1344
|
if (remaining > 0) {
|
|
1346
1345
|
return (0, import_core4.setApiResponse)(
|
|
1347
|
-
import_core4.HTTP.
|
|
1348
|
-
"
|
|
1349
|
-
"
|
|
1350
|
-
{
|
|
1351
|
-
retryAfter: Math.ceil(remaining / 1e3)
|
|
1352
|
-
}
|
|
1346
|
+
import_core4.HTTP.OK,
|
|
1347
|
+
"PASSWORD_RESET_EMAIL_SENT",
|
|
1348
|
+
"Password reset email sent (if account exists)."
|
|
1353
1349
|
);
|
|
1354
1350
|
}
|
|
1355
1351
|
const pin = (0, import_node_crypto2.randomInt)(1e5, 1e6).toString();
|
|
@@ -1468,10 +1464,7 @@ function authController(store, config, bus) {
|
|
|
1468
1464
|
{
|
|
1469
1465
|
status: 200,
|
|
1470
1466
|
headers: {
|
|
1471
|
-
"Set-Cookie":
|
|
1472
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
1473
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
1474
|
-
].join(", ")
|
|
1467
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1475
1468
|
}
|
|
1476
1469
|
}
|
|
1477
1470
|
);
|
|
@@ -1588,7 +1581,7 @@ function normalizePhone2(phone2) {
|
|
|
1588
1581
|
function isValidPhone2(phone2) {
|
|
1589
1582
|
return typeof phone2 === "string" && /^\+?[1-9]\d{6,14}$/.test(normalizePhone2(phone2));
|
|
1590
1583
|
}
|
|
1591
|
-
function userController(store, bus) {
|
|
1584
|
+
function userController(store, config, bus) {
|
|
1592
1585
|
const users = new UserModel(store);
|
|
1593
1586
|
const emailVerif = new EmailVerificationModel(store);
|
|
1594
1587
|
const phoneVerif = new PhoneVerificationModel(store);
|
|
@@ -1777,10 +1770,7 @@ function userController(store, bus) {
|
|
|
1777
1770
|
{
|
|
1778
1771
|
status: 200,
|
|
1779
1772
|
headers: {
|
|
1780
|
-
"Set-Cookie":
|
|
1781
|
-
"access_token=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0",
|
|
1782
|
-
"refresh_token=; HttpOnly; SameSite=Strict; Path=/auth/refresh; Max-Age=0"
|
|
1783
|
-
].join(", ")
|
|
1773
|
+
"Set-Cookie": clearedTokenCookies(config)
|
|
1784
1774
|
}
|
|
1785
1775
|
}
|
|
1786
1776
|
);
|
|
@@ -1884,10 +1874,7 @@ function oauthController(store, config) {
|
|
|
1884
1874
|
{
|
|
1885
1875
|
status: 200,
|
|
1886
1876
|
headers: {
|
|
1887
|
-
"Set-Cookie":
|
|
1888
|
-
`access_token=${accessToken}; HttpOnly; SameSite=Strict; Path=/`,
|
|
1889
|
-
`refresh_token=${refreshToken}; HttpOnly; SameSite=Strict; Path=/auth/refresh`
|
|
1890
|
-
].join(", ")
|
|
1877
|
+
"Set-Cookie": tokenPairCookies(accessToken, refreshToken, config)
|
|
1891
1878
|
}
|
|
1892
1879
|
}
|
|
1893
1880
|
);
|
|
@@ -1897,7 +1884,7 @@ function oauthController(store, config) {
|
|
|
1897
1884
|
|
|
1898
1885
|
// src/routes.ts
|
|
1899
1886
|
function buildAuthRoutes(store, config, bus) {
|
|
1900
|
-
const user = userController(store, bus);
|
|
1887
|
+
const user = userController(store, config, bus);
|
|
1901
1888
|
const auth = authController(store, config, bus);
|
|
1902
1889
|
const oauth = oauthController(store, config);
|
|
1903
1890
|
const mfa = mfaController(store, config, config.appName ?? "Fonderie", bus);
|