@codecanva/nest-auth 0.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/README.md +164 -0
- package/dist/auth.constants.d.ts +8 -0
- package/dist/auth.constants.d.ts.map +1 -0
- package/dist/auth.constants.js +11 -0
- package/dist/auth.constants.js.map +1 -0
- package/dist/auth.module.d.ts +6 -0
- package/dist/auth.module.d.ts.map +1 -0
- package/dist/auth.module.js +75 -0
- package/dist/auth.module.js.map +1 -0
- package/dist/auth.service.d.ts +25 -0
- package/dist/auth.service.d.ts.map +1 -0
- package/dist/auth.service.js +108 -0
- package/dist/auth.service.js.map +1 -0
- package/dist/decorators/current-user.decorator.d.ts +3 -0
- package/dist/decorators/current-user.decorator.d.ts.map +1 -0
- package/dist/decorators/current-user.decorator.js +12 -0
- package/dist/decorators/current-user.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +19 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/public.decorator.d.ts +2 -0
- package/dist/decorators/public.decorator.d.ts.map +1 -0
- package/dist/decorators/public.decorator.js +8 -0
- package/dist/decorators/public.decorator.js.map +1 -0
- package/dist/dto/index.d.ts +3 -0
- package/dist/dto/index.d.ts.map +1 -0
- package/dist/dto/index.js +19 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/dto/login.dto.d.ts +5 -0
- package/dist/dto/login.dto.d.ts.map +1 -0
- package/dist/dto/login.dto.js +28 -0
- package/dist/dto/login.dto.js.map +1 -0
- package/dist/dto/refresh-token.dto.d.ts +4 -0
- package/dist/dto/refresh-token.dto.d.ts.map +1 -0
- package/dist/dto/refresh-token.dto.js +23 -0
- package/dist/dto/refresh-token.dto.js.map +1 -0
- package/dist/errors/auth.errors.d.ts +19 -0
- package/dist/errors/auth.errors.d.ts.map +1 -0
- package/dist/errors/auth.errors.js +41 -0
- package/dist/errors/auth.errors.js.map +1 -0
- package/dist/guards/index.d.ts +3 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +19 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/jwt-auth.guard.d.ts +10 -0
- package/dist/guards/jwt-auth.guard.d.ts.map +1 -0
- package/dist/guards/jwt-auth.guard.js +38 -0
- package/dist/guards/jwt-auth.guard.js.map +1 -0
- package/dist/guards/refresh-auth.guard.d.ts +5 -0
- package/dist/guards/refresh-auth.guard.d.ts.map +1 -0
- package/dist/guards/refresh-auth.guard.js +19 -0
- package/dist/guards/refresh-auth.guard.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/auth-module-options.interface.d.ts +38 -0
- package/dist/interfaces/auth-module-options.interface.d.ts.map +1 -0
- package/dist/interfaces/auth-module-options.interface.js +3 -0
- package/dist/interfaces/auth-module-options.interface.js.map +1 -0
- package/dist/interfaces/auth-user.interface.d.ts +8 -0
- package/dist/interfaces/auth-user.interface.d.ts.map +1 -0
- package/dist/interfaces/auth-user.interface.js +3 -0
- package/dist/interfaces/auth-user.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +6 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +22 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/jwt-payload.interface.d.ts +14 -0
- package/dist/interfaces/jwt-payload.interface.d.ts.map +1 -0
- package/dist/interfaces/jwt-payload.interface.js +3 -0
- package/dist/interfaces/jwt-payload.interface.js.map +1 -0
- package/dist/interfaces/refresh-token-store.interface.d.ts +34 -0
- package/dist/interfaces/refresh-token-store.interface.d.ts.map +1 -0
- package/dist/interfaces/refresh-token-store.interface.js +3 -0
- package/dist/interfaces/refresh-token-store.interface.js.map +1 -0
- package/dist/interfaces/user-validator.interface.d.ts +11 -0
- package/dist/interfaces/user-validator.interface.d.ts.map +1 -0
- package/dist/interfaces/user-validator.interface.js +3 -0
- package/dist/interfaces/user-validator.interface.js.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +18 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/token.service.d.ts +23 -0
- package/dist/services/token.service.d.ts.map +1 -0
- package/dist/services/token.service.js +94 -0
- package/dist/services/token.service.js.map +1 -0
- package/dist/strategies/index.d.ts +3 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +19 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/jwt.strategy.d.ts +15 -0
- package/dist/strategies/jwt.strategy.d.ts.map +1 -0
- package/dist/strategies/jwt.strategy.js +50 -0
- package/dist/strategies/jwt.strategy.js.map +1 -0
- package/dist/strategies/refresh.strategy.d.ts +18 -0
- package/dist/strategies/refresh.strategy.d.ts.map +1 -0
- package/dist/strategies/refresh.strategy.js +65 -0
- package/dist/strategies/refresh.strategy.js.map +1 -0
- package/dist/utils/extract-token.d.ts +2 -0
- package/dist/utils/extract-token.d.ts.map +1 -0
- package/dist/utils/extract-token.js +12 -0
- package/dist/utils/extract-token.js.map +1 -0
- package/dist/utils/hash-token.d.ts +3 -0
- package/dist/utils/hash-token.d.ts.map +1 -0
- package/dist/utils/hash-token.js +16 -0
- package/dist/utils/hash-token.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.service.js","sourceRoot":"","sources":["../../src/lib/services/token.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,qCAIqB;AACrB,sDAA4E;AAUrE,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEJ;IAEA;IAHnB,YACmB,GAAe,EAEf,OAA0B;QAF1B,QAAG,GAAH,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,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7C,MAAM,WAAW,GAA2B;QAC1C,CAAC,EAAE,CAAC;QACJ,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,KAAK;QACR,CAAC,EAAE,MAAM;KACV,CAAC;IACF,OAAO,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/strategies/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./jwt.strategy"), exports);
|
|
18
|
+
__exportStar(require("./refresh.strategy"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/strategies/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,qDAAmC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Strategy } from 'passport-jwt';
|
|
2
|
+
import type { AuthModuleOptions } from '../interfaces/auth-module-options.interface';
|
|
3
|
+
import type { AuthUser } from '../interfaces/auth-user.interface';
|
|
4
|
+
import type { JwtPayload } from '../interfaces/jwt-payload.interface';
|
|
5
|
+
import type { UserValidator } from '../interfaces/user-validator.interface';
|
|
6
|
+
declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
|
|
7
|
+
validate(...args: any[]): unknown;
|
|
8
|
+
};
|
|
9
|
+
export declare class JwtStrategy extends JwtStrategy_base {
|
|
10
|
+
private readonly validator;
|
|
11
|
+
constructor(options: AuthModuleOptions, validator: UserValidator);
|
|
12
|
+
validate(payload: JwtPayload): Promise<AuthUser>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=jwt.strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.strategy.d.ts","sourceRoot":"","sources":["../../src/lib/strategies/jwt.strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,QAAQ,EAAE,MAAM,cAAc,CAAC;AAMpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;;;;AAE5E,qBACa,WAAY,SAAQ,gBAA6C;IAGlD,OAAO,CAAC,QAAQ,CAAC,SAAS;gBADrB,OAAO,EAAE,iBAAiB,EACd,SAAS,EAAE,aAAa;IAe7D,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;CAKvD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.JwtStrategy = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const passport_1 = require("@nestjs/passport");
|
|
18
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
19
|
+
const auth_constants_1 = require("../auth.constants");
|
|
20
|
+
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, auth_constants_1.JWT_STRATEGY_NAME) {
|
|
21
|
+
validator;
|
|
22
|
+
constructor(options, validator) {
|
|
23
|
+
super({
|
|
24
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
25
|
+
secretOrKey: options.accessSecret,
|
|
26
|
+
ignoreExpiration: false,
|
|
27
|
+
passReqToCallback: false,
|
|
28
|
+
...(options.issuer ? { issuer: options.issuer } : {}),
|
|
29
|
+
...(options.audience ? { audience: options.audience } : {}),
|
|
30
|
+
jsonWebTokenOptions: {
|
|
31
|
+
clockTolerance: options.clockTolerance ?? 5,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
this.validator = validator;
|
|
35
|
+
}
|
|
36
|
+
async validate(payload) {
|
|
37
|
+
const user = await this.validator.findById(payload.sub);
|
|
38
|
+
if (!user)
|
|
39
|
+
throw new common_1.UnauthorizedException();
|
|
40
|
+
return user;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.JwtStrategy = JwtStrategy;
|
|
44
|
+
exports.JwtStrategy = JwtStrategy = __decorate([
|
|
45
|
+
(0, common_1.Injectable)(),
|
|
46
|
+
__param(0, (0, common_1.Inject)(auth_constants_1.AUTH_MODULE_OPTIONS)),
|
|
47
|
+
__param(1, (0, common_1.Inject)(auth_constants_1.USER_VALIDATOR)),
|
|
48
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
49
|
+
], JwtStrategy);
|
|
50
|
+
//# sourceMappingURL=jwt.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../../src/lib/strategies/jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,+CAAoD;AACpD,+CAAoD;AACpD,sDAI2B;AAOpB,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,EAAE,kCAAiB,CAAC;IAGjC;IAF3C,YAC+B,OAA0B,EACd,SAAwB;QAEjE,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,WAAW,EAAE,OAAO,CAAC,YAAY;YACjC,gBAAgB,EAAE,KAAK;YACvB,iBAAiB,EAAE,KAAK;YACxB,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrD,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,mBAAmB,EAAE;gBACnB,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC;aAC5C;SACF,CAAC,CAAC;QAZsC,cAAS,GAAT,SAAS,CAAe;IAanE,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAmB;QAChC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,8BAAqB,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAvBY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,oCAAmB,CAAC,CAAA;IAC3B,WAAA,IAAA,eAAM,EAAC,+BAAc,CAAC,CAAA;;GAHd,WAAW,CAuBvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import { Strategy } from 'passport-jwt';
|
|
3
|
+
import type { AuthModuleOptions } from '../interfaces/auth-module-options.interface';
|
|
4
|
+
import type { RefreshJwtPayload } from '../interfaces/jwt-payload.interface';
|
|
5
|
+
export interface RefreshRequestUser {
|
|
6
|
+
userId: string | number;
|
|
7
|
+
jti: string;
|
|
8
|
+
refreshToken: string;
|
|
9
|
+
}
|
|
10
|
+
declare const RefreshStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
|
|
11
|
+
validate(...args: any[]): unknown;
|
|
12
|
+
};
|
|
13
|
+
export declare class RefreshStrategy extends RefreshStrategy_base {
|
|
14
|
+
constructor(options: AuthModuleOptions);
|
|
15
|
+
validate(req: Request, payload: RefreshJwtPayload): RefreshRequestUser;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=refresh.strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.strategy.d.ts","sourceRoot":"","sources":["../../src/lib/strategies/refresh.strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAc,QAAQ,EAAE,MAAM,cAAc,CAAC;AAMpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAE7E,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;CACtB;;;;AAOD,qBACa,eAAgB,SAAQ,oBAGpC;gBAC0C,OAAO,EAAE,iBAAiB;IAiBnE,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB,GAAG,kBAAkB;CAUvE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.RefreshStrategy = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const passport_1 = require("@nestjs/passport");
|
|
18
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
19
|
+
const auth_constants_1 = require("../auth.constants");
|
|
20
|
+
const fromBody = (req) => {
|
|
21
|
+
const body = (req?.body ?? {});
|
|
22
|
+
return typeof body.refreshToken === 'string' ? body.refreshToken : null;
|
|
23
|
+
};
|
|
24
|
+
let RefreshStrategy = class RefreshStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, auth_constants_1.REFRESH_STRATEGY_NAME) {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
super({
|
|
27
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromExtractors([
|
|
28
|
+
fromBody,
|
|
29
|
+
passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
30
|
+
]),
|
|
31
|
+
secretOrKey: options.refreshSecret,
|
|
32
|
+
ignoreExpiration: false,
|
|
33
|
+
passReqToCallback: true,
|
|
34
|
+
...(options.issuer ? { issuer: options.issuer } : {}),
|
|
35
|
+
...(options.audience ? { audience: options.audience } : {}),
|
|
36
|
+
jsonWebTokenOptions: {
|
|
37
|
+
clockTolerance: options.clockTolerance ?? 5,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
validate(req, payload) {
|
|
42
|
+
if (payload?.typ !== auth_constants_1.REFRESH_TOKEN_TYPE) {
|
|
43
|
+
throw new common_1.UnauthorizedException('Not a refresh token');
|
|
44
|
+
}
|
|
45
|
+
const refreshToken = fromBody(req) ?? extractFromHeader(req);
|
|
46
|
+
if (!refreshToken) {
|
|
47
|
+
throw new common_1.UnauthorizedException('Missing refresh token');
|
|
48
|
+
}
|
|
49
|
+
return { userId: payload.sub, jti: payload.jti, refreshToken };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.RefreshStrategy = RefreshStrategy;
|
|
53
|
+
exports.RefreshStrategy = RefreshStrategy = __decorate([
|
|
54
|
+
(0, common_1.Injectable)(),
|
|
55
|
+
__param(0, (0, common_1.Inject)(auth_constants_1.AUTH_MODULE_OPTIONS)),
|
|
56
|
+
__metadata("design:paramtypes", [Object])
|
|
57
|
+
], RefreshStrategy);
|
|
58
|
+
function extractFromHeader(req) {
|
|
59
|
+
const auth = req.headers?.authorization;
|
|
60
|
+
if (!auth)
|
|
61
|
+
return null;
|
|
62
|
+
const [scheme, token] = auth.split(' ');
|
|
63
|
+
return scheme?.toLowerCase() === 'bearer' && token ? token : null;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=refresh.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.strategy.js","sourceRoot":"","sources":["../../src/lib/strategies/refresh.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,+CAAoD;AAEpD,+CAAoD;AACpD,sDAI2B;AAU3B,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAiB,EAAE;IAC/C,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,CAA+B,CAAC;IAC7D,OAAO,OAAO,IAAI,CAAC,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1E,CAAC,CAAC;AAGK,IAAM,eAAe,GAArB,MAAM,eAAgB,S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AJ7B,eAAe,CA+B3B;AAED,SAAS,iBAAiB,CAAC,GAAY;IACrC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC;IACxC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,MAAM,EAAE,WAAW,EAAE,KAAK,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-token.d.ts","sourceRoot":"","sources":["../../src/lib/utils/extract-token.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKtE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractBearerToken = extractBearerToken;
|
|
4
|
+
function extractBearerToken(headerValue) {
|
|
5
|
+
if (!headerValue)
|
|
6
|
+
return null;
|
|
7
|
+
const [scheme, token] = headerValue.split(' ');
|
|
8
|
+
if (!scheme || scheme.toLowerCase() !== 'bearer' || !token)
|
|
9
|
+
return null;
|
|
10
|
+
return token.trim() || null;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=extract-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-token.js","sourceRoot":"","sources":["../../src/lib/utils/extract-token.ts"],"names":[],"mappings":";;AAAA,gDAKC;AALD,SAAgB,kBAAkB,CAAC,WAAoB;IACrD,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9B,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,WAAW,EAAE,KAAK,QAAQ,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxE,OAAO,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-token.d.ts","sourceRoot":"","sources":["../../src/lib/utils/hash-token.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAKhE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashToken = hashToken;
|
|
4
|
+
exports.generateTokenId = generateTokenId;
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
function hashToken(token, pepper) {
|
|
7
|
+
const h = (0, crypto_1.createHash)('sha256');
|
|
8
|
+
h.update(token);
|
|
9
|
+
if (pepper)
|
|
10
|
+
h.update(pepper);
|
|
11
|
+
return h.digest('hex');
|
|
12
|
+
}
|
|
13
|
+
function generateTokenId() {
|
|
14
|
+
return (0, crypto_1.randomBytes)(16).toString('hex');
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=hash-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-token.js","sourceRoot":"","sources":["../../src/lib/utils/hash-token.ts"],"names":[],"mappings":";;AAEA,8BAKC;AAED,0CAEC;AAXD,mCAAiD;AAEjD,SAAgB,SAAS,CAAC,KAAa,EAAE,MAAe;IACtD,MAAM,CAAC,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChB,IAAI,MAAM;QAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED,SAAgB,eAAe;IAC7B,OAAO,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./extract-token"), exports);
|
|
18
|
+
__exportStar(require("./hash-token"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,+CAA6B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codecanva/nest-auth",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reusable NestJS authentication module with JWT access + refresh-token rotation, multi-device sessions, and pluggable persistence.",
|
|
5
|
+
"author": "codecanva",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"nestjs",
|
|
9
|
+
"auth",
|
|
10
|
+
"jwt",
|
|
11
|
+
"refresh-token",
|
|
12
|
+
"passport",
|
|
13
|
+
"authentication"
|
|
14
|
+
],
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build:lib": "rm -rf dist && tsc -p tsconfig.lib.json",
|
|
26
|
+
"build:demo": "nest build",
|
|
27
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
28
|
+
"start": "nest start",
|
|
29
|
+
"start:dev": "nest start --watch",
|
|
30
|
+
"start:debug": "nest start --debug --watch",
|
|
31
|
+
"start:prod": "node dist-demo/main",
|
|
32
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"test:watch": "jest --watch",
|
|
35
|
+
"test:cov": "jest --coverage",
|
|
36
|
+
"test:e2e": "jest --config ./test/jest-e2e.json",
|
|
37
|
+
"prepublishOnly": "npm run build:lib",
|
|
38
|
+
"publish:lib": "npm publish"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
42
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
43
|
+
"@nestjs/jwt": "^10.0.0 || ^11.0.0",
|
|
44
|
+
"@nestjs/passport": "^10.0.0 || ^11.0.0",
|
|
45
|
+
"class-transformer": "^0.5.0",
|
|
46
|
+
"class-validator": "^0.14.0",
|
|
47
|
+
"passport": "^0.7.0",
|
|
48
|
+
"passport-jwt": "^4.0.0",
|
|
49
|
+
"reflect-metadata": "^0.2.0",
|
|
50
|
+
"rxjs": "^7.8.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
55
|
+
"@eslint/js": "^9.18.0",
|
|
56
|
+
"@nestjs/cli": "^11.0.0",
|
|
57
|
+
"@nestjs/common": "^11.0.1",
|
|
58
|
+
"@nestjs/core": "^11.0.1",
|
|
59
|
+
"@nestjs/jwt": "^11.0.0",
|
|
60
|
+
"@nestjs/passport": "^11.0.5",
|
|
61
|
+
"@nestjs/platform-express": "^11.0.1",
|
|
62
|
+
"@nestjs/schematics": "^11.0.0",
|
|
63
|
+
"@nestjs/testing": "^11.0.1",
|
|
64
|
+
"@types/express": "^5.0.0",
|
|
65
|
+
"@types/jest": "^30.0.0",
|
|
66
|
+
"@types/node": "^24.0.0",
|
|
67
|
+
"@types/passport-jwt": "^4.0.1",
|
|
68
|
+
"@types/supertest": "^7.0.0",
|
|
69
|
+
"class-transformer": "^0.5.1",
|
|
70
|
+
"class-validator": "^0.14.1",
|
|
71
|
+
"eslint": "^9.18.0",
|
|
72
|
+
"eslint-config-prettier": "^10.0.1",
|
|
73
|
+
"eslint-plugin-prettier": "^5.2.2",
|
|
74
|
+
"globals": "^17.0.0",
|
|
75
|
+
"jest": "^30.0.0",
|
|
76
|
+
"passport": "^0.7.0",
|
|
77
|
+
"passport-jwt": "^4.0.1",
|
|
78
|
+
"prettier": "^3.4.2",
|
|
79
|
+
"reflect-metadata": "^0.2.2",
|
|
80
|
+
"rxjs": "^7.8.1",
|
|
81
|
+
"source-map-support": "^0.5.21",
|
|
82
|
+
"supertest": "^7.0.0",
|
|
83
|
+
"ts-jest": "^29.2.5",
|
|
84
|
+
"ts-loader": "^9.5.2",
|
|
85
|
+
"ts-node": "^10.9.2",
|
|
86
|
+
"tsconfig-paths": "^4.2.0",
|
|
87
|
+
"typescript": "^5.7.3",
|
|
88
|
+
"typescript-eslint": "^8.20.0"
|
|
89
|
+
},
|
|
90
|
+
"jest": {
|
|
91
|
+
"moduleFileExtensions": [
|
|
92
|
+
"js",
|
|
93
|
+
"json",
|
|
94
|
+
"ts"
|
|
95
|
+
],
|
|
96
|
+
"rootDir": "src",
|
|
97
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
98
|
+
"transform": {
|
|
99
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
100
|
+
},
|
|
101
|
+
"collectCoverageFrom": [
|
|
102
|
+
"**/*.(t|j)s"
|
|
103
|
+
],
|
|
104
|
+
"coverageDirectory": "../coverage",
|
|
105
|
+
"testEnvironment": "node"
|
|
106
|
+
}
|
|
107
|
+
}
|