najm-auth 4.2.0 → 4.2.2
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/README.md +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +84 -39
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -220,7 +220,8 @@ All routes are prefixed with `/auth` and auto-registered by the plugin.
|
|
|
220
220
|
Applications with an approval-owned onboarding flow should set
|
|
221
221
|
`publicRegistration: false`. This removes the unauthenticated route while
|
|
222
222
|
retaining `AuthService.registerUser()`, `provisionUser()`, and other internal
|
|
223
|
-
account-management APIs for trusted application services.
|
|
223
|
+
account-management APIs for trusted application services. The registration
|
|
224
|
+
controller also answers 404 when disabled if an older core mounts it anyway.
|
|
224
225
|
|
|
225
226
|
### Identity presets
|
|
226
227
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2170,6 +2170,7 @@ declare class AuthIdentityContextService {
|
|
|
2170
2170
|
*/
|
|
2171
2171
|
declare class RegistrationController {
|
|
2172
2172
|
private authService;
|
|
2173
|
+
private config;
|
|
2173
2174
|
constructor(authService: AuthService);
|
|
2174
2175
|
registerUser(body: RegisterDto): Promise<SanitizedUser>;
|
|
2175
2176
|
}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/AuthPlugin.ts
|
|
9
|
-
import { Err as
|
|
9
|
+
import { Err as Err17, plugin } from "najm-core";
|
|
10
10
|
import { cache } from "najm-cache";
|
|
11
11
|
|
|
12
12
|
// src/auth.tokens.ts
|
|
@@ -2118,6 +2118,24 @@ CredentialSetupRequirementRepository = __decorate11([
|
|
|
2118
2118
|
// src/credentialSetup/types.ts
|
|
2119
2119
|
var PASSWORD_SETUP_PURPOSE = "password";
|
|
2120
2120
|
|
|
2121
|
+
// src/shared/storedTime.ts
|
|
2122
|
+
function storedTimeMs(value) {
|
|
2123
|
+
if (value instanceof Date)
|
|
2124
|
+
return value.getTime();
|
|
2125
|
+
const text3 = value.trim().replace(" ", "T");
|
|
2126
|
+
const time = text3.split("T")[1];
|
|
2127
|
+
if (!time)
|
|
2128
|
+
return Date.parse(text3);
|
|
2129
|
+
if (/Z$/i.test(time))
|
|
2130
|
+
return Date.parse(text3);
|
|
2131
|
+
const offset = /([+-])(\d{2}):?(\d{2})?$/.exec(time);
|
|
2132
|
+
if (!offset)
|
|
2133
|
+
return Date.parse(`${text3}Z`);
|
|
2134
|
+
const [zone, sign, hours, minutes = "00"] = offset;
|
|
2135
|
+
return Date.parse(`${text3.slice(0, -zone.length)}${sign}${hours}:${minutes}`);
|
|
2136
|
+
}
|
|
2137
|
+
__name(storedTimeMs, "storedTimeMs");
|
|
2138
|
+
|
|
2121
2139
|
// src/tokens/TokenService.ts
|
|
2122
2140
|
import { Err as Err7 } from "najm-core";
|
|
2123
2141
|
var __decorate12 = function(decorators, target, key, desc) {
|
|
@@ -2297,7 +2315,7 @@ var TokenService = class TokenService2 {
|
|
|
2297
2315
|
if (presentedHash === stored.token) {
|
|
2298
2316
|
return { userId, tokenFamily };
|
|
2299
2317
|
}
|
|
2300
|
-
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil &&
|
|
2318
|
+
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil && storedTimeMs(stored.previousValidUntil) > Date.now() && !stored.previousUsedAt;
|
|
2301
2319
|
if (canRecover) {
|
|
2302
2320
|
return { userId, tokenFamily };
|
|
2303
2321
|
}
|
|
@@ -2557,7 +2575,7 @@ var TokenService = class TokenService2 {
|
|
|
2557
2575
|
if (presentedHash === stored.token) {
|
|
2558
2576
|
return this.rotateTokens(userId, tokenFamily, stored.token);
|
|
2559
2577
|
}
|
|
2560
|
-
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil &&
|
|
2578
|
+
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil && storedTimeMs(stored.previousValidUntil) > Date.now() && !stored.previousUsedAt;
|
|
2561
2579
|
if (canRecover) {
|
|
2562
2580
|
const claimed = await this.tokenRepository.markPreviousUsed(tokenFamily, presentedHash);
|
|
2563
2581
|
if (!claimed?.length) {
|
|
@@ -2695,7 +2713,7 @@ var TokenService = class TokenService2 {
|
|
|
2695
2713
|
if (presentedHash === stored.token) {
|
|
2696
2714
|
return decoded.tokenFamily;
|
|
2697
2715
|
}
|
|
2698
|
-
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil &&
|
|
2716
|
+
const canRecover = stored.previousHash && presentedHash === stored.previousHash && stored.previousValidUntil && storedTimeMs(stored.previousValidUntil) > Date.now() && !stored.previousUsedAt;
|
|
2699
2717
|
return canRecover ? decoded.tokenFamily : null;
|
|
2700
2718
|
} catch {
|
|
2701
2719
|
return null;
|
|
@@ -3503,7 +3521,7 @@ var AuthService = class AuthService2 {
|
|
|
3503
3521
|
isLockoutActive(lockoutUntil) {
|
|
3504
3522
|
if (!lockoutUntil)
|
|
3505
3523
|
return false;
|
|
3506
|
-
return
|
|
3524
|
+
return storedTimeMs(lockoutUntil) > Date.now();
|
|
3507
3525
|
}
|
|
3508
3526
|
nextLockoutUntil() {
|
|
3509
3527
|
const durationMs = timestring4(this.config.lockout.duration, "ms");
|
|
@@ -4194,6 +4212,7 @@ var isAdmin = composeGuards(isAuth(), Role(ROLES.ADMIN));
|
|
|
4194
4212
|
var isAdministrator = composeGuards(isAuth(), Role(ROLE_GROUPS.ADMINISTRATORS));
|
|
4195
4213
|
|
|
4196
4214
|
// src/auth/AuthController.ts
|
|
4215
|
+
import { Public } from "najm-guard";
|
|
4197
4216
|
import { Validate } from "najm-validation";
|
|
4198
4217
|
import { RateLimit, UNRESOLVED_CLIENT_ADDRESS } from "najm-rate";
|
|
4199
4218
|
import { createHash as createHash3 } from "crypto";
|
|
@@ -4447,6 +4466,7 @@ var AuthController = class AuthController2 {
|
|
|
4447
4466
|
};
|
|
4448
4467
|
__decorate21([
|
|
4449
4468
|
Post("/login"),
|
|
4469
|
+
Public(),
|
|
4450
4470
|
RateLimit({
|
|
4451
4471
|
limit: loginRateLimit.limit,
|
|
4452
4472
|
window: loginRateLimit.window,
|
|
@@ -4474,6 +4494,7 @@ __decorate21([
|
|
|
4474
4494
|
], AuthController.prototype, "inviteUser", null);
|
|
4475
4495
|
__decorate21([
|
|
4476
4496
|
Post("/refresh"),
|
|
4497
|
+
Public(),
|
|
4477
4498
|
RateLimit({ limit: 15, window: "15m", key: cookieFingerprint() }),
|
|
4478
4499
|
ResMsg("auth.success.tokenRefreshed"),
|
|
4479
4500
|
__metadata21("design:type", Function),
|
|
@@ -4482,6 +4503,7 @@ __decorate21([
|
|
|
4482
4503
|
], AuthController.prototype, "refreshTokens", null);
|
|
4483
4504
|
__decorate21([
|
|
4484
4505
|
Post("/session/recover"),
|
|
4506
|
+
Public(),
|
|
4485
4507
|
RateLimit({ limit: 120, window: "1m", key: cookieFingerprint() }),
|
|
4486
4508
|
ResMsg("auth.success.sessionRecovered"),
|
|
4487
4509
|
__param5(0, Headers("x-najm-session-recovery")),
|
|
@@ -4492,6 +4514,7 @@ __decorate21([
|
|
|
4492
4514
|
], AuthController.prototype, "recoverSession", null);
|
|
4493
4515
|
__decorate21([
|
|
4494
4516
|
Post("/logout"),
|
|
4517
|
+
Public(),
|
|
4495
4518
|
__param5(0, User2("id")),
|
|
4496
4519
|
__param5(1, Headers("authorization")),
|
|
4497
4520
|
__metadata21("design:type", Function),
|
|
@@ -4511,6 +4534,7 @@ __decorate21([
|
|
|
4511
4534
|
], AuthController.prototype, "changePassword", null);
|
|
4512
4535
|
__decorate21([
|
|
4513
4536
|
Get("/me"),
|
|
4537
|
+
Public(),
|
|
4514
4538
|
RateLimit({ limit: 30, window: "1m", key: cookieFingerprint() }),
|
|
4515
4539
|
ResMsg("auth.users.success.retrieved"),
|
|
4516
4540
|
__param5(0, Headers("authorization")),
|
|
@@ -4520,6 +4544,7 @@ __decorate21([
|
|
|
4520
4544
|
], AuthController.prototype, "userProfile", null);
|
|
4521
4545
|
__decorate21([
|
|
4522
4546
|
Post("/forgot-password"),
|
|
4547
|
+
Public(),
|
|
4523
4548
|
RateLimit({ limit: 3, window: "15m", key: authEmailRateLimitKey, message: "Too many password reset requests. Please try again later." }),
|
|
4524
4549
|
Validate(resetPasswordDto),
|
|
4525
4550
|
ResMsg("auth.success.passwordResetSent"),
|
|
@@ -4530,6 +4555,7 @@ __decorate21([
|
|
|
4530
4555
|
], AuthController.prototype, "forgotPassword", null);
|
|
4531
4556
|
__decorate21([
|
|
4532
4557
|
Post("/reset-password"),
|
|
4558
|
+
Public(),
|
|
4533
4559
|
RateLimit({ limit: 5, window: "15m", key: "ip", message: "Too many password reset attempts. Please try again later." }),
|
|
4534
4560
|
Validate(confirmResetPasswordDto),
|
|
4535
4561
|
ResMsg("auth.success.passwordReset"),
|
|
@@ -4744,8 +4770,9 @@ AuthIdentityContextService = __decorate23([
|
|
|
4744
4770
|
], AuthIdentityContextService);
|
|
4745
4771
|
|
|
4746
4772
|
// src/auth/RegistrationController.ts
|
|
4747
|
-
import { Body as Body2, Controller as Controller2, Post as Post2, ResMsg as ResMsg2 } from "najm-core";
|
|
4773
|
+
import { Body as Body2, Controller as Controller2, Err as Err14, Inject as Inject15, Post as Post2, ResMsg as ResMsg2 } from "najm-core";
|
|
4748
4774
|
import { RateLimit as RateLimit2 } from "najm-rate";
|
|
4775
|
+
import { Public as Public2 } from "najm-guard";
|
|
4749
4776
|
import { Validate as Validate2 } from "najm-validation";
|
|
4750
4777
|
var __decorate24 = function(decorators, target, key, desc) {
|
|
4751
4778
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -4767,15 +4794,23 @@ var RegistrationController = class RegistrationController2 {
|
|
|
4767
4794
|
__name(this, "RegistrationController");
|
|
4768
4795
|
}
|
|
4769
4796
|
authService;
|
|
4797
|
+
config;
|
|
4770
4798
|
constructor(authService) {
|
|
4771
4799
|
this.authService = authService;
|
|
4772
4800
|
}
|
|
4773
4801
|
async registerUser(body) {
|
|
4802
|
+
if (this.config.publicRegistration === false)
|
|
4803
|
+
Err14("Not Found", 404);
|
|
4774
4804
|
return this.authService.registerUser(body);
|
|
4775
4805
|
}
|
|
4776
4806
|
};
|
|
4807
|
+
__decorate24([
|
|
4808
|
+
Inject15(AUTH_CONFIG),
|
|
4809
|
+
__metadata24("design:type", Object)
|
|
4810
|
+
], RegistrationController.prototype, "config", void 0);
|
|
4777
4811
|
__decorate24([
|
|
4778
4812
|
Post2("/register"),
|
|
4813
|
+
Public2(),
|
|
4779
4814
|
RateLimit2({ limit: 5, window: "15m", key: authEmailRateLimitKey }),
|
|
4780
4815
|
Validate2(registerDto),
|
|
4781
4816
|
ResMsg2("auth.success.register"),
|
|
@@ -5239,7 +5274,7 @@ __export(permissions_exports, {
|
|
|
5239
5274
|
|
|
5240
5275
|
// src/permissions/PermissionRepository.ts
|
|
5241
5276
|
import { eq as eq7, and as and4 } from "drizzle-orm";
|
|
5242
|
-
import { Repository as Repository6, Inject as
|
|
5277
|
+
import { Repository as Repository6, Inject as Inject16 } from "najm-core";
|
|
5243
5278
|
import { DB as DB6 } from "najm-database";
|
|
5244
5279
|
var __decorate27 = function(decorators, target, key, desc) {
|
|
5245
5280
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -5330,7 +5365,7 @@ __decorate27([
|
|
|
5330
5365
|
__metadata27("design:type", Object)
|
|
5331
5366
|
], PermissionRepository.prototype, "db", void 0);
|
|
5332
5367
|
__decorate27([
|
|
5333
|
-
|
|
5368
|
+
Inject16(AUTH_SCHEMA),
|
|
5334
5369
|
__metadata27("design:type", Object)
|
|
5335
5370
|
], PermissionRepository.prototype, "schema", void 0);
|
|
5336
5371
|
PermissionRepository = __decorate27([
|
|
@@ -5407,7 +5442,7 @@ import { Injectable as Injectable15 } from "najm-core";
|
|
|
5407
5442
|
// src/permissions/PermissionValidator.ts
|
|
5408
5443
|
import { Injectable as Injectable14 } from "najm-core";
|
|
5409
5444
|
import { I18n as I18n9 } from "najm-i18n";
|
|
5410
|
-
import { Err as
|
|
5445
|
+
import { Err as Err15 } from "najm-core";
|
|
5411
5446
|
var __decorate29 = function(decorators, target, key, desc) {
|
|
5412
5447
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5413
5448
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5436,7 +5471,7 @@ var PermissionValidator = class PermissionValidator2 {
|
|
|
5436
5471
|
async checkPermissionExists(id) {
|
|
5437
5472
|
const permission = await this.permissionRepository.getById(id);
|
|
5438
5473
|
if (!permission) {
|
|
5439
|
-
|
|
5474
|
+
Err15(this.t("errors.notFound"), 404);
|
|
5440
5475
|
}
|
|
5441
5476
|
return permission;
|
|
5442
5477
|
}
|
|
@@ -5446,7 +5481,7 @@ var PermissionValidator = class PermissionValidator2 {
|
|
|
5446
5481
|
async checkPermissionExistsByName(name) {
|
|
5447
5482
|
const permission = await this.permissionRepository.getByName(name);
|
|
5448
5483
|
if (!permission) {
|
|
5449
|
-
|
|
5484
|
+
Err15(this.t("errors.notFound"), 404);
|
|
5450
5485
|
}
|
|
5451
5486
|
return permission;
|
|
5452
5487
|
}
|
|
@@ -5458,7 +5493,7 @@ var PermissionValidator = class PermissionValidator2 {
|
|
|
5458
5493
|
return;
|
|
5459
5494
|
const existingPermission = await this.permissionRepository.getByName(name);
|
|
5460
5495
|
if (existingPermission && existingPermission.id !== excludeId) {
|
|
5461
|
-
|
|
5496
|
+
Err15(this.t("errors.nameExists"), 409);
|
|
5462
5497
|
}
|
|
5463
5498
|
}
|
|
5464
5499
|
/**
|
|
@@ -5481,7 +5516,7 @@ var PermissionValidator = class PermissionValidator2 {
|
|
|
5481
5516
|
await this.checkPermissionExists(permissionId);
|
|
5482
5517
|
const hasPermission = await this.permissionRepository.checkRoleHasPermission(roleId, permissionId);
|
|
5483
5518
|
if (hasPermission) {
|
|
5484
|
-
|
|
5519
|
+
Err15(this.t("errors.roleAlreadyHasPermission"), 409);
|
|
5485
5520
|
}
|
|
5486
5521
|
}
|
|
5487
5522
|
};
|
|
@@ -6034,7 +6069,7 @@ function own(table, opts) {
|
|
|
6034
6069
|
__name(own, "own");
|
|
6035
6070
|
|
|
6036
6071
|
// src/ownership/configureOwnership.ts
|
|
6037
|
-
import { Injectable as Injectable16, Inject as
|
|
6072
|
+
import { Injectable as Injectable16, Inject as Inject17, User as User4, Body as Body6, Params as Params4 } from "najm-core";
|
|
6038
6073
|
import { createGuard as createGuard5, composeGuards as composeGuards4 } from "najm-guard";
|
|
6039
6074
|
var __decorate32 = function(decorators, target, key, desc) {
|
|
6040
6075
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -6075,7 +6110,7 @@ function createResourceGuards(ownershipClass, resourceType, resource, options) {
|
|
|
6075
6110
|
}
|
|
6076
6111
|
};
|
|
6077
6112
|
__decorate32([
|
|
6078
|
-
|
|
6113
|
+
Inject17(ownershipClass),
|
|
6079
6114
|
__metadata32("design:type", Object)
|
|
6080
6115
|
], AccessGuard.prototype, "ownership", void 0);
|
|
6081
6116
|
__decorate32([
|
|
@@ -6099,7 +6134,7 @@ function createResourceGuards(ownershipClass, resourceType, resource, options) {
|
|
|
6099
6134
|
}
|
|
6100
6135
|
};
|
|
6101
6136
|
__decorate32([
|
|
6102
|
-
|
|
6137
|
+
Inject17(ownershipClass),
|
|
6103
6138
|
__metadata32("design:type", Object)
|
|
6104
6139
|
], ListGuard.prototype, "ownership", void 0);
|
|
6105
6140
|
__decorate32([
|
|
@@ -6258,7 +6293,7 @@ function configureOwnership(config) {
|
|
|
6258
6293
|
}
|
|
6259
6294
|
};
|
|
6260
6295
|
__decorate32([
|
|
6261
|
-
|
|
6296
|
+
Inject17(GeneratedOwnershipService),
|
|
6262
6297
|
__metadata32("design:type", GeneratedOwnershipService)
|
|
6263
6298
|
], BodyAccessGuard.prototype, "ownership", void 0);
|
|
6264
6299
|
__decorate32([
|
|
@@ -6384,7 +6419,7 @@ __name(Policy, "Policy");
|
|
|
6384
6419
|
// src/ownership/OwnedDecorator.ts
|
|
6385
6420
|
import "reflect-metadata";
|
|
6386
6421
|
import { sql as sql6, and as and5 } from "drizzle-orm";
|
|
6387
|
-
import { Injectable as Injectable17, Inject as
|
|
6422
|
+
import { Injectable as Injectable17, Inject as Inject18, DI as DI3, Container as Container2, REQUEST_ID } from "najm-core";
|
|
6388
6423
|
import { USER as USER2 } from "najm-guard";
|
|
6389
6424
|
|
|
6390
6425
|
// src/ownership/ownershipCondition.ts
|
|
@@ -6449,7 +6484,7 @@ function ownedProperty(proto, key, tokens) {
|
|
|
6449
6484
|
enumerable: false
|
|
6450
6485
|
});
|
|
6451
6486
|
if (!Reflect.hasOwnMetadata(OWNED_PROPERTIES, proto, "_scopeCtx")) {
|
|
6452
|
-
|
|
6487
|
+
Inject18(ScopeContext)(proto, "_scopeCtx");
|
|
6453
6488
|
Reflect.defineMetadata(OWNED_PROPERTIES, true, proto, "_scopeCtx");
|
|
6454
6489
|
Object.defineProperty(proto, "_scopeCtx", {
|
|
6455
6490
|
get() {
|
|
@@ -6523,7 +6558,7 @@ function Owned(token, ...alternatives) {
|
|
|
6523
6558
|
throw new Error("@Owned requires a repository class");
|
|
6524
6559
|
Reflect.defineMetadata(OWNED_META, token, target);
|
|
6525
6560
|
const proto = target.prototype;
|
|
6526
|
-
|
|
6561
|
+
Inject18(ScopeContext)(proto, "_scopeCtx");
|
|
6527
6562
|
Object.defineProperty(proto, "ownershipCondition", {
|
|
6528
6563
|
value() {
|
|
6529
6564
|
return ownershipCondition(this.db, tokens, this._scopeCtx);
|
|
@@ -6745,7 +6780,7 @@ __name(getAuthLocale, "getAuthLocale");
|
|
|
6745
6780
|
var AUTH_SUPPORTED_LANGUAGES = Object.keys(AUTH_LOCALES);
|
|
6746
6781
|
|
|
6747
6782
|
// src/oauth/google/GoogleOAuthProvider.ts
|
|
6748
|
-
import { Inject as
|
|
6783
|
+
import { Inject as Inject20, Injectable as Injectable19 } from "najm-core";
|
|
6749
6784
|
|
|
6750
6785
|
// src/oauth/types.ts
|
|
6751
6786
|
var OAuthFlowError = class extends Error {
|
|
@@ -6763,7 +6798,7 @@ var OAuthFlowError = class extends Error {
|
|
|
6763
6798
|
};
|
|
6764
6799
|
|
|
6765
6800
|
// src/oauth/google/GoogleTokenVerifier.ts
|
|
6766
|
-
import { Inject as
|
|
6801
|
+
import { Inject as Inject19, Injectable as Injectable18 } from "najm-core";
|
|
6767
6802
|
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
6768
6803
|
var __decorate34 = function(decorators, target, key, desc) {
|
|
6769
6804
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -6824,7 +6859,7 @@ var GoogleTokenVerifier = class GoogleTokenVerifier2 {
|
|
|
6824
6859
|
}
|
|
6825
6860
|
};
|
|
6826
6861
|
__decorate34([
|
|
6827
|
-
|
|
6862
|
+
Inject19(AUTH_CONFIG),
|
|
6828
6863
|
__metadata34("design:type", Object)
|
|
6829
6864
|
], GoogleTokenVerifier.prototype, "config", void 0);
|
|
6830
6865
|
GoogleTokenVerifier = __decorate34([
|
|
@@ -6910,7 +6945,7 @@ var GoogleOAuthProvider = class GoogleOAuthProvider2 {
|
|
|
6910
6945
|
}
|
|
6911
6946
|
};
|
|
6912
6947
|
__decorate35([
|
|
6913
|
-
|
|
6948
|
+
Inject20(AUTH_CONFIG),
|
|
6914
6949
|
__metadata35("design:type", Object)
|
|
6915
6950
|
], GoogleOAuthProvider.prototype, "config", void 0);
|
|
6916
6951
|
GoogleOAuthProvider = __decorate35([
|
|
@@ -6919,7 +6954,7 @@ GoogleOAuthProvider = __decorate35([
|
|
|
6919
6954
|
], GoogleOAuthProvider);
|
|
6920
6955
|
|
|
6921
6956
|
// src/oauth/github/GitHubOAuthProvider.ts
|
|
6922
|
-
import { Inject as
|
|
6957
|
+
import { Inject as Inject21, Injectable as Injectable20 } from "najm-core";
|
|
6923
6958
|
var __decorate36 = function(decorators, target, key, desc) {
|
|
6924
6959
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6925
6960
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -7043,7 +7078,7 @@ var GitHubOAuthProvider = class GitHubOAuthProvider2 {
|
|
|
7043
7078
|
}
|
|
7044
7079
|
};
|
|
7045
7080
|
__decorate36([
|
|
7046
|
-
|
|
7081
|
+
Inject21(AUTH_CONFIG),
|
|
7047
7082
|
__metadata36("design:type", Object)
|
|
7048
7083
|
], GitHubOAuthProvider.prototype, "config", void 0);
|
|
7049
7084
|
GitHubOAuthProvider = __decorate36([
|
|
@@ -7054,18 +7089,19 @@ GitHubOAuthProvider = __decorate36([
|
|
|
7054
7089
|
import { createHash as createHash5 } from "crypto";
|
|
7055
7090
|
import { Controller as Controller6, Ctx as Ctx2, Get as Get5, Post as Post6, Query as Query2, User as User5 } from "najm-core";
|
|
7056
7091
|
import { RateLimit as RateLimit3 } from "najm-rate";
|
|
7092
|
+
import { Public as Public3 } from "najm-guard";
|
|
7057
7093
|
|
|
7058
7094
|
// src/oauth/OAuthService.ts
|
|
7059
|
-
import { Err as
|
|
7095
|
+
import { Err as Err16, Inject as Inject24, Injectable as Injectable23, Log as Log2 } from "najm-core";
|
|
7060
7096
|
|
|
7061
7097
|
// src/oauth/OAuthAccountService.ts
|
|
7062
7098
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
7063
|
-
import { Inject as
|
|
7099
|
+
import { Inject as Inject23, Injectable as Injectable21 } from "najm-core";
|
|
7064
7100
|
import { Transaction as Transaction5 } from "najm-database";
|
|
7065
7101
|
|
|
7066
7102
|
// src/oauth/OAuthAccountRepository.ts
|
|
7067
7103
|
import { and as and6, eq as eq9 } from "drizzle-orm";
|
|
7068
|
-
import { Inject as
|
|
7104
|
+
import { Inject as Inject22, Repository as Repository7 } from "najm-core";
|
|
7069
7105
|
import { DB as DB7 } from "najm-database";
|
|
7070
7106
|
var __decorate37 = function(decorators, target, key, desc) {
|
|
7071
7107
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -7106,7 +7142,7 @@ __decorate37([
|
|
|
7106
7142
|
__metadata37("design:type", Object)
|
|
7107
7143
|
], OAuthAccountRepository.prototype, "db", void 0);
|
|
7108
7144
|
__decorate37([
|
|
7109
|
-
|
|
7145
|
+
Inject22(AUTH_SCHEMA),
|
|
7110
7146
|
__metadata37("design:type", Object)
|
|
7111
7147
|
], OAuthAccountRepository.prototype, "schema", void 0);
|
|
7112
7148
|
OAuthAccountRepository = __decorate37([
|
|
@@ -7203,7 +7239,7 @@ var OAuthAccountService = class OAuthAccountService2 {
|
|
|
7203
7239
|
}
|
|
7204
7240
|
};
|
|
7205
7241
|
__decorate38([
|
|
7206
|
-
|
|
7242
|
+
Inject23(AUTH_CONFIG),
|
|
7207
7243
|
__metadata38("design:type", Object)
|
|
7208
7244
|
], OAuthAccountService.prototype, "config", void 0);
|
|
7209
7245
|
__decorate38([
|
|
@@ -7407,7 +7443,7 @@ var OAuthService = class OAuthService2 {
|
|
|
7407
7443
|
*/
|
|
7408
7444
|
failStart(error) {
|
|
7409
7445
|
if (error instanceof OAuthFlowError) {
|
|
7410
|
-
|
|
7446
|
+
Err16(error.oauthCode, error.status);
|
|
7411
7447
|
}
|
|
7412
7448
|
throw error;
|
|
7413
7449
|
}
|
|
@@ -7514,7 +7550,7 @@ var OAuthService = class OAuthService2 {
|
|
|
7514
7550
|
}
|
|
7515
7551
|
};
|
|
7516
7552
|
__decorate40([
|
|
7517
|
-
|
|
7553
|
+
Inject24(AUTH_CONFIG),
|
|
7518
7554
|
__metadata40("design:type", Object)
|
|
7519
7555
|
], OAuthService.prototype, "config", void 0);
|
|
7520
7556
|
__decorate40([
|
|
@@ -7568,6 +7604,7 @@ var GitHubOAuthController = class GitHubOAuthController2 {
|
|
|
7568
7604
|
};
|
|
7569
7605
|
__decorate41([
|
|
7570
7606
|
Get5("/start"),
|
|
7607
|
+
Public3(),
|
|
7571
7608
|
RateLimit3({ limit: 20, window: "15m", key: "ip" }),
|
|
7572
7609
|
__param13(0, Ctx2()),
|
|
7573
7610
|
__param13(1, Query2("returnTo")),
|
|
@@ -7577,6 +7614,7 @@ __decorate41([
|
|
|
7577
7614
|
], GitHubOAuthController.prototype, "start", null);
|
|
7578
7615
|
__decorate41([
|
|
7579
7616
|
Get5("/callback"),
|
|
7617
|
+
Public3(),
|
|
7580
7618
|
RateLimit3({ limit: 20, window: "15m", key: callbackKey }),
|
|
7581
7619
|
__param13(0, Ctx2()),
|
|
7582
7620
|
__param13(1, Query2("code")),
|
|
@@ -7605,6 +7643,7 @@ GitHubOAuthController = __decorate41([
|
|
|
7605
7643
|
import { createHash as createHash6 } from "crypto";
|
|
7606
7644
|
import { Controller as Controller7, Ctx as Ctx3, Get as Get6, Post as Post7, Query as Query3, User as User6 } from "najm-core";
|
|
7607
7645
|
import { RateLimit as RateLimit4 } from "najm-rate";
|
|
7646
|
+
import { Public as Public4 } from "najm-guard";
|
|
7608
7647
|
var __decorate42 = function(decorators, target, key, desc) {
|
|
7609
7648
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7610
7649
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -7647,6 +7686,7 @@ var OAuthController = class OAuthController2 {
|
|
|
7647
7686
|
};
|
|
7648
7687
|
__decorate42([
|
|
7649
7688
|
Get6("/start"),
|
|
7689
|
+
Public4(),
|
|
7650
7690
|
RateLimit4({ limit: 20, window: "15m", key: "ip" }),
|
|
7651
7691
|
__param14(0, Ctx3()),
|
|
7652
7692
|
__param14(1, Query3("returnTo")),
|
|
@@ -7656,6 +7696,7 @@ __decorate42([
|
|
|
7656
7696
|
], OAuthController.prototype, "start", null);
|
|
7657
7697
|
__decorate42([
|
|
7658
7698
|
Get6("/callback"),
|
|
7699
|
+
Public4(),
|
|
7659
7700
|
RateLimit4({ limit: 20, window: "15m", key: callbackKey2 }),
|
|
7660
7701
|
__param14(0, Ctx3()),
|
|
7661
7702
|
__param14(1, Query3("code")),
|
|
@@ -7696,6 +7737,7 @@ var OAUTH_MODULE = [
|
|
|
7696
7737
|
// src/credentialSetup/CredentialSetupController.ts
|
|
7697
7738
|
import { Body as Body7, Controller as Controller8, Get as Get7, Post as Post8, ResMsg as ResMsg6 } from "najm-core";
|
|
7698
7739
|
import { RateLimit as RateLimit5 } from "najm-rate";
|
|
7740
|
+
import { Public as Public5 } from "najm-guard";
|
|
7699
7741
|
import { Validate as Validate6 } from "najm-validation";
|
|
7700
7742
|
|
|
7701
7743
|
// src/credentialSetup/CredentialSetupDto.ts
|
|
@@ -7741,6 +7783,7 @@ var CredentialSetupController = class CredentialSetupController2 {
|
|
|
7741
7783
|
};
|
|
7742
7784
|
__decorate43([
|
|
7743
7785
|
Get7("/setup"),
|
|
7786
|
+
Public5(),
|
|
7744
7787
|
RateLimit5({ limit: 30, window: "15m", key: "ip" }),
|
|
7745
7788
|
ResMsg6("auth.success.credentialSetupPending"),
|
|
7746
7789
|
__metadata43("design:type", Function),
|
|
@@ -7749,6 +7792,7 @@ __decorate43([
|
|
|
7749
7792
|
], CredentialSetupController.prototype, "status", null);
|
|
7750
7793
|
__decorate43([
|
|
7751
7794
|
Post8("/change"),
|
|
7795
|
+
Public5(),
|
|
7752
7796
|
RateLimit5({ limit: 5, window: "15m", key: "ip" }),
|
|
7753
7797
|
Validate6(credentialSetupChangeDto),
|
|
7754
7798
|
ResMsg6("auth.success.credentialSetupPasswordReplaced"),
|
|
@@ -7759,6 +7803,7 @@ __decorate43([
|
|
|
7759
7803
|
], CredentialSetupController.prototype, "change", null);
|
|
7760
7804
|
__decorate43([
|
|
7761
7805
|
Post8("/cancel"),
|
|
7806
|
+
Public5(),
|
|
7762
7807
|
RateLimit5({ limit: 10, window: "15m", key: "ip" }),
|
|
7763
7808
|
ResMsg6("auth.success.credentialSetupCancelled"),
|
|
7764
7809
|
__metadata43("design:type", Function),
|
|
@@ -7821,9 +7866,9 @@ var resolveGoogleConfig = /* @__PURE__ */ __name((config) => {
|
|
|
7821
7866
|
const clientId = google.clientId ?? process.env.GOOGLE_CLIENT_ID ?? "";
|
|
7822
7867
|
const clientSecret = google.clientSecret ?? process.env.GOOGLE_CLIENT_SECRET ?? "";
|
|
7823
7868
|
if (!clientId)
|
|
7824
|
-
throw
|
|
7869
|
+
throw Err17.configRequired("auth.oauth.google", "GOOGLE_CLIENT_ID");
|
|
7825
7870
|
if (!clientSecret)
|
|
7826
|
-
throw
|
|
7871
|
+
throw Err17.configRequired("auth.oauth.google", "GOOGLE_CLIENT_SECRET");
|
|
7827
7872
|
const frontendUrl = config?.frontendUrl ?? process.env.FRONTEND_URL ?? "http://localhost:3000";
|
|
7828
7873
|
const callbackUrl = google.callbackUrl ?? process.env.GOOGLE_CALLBACK_URL ?? `${frontendUrl.replace(/\/$/, "")}/api/auth/oauth/google/callback`;
|
|
7829
7874
|
return {
|
|
@@ -7845,9 +7890,9 @@ var resolveGitHubConfig = /* @__PURE__ */ __name((config) => {
|
|
|
7845
7890
|
const clientId = github.clientId ?? process.env.GITHUB_CLIENT_ID ?? "";
|
|
7846
7891
|
const clientSecret = github.clientSecret ?? process.env.GITHUB_CLIENT_SECRET ?? "";
|
|
7847
7892
|
if (!clientId)
|
|
7848
|
-
throw
|
|
7893
|
+
throw Err17.configRequired("auth.oauth.github", "GITHUB_CLIENT_ID");
|
|
7849
7894
|
if (!clientSecret)
|
|
7850
|
-
throw
|
|
7895
|
+
throw Err17.configRequired("auth.oauth.github", "GITHUB_CLIENT_SECRET");
|
|
7851
7896
|
const frontendUrl = config?.frontendUrl ?? process.env.FRONTEND_URL ?? "http://localhost:3000";
|
|
7852
7897
|
const callbackUrl = github.callbackUrl ?? process.env.GITHUB_CALLBACK_URL ?? `${frontendUrl.replace(/\/$/, "")}/api/auth/oauth/github/callback`;
|
|
7853
7898
|
return {
|
|
@@ -7917,10 +7962,10 @@ var resolveAuthConfig = /* @__PURE__ */ __name((config) => {
|
|
|
7917
7962
|
}
|
|
7918
7963
|
};
|
|
7919
7964
|
if (!finalConfig.jwt.accessSecret) {
|
|
7920
|
-
throw
|
|
7965
|
+
throw Err17.configRequired("auth", "JWT_ACCESS_SECRET");
|
|
7921
7966
|
}
|
|
7922
7967
|
if (!finalConfig.jwt.refreshSecret) {
|
|
7923
|
-
throw
|
|
7968
|
+
throw Err17.configRequired("auth", "JWT_REFRESH_SECRET");
|
|
7924
7969
|
}
|
|
7925
7970
|
return finalConfig;
|
|
7926
7971
|
}, "resolveAuthConfig");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "najm-auth",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "Authentication and authorization library for najm framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -92,9 +92,9 @@
|
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"bcryptjs": "^3.0.2",
|
|
94
94
|
"najm-cookies": "^2.0.2",
|
|
95
|
-
"najm-core": "^
|
|
95
|
+
"najm-core": "^3.0.0",
|
|
96
96
|
"najm-database": "^2.0.4",
|
|
97
|
-
"najm-guard": "^2.0
|
|
97
|
+
"najm-guard": "^2.1.0",
|
|
98
98
|
"najm-i18n": "^2.1.2",
|
|
99
99
|
"najm-cache": "^2.2.0",
|
|
100
100
|
"najm-email": "^2.0.4",
|