@loopstack/auth 0.5.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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/auth.module-definition.d.ts +2 -0
- package/dist/auth.module-definition.js +7 -0
- package/dist/auth.module-definition.js.map +1 -0
- package/dist/auth.module.d.ts +5 -0
- package/dist/auth.module.js +69 -0
- package/dist/auth.module.js.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/controllers/auth.controller.d.ts +25 -0
- package/dist/controllers/auth.controller.js +195 -0
- package/dist/controllers/auth.controller.js.map +1 -0
- package/dist/controllers/index.d.ts +1 -0
- package/dist/controllers/index.js +18 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/decorators/current-user.decorator.d.ts +1 -0
- package/dist/decorators/current-user.decorator.js +9 -0
- package/dist/decorators/current-user.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.js +20 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/public.decorator.d.ts +1 -0
- package/dist/decorators/public.decorator.js +8 -0
- package/dist/decorators/public.decorator.js.map +1 -0
- package/dist/decorators/roles.decorator.d.ts +1 -0
- package/dist/decorators/roles.decorator.js +8 -0
- package/dist/decorators/roles.decorator.js.map +1 -0
- package/dist/guards/dev-auth.guard.d.ts +4 -0
- package/dist/guards/dev-auth.guard.js +18 -0
- package/dist/guards/dev-auth.guard.js.map +1 -0
- package/dist/guards/google-auth.guard.d.ts +5 -0
- package/dist/guards/google-auth.guard.js +23 -0
- package/dist/guards/google-auth.guard.js.map +1 -0
- package/dist/guards/index.d.ts +5 -0
- package/dist/guards/index.js +22 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/jwt-auth.guard.d.ts +9 -0
- package/dist/guards/jwt-auth.guard.js +39 -0
- package/dist/guards/jwt-auth.guard.js.map +1 -0
- package/dist/guards/local-auth.guard.d.ts +4 -0
- package/dist/guards/local-auth.guard.js +18 -0
- package/dist/guards/local-auth.guard.js.map +1 -0
- package/dist/guards/roles.guard.d.ts +7 -0
- package/dist/guards/roles.guard.js +38 -0
- package/dist/guards/roles.guard.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/auth-config.interface.d.ts +21 -0
- package/dist/interfaces/auth-config.interface.js +3 -0
- package/dist/interfaces/auth-config.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +19 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/module-options.interface.d.ts +2 -0
- package/dist/interfaces/module-options.interface.js +3 -0
- package/dist/interfaces/module-options.interface.js.map +1 -0
- package/dist/repositories/auth-provider.repository.d.ts +9 -0
- package/dist/repositories/auth-provider.repository.js +47 -0
- package/dist/repositories/auth-provider.repository.js.map +1 -0
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.js +18 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/user.repository.d.ts +10 -0
- package/dist/repositories/user.repository.js +52 -0
- package/dist/repositories/user.repository.js.map +1 -0
- package/dist/services/auth.service.d.ts +20 -0
- package/dist/services/auth.service.js +110 -0
- package/dist/services/auth.service.js.map +1 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +21 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/oauth.service.d.ts +15 -0
- package/dist/services/oauth.service.js +91 -0
- package/dist/services/oauth.service.js.map +1 -0
- package/dist/services/password.service.d.ts +5 -0
- package/dist/services/password.service.js +25 -0
- package/dist/services/password.service.js.map +1 -0
- package/dist/services/token.service.d.ts +13 -0
- package/dist/services/token.service.js +63 -0
- package/dist/services/token.service.js.map +1 -0
- package/dist/strategies/dev.strategy.d.ts +9 -0
- package/dist/strategies/dev.strategy.js +36 -0
- package/dist/strategies/dev.strategy.js.map +1 -0
- package/dist/strategies/google.strategy.d.ts +8 -0
- package/dist/strategies/google.strategy.js +51 -0
- package/dist/strategies/google.strategy.js.map +1 -0
- package/dist/strategies/index.d.ts +4 -0
- package/dist/strategies/index.js +21 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/jwt.strategy.d.ts +13 -0
- package/dist/strategies/jwt.strategy.js +52 -0
- package/dist/strategies/jwt.strategy.js.map +1 -0
- package/dist/strategies/local.strategy.d.ts +8 -0
- package/dist/strategies/local.strategy.js +36 -0
- package/dist/strategies/local.strategy.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OAuthService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const token_service_1 = require("./token.service");
|
|
15
|
+
const auth_service_1 = require("./auth.service");
|
|
16
|
+
const repositories_1 = require("../repositories");
|
|
17
|
+
const auth_provider_repository_1 = require("../repositories/auth-provider.repository");
|
|
18
|
+
let OAuthService = class OAuthService {
|
|
19
|
+
userRepository;
|
|
20
|
+
authProviderRepository;
|
|
21
|
+
tokenService;
|
|
22
|
+
authService;
|
|
23
|
+
constructor(userRepository, authProviderRepository, tokenService, authService) {
|
|
24
|
+
this.userRepository = userRepository;
|
|
25
|
+
this.authProviderRepository = authProviderRepository;
|
|
26
|
+
this.tokenService = tokenService;
|
|
27
|
+
this.authService = authService;
|
|
28
|
+
}
|
|
29
|
+
async handleOAuthLogin(profile) {
|
|
30
|
+
let authProvider = await this.authProviderRepository.findByProviderAndId(profile.provider, profile.id);
|
|
31
|
+
let user;
|
|
32
|
+
if (authProvider) {
|
|
33
|
+
user = authProvider.user;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
user = await this.userRepository.findByEmail(profile.email);
|
|
37
|
+
if (!user) {
|
|
38
|
+
user = await this.userRepository.create({
|
|
39
|
+
email: profile.email,
|
|
40
|
+
firstName: profile.firstName || profile.displayName?.split(' ')[0] || '',
|
|
41
|
+
lastName: profile.lastName || profile.displayName?.split(' ').slice(1).join(' ') || '',
|
|
42
|
+
isActive: true,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
await this.authProviderRepository.create({
|
|
46
|
+
provider: profile.provider,
|
|
47
|
+
providerId: profile.id,
|
|
48
|
+
user: user,
|
|
49
|
+
profile: profile._json,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const tokens = await this.tokenService.generateTokens(user);
|
|
53
|
+
return {
|
|
54
|
+
...tokens,
|
|
55
|
+
tokenType: 'Bearer',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async linkProvider(userId, linkProviderDto) {
|
|
59
|
+
const user = await this.userRepository.findById(userId);
|
|
60
|
+
if (!user) {
|
|
61
|
+
throw new common_1.NotFoundException('User not found');
|
|
62
|
+
}
|
|
63
|
+
const existingProvider = await this.authProviderRepository.findByProviderAndId(linkProviderDto.provider, linkProviderDto.code);
|
|
64
|
+
if (existingProvider) {
|
|
65
|
+
throw new common_1.ConflictException('This provider is already linked to another account');
|
|
66
|
+
}
|
|
67
|
+
await this.authProviderRepository.create({
|
|
68
|
+
provider: linkProviderDto.provider,
|
|
69
|
+
providerId: linkProviderDto.code,
|
|
70
|
+
user: user,
|
|
71
|
+
});
|
|
72
|
+
const updatedUser = await this.userRepository.findById(userId);
|
|
73
|
+
if (!updatedUser) {
|
|
74
|
+
throw new common_1.NotFoundException('User not found');
|
|
75
|
+
}
|
|
76
|
+
return this.authService.mapUserToResponse(updatedUser);
|
|
77
|
+
}
|
|
78
|
+
async getUserProviders(userId) {
|
|
79
|
+
const providers = await this.authProviderRepository.findByUserId(userId);
|
|
80
|
+
return providers.map(p => p.provider);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.OAuthService = OAuthService;
|
|
84
|
+
exports.OAuthService = OAuthService = __decorate([
|
|
85
|
+
(0, common_1.Injectable)(),
|
|
86
|
+
__metadata("design:paramtypes", [repositories_1.UserRepository,
|
|
87
|
+
auth_provider_repository_1.AuthProviderRepository,
|
|
88
|
+
token_service_1.TokenService,
|
|
89
|
+
auth_service_1.AuthService])
|
|
90
|
+
], OAuthService);
|
|
91
|
+
//# sourceMappingURL=oauth.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.service.js","sourceRoot":"","sources":["../../src/services/oauth.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PasswordService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const bcrypt = require("bcrypt");
|
|
12
|
+
let PasswordService = class PasswordService {
|
|
13
|
+
saltRounds = 10;
|
|
14
|
+
async hash(password) {
|
|
15
|
+
return bcrypt.hash(password, this.saltRounds);
|
|
16
|
+
}
|
|
17
|
+
async compare(password, hash) {
|
|
18
|
+
return bcrypt.compare(password, hash);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.PasswordService = PasswordService;
|
|
22
|
+
exports.PasswordService = PasswordService = __decorate([
|
|
23
|
+
(0, common_1.Injectable)()
|
|
24
|
+
], PasswordService);
|
|
25
|
+
//# sourceMappingURL=password.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.service.js","sourceRoot":"","sources":["../../src/services/password.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,iCAAiC;AAG1B,IAAM,eAAe,GAArB,MAAM,eAAe;IACT,UAAU,GAAG,EAAE,CAAC;IAEjC,KAAK,CAAC,IAAI,CAAC,QAAgB;QACzB,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAAgB,EAAE,IAAY;QAC1C,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;AAVY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;GACA,eAAe,CAU3B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JwtService } from '@nestjs/jwt';
|
|
2
|
+
import { AuthConfig } from '../interfaces';
|
|
3
|
+
export declare class TokenService {
|
|
4
|
+
private config;
|
|
5
|
+
private jwtService;
|
|
6
|
+
constructor(config: AuthConfig, jwtService: JwtService);
|
|
7
|
+
generateTokens(user: any): Promise<{
|
|
8
|
+
accessToken: string;
|
|
9
|
+
refreshToken: string;
|
|
10
|
+
expiresIn: number;
|
|
11
|
+
}>;
|
|
12
|
+
private getExpiresInSeconds;
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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.TokenService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
let TokenService = class TokenService {
|
|
20
|
+
config;
|
|
21
|
+
jwtService;
|
|
22
|
+
constructor(config, jwtService) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.jwtService = jwtService;
|
|
25
|
+
}
|
|
26
|
+
async generateTokens(user) {
|
|
27
|
+
const payload = {
|
|
28
|
+
sub: user.id || null,
|
|
29
|
+
email: user.email,
|
|
30
|
+
roles: user.roles?.map(role => typeof role === 'string' ? role : role.name) || [],
|
|
31
|
+
};
|
|
32
|
+
const [accessToken, refreshToken] = await Promise.all([
|
|
33
|
+
this.jwtService.signAsync(payload),
|
|
34
|
+
this.jwtService.signAsync(payload, {
|
|
35
|
+
secret: this.config.jwt?.refreshSecret || this.config.jwt?.secret,
|
|
36
|
+
expiresIn: this.config.jwt?.refreshExpiresIn || '7d',
|
|
37
|
+
}),
|
|
38
|
+
]);
|
|
39
|
+
return {
|
|
40
|
+
accessToken,
|
|
41
|
+
refreshToken,
|
|
42
|
+
expiresIn: this.getExpiresInSeconds(this.config.jwt?.expiresIn || '1h'),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
getExpiresInSeconds(expiresIn) {
|
|
46
|
+
const unit = expiresIn.slice(-1);
|
|
47
|
+
const value = parseInt(expiresIn.slice(0, -1));
|
|
48
|
+
switch (unit) {
|
|
49
|
+
case 'h': return value * 3600;
|
|
50
|
+
case 'd': return value * 86400;
|
|
51
|
+
case 'm': return value * 60;
|
|
52
|
+
case 's': return value;
|
|
53
|
+
default: return 3600;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.TokenService = TokenService;
|
|
58
|
+
exports.TokenService = TokenService = __decorate([
|
|
59
|
+
(0, common_1.Injectable)(),
|
|
60
|
+
__param(0, (0, common_1.Inject)(constants_1.AUTH_CONFIG)),
|
|
61
|
+
__metadata("design:paramtypes", [Object, jwt_1.JwtService])
|
|
62
|
+
], TokenService);
|
|
63
|
+
//# sourceMappingURL=token.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.service.js","sourceRoot":"","sources":["../../src/services/token.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,qCAAyC;AAEzC,4CAA2C;AAIpC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEQ;IACrB;IAFV,YAC+B,MAAkB,EACvC,UAAsB;QADD,WAAM,GAAN,MAAM,CAAY;QACvC,eAAU,GAAV,UAAU,CAAY;IAC7B,CAAC;IAEJ,KAAK,CAAC,cAAc,CAAC,IAAS;QAC5B,MAAM,OAAO,GAAwB;YACnC,GAAG,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI;YACpB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;SAClF,CAAC;QAEF,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACpD,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC;YAClC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,EAAE;gBACjC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM;gBACjE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,gBAAgB,IAAI,IAAI;aACrD,CAAC;SACH,CAAC,CAAC;QAEH,OAAO;YACL,WAAW;YACX,YAAY;YACZ,SAAS,EAAE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,IAAI,IAAI,CAAC;SACxE,CAAC;IACJ,CAAC;IAEO,mBAAmB,CAAC,SAAiB;QAC3C,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAE/C,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,GAAG,CAAC,CAAC,OAAO,KAAK,GAAG,IAAI,CAAC;YAC9B,KAAK,GAAG,CAAC,CAAC,OAAO,KAAK,GAAG,KAAK,CAAC;YAC/B,KAAK,GAAG,CAAC,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;YAC5B,KAAK,GAAG,CAAC,CAAC,OAAO,KAAK,CAAC;YACvB,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;QACvB,CAAC;IACH,CAAC;CACF,CAAA;AAxCY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,uBAAW,CAAC,CAAA;6CACA,gBAAU;GAHrB,YAAY,CAwCxB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Strategy } from 'passport-custom';
|
|
2
|
+
declare const DevStrategy_base: new () => Strategy & {
|
|
3
|
+
validate(...args: any[]): unknown;
|
|
4
|
+
};
|
|
5
|
+
export declare class DevStrategy extends DevStrategy_base {
|
|
6
|
+
constructor();
|
|
7
|
+
validate(req: Request): Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DevStrategy = void 0;
|
|
13
|
+
const passport_1 = require("@nestjs/passport");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const passport_custom_1 = require("passport-custom");
|
|
16
|
+
let DevStrategy = class DevStrategy extends (0, passport_1.PassportStrategy)(passport_custom_1.Strategy, 'dev') {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
async validate(req) {
|
|
21
|
+
return {
|
|
22
|
+
id: null,
|
|
23
|
+
email: 'dev@localhost',
|
|
24
|
+
firstName: 'Dev',
|
|
25
|
+
lastName: 'User',
|
|
26
|
+
roles: [],
|
|
27
|
+
isActive: true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.DevStrategy = DevStrategy;
|
|
32
|
+
exports.DevStrategy = DevStrategy = __decorate([
|
|
33
|
+
(0, common_1.Injectable)(),
|
|
34
|
+
__metadata("design:paramtypes", [])
|
|
35
|
+
], DevStrategy);
|
|
36
|
+
//# sourceMappingURL=dev.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.strategy.js","sourceRoot":"","sources":["../../src/strategies/dev.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAoD;AACpD,2CAA4C;AAC5C,qDAA2C;AAGpC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,0BAAQ,EAAE,KAAK,CAAC;IAChE;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAY;QACzB,OAAO;YACL,EAAE,EAAE,IAAI;YACR,KAAK,EAAE,eAAe;YACtB,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;CACF,CAAA;AAfY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;;GACA,WAAW,CAevB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VerifyCallback } from 'passport-google-oauth20';
|
|
2
|
+
import { AuthConfig } from '../interfaces';
|
|
3
|
+
declare const GoogleStrategy_base: new (...args: any) => any;
|
|
4
|
+
export declare class GoogleStrategy extends GoogleStrategy_base {
|
|
5
|
+
constructor(config: AuthConfig);
|
|
6
|
+
validate(accessToken: string, refreshToken: string, profile: any, done: VerifyCallback): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
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.GoogleStrategy = void 0;
|
|
16
|
+
const passport_1 = require("@nestjs/passport");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
const passport_google_oauth20_1 = require("passport-google-oauth20");
|
|
20
|
+
let GoogleStrategy = class GoogleStrategy extends (0, passport_1.PassportStrategy)(passport_google_oauth20_1.Strategy, 'google') {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
super({
|
|
23
|
+
clientID: config.oauth?.google?.clientId,
|
|
24
|
+
clientSecret: config.oauth?.google?.clientSecret,
|
|
25
|
+
callbackURL: config.oauth?.google?.callbackUrl,
|
|
26
|
+
scope: config.oauth?.google?.scope || ['email', 'profile'],
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async validate(accessToken, refreshToken, profile, done) {
|
|
30
|
+
const { id, name, emails, photos } = profile;
|
|
31
|
+
const user = {
|
|
32
|
+
id,
|
|
33
|
+
email: emails[0].value,
|
|
34
|
+
firstName: name.givenName,
|
|
35
|
+
lastName: name.familyName,
|
|
36
|
+
displayName: profile.displayName,
|
|
37
|
+
photos,
|
|
38
|
+
provider: 'google',
|
|
39
|
+
_raw: profile._raw,
|
|
40
|
+
_json: profile._json,
|
|
41
|
+
};
|
|
42
|
+
done(null, user);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.GoogleStrategy = GoogleStrategy;
|
|
46
|
+
exports.GoogleStrategy = GoogleStrategy = __decorate([
|
|
47
|
+
(0, common_1.Injectable)(),
|
|
48
|
+
__param(0, (0, common_1.Inject)(constants_1.AUTH_CONFIG)),
|
|
49
|
+
__metadata("design:paramtypes", [Object])
|
|
50
|
+
], GoogleStrategy);
|
|
51
|
+
//# sourceMappingURL=google.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.strategy.js","sourceRoot":"","sources":["../../src/strategies/google.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,2CAAoD;AACpD,4CAA2C;AAC3C,qEAAmE;AAK5D,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,IAAA,2BAAgB,EAAC,kCAAQ,EAAE,QAAQ,CAAC;IACtE,YAAiC,MAAkB;QACjD,KAAK,CAAC;YACJ,QAAQ,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ;YACxC,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY;YAChD,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW;YAC9C,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;SAC3D,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,WAAmB,EACnB,YAAoB,EACpB,OAAY,EACZ,IAAoB;QAEpB,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE7C,MAAM,IAAI,GAA0B;YAClC,EAAE;YACF,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;YACtB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,UAAU;YACzB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,MAAM;YACN,QAAQ,EAAE,QAAQ;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC;QAEF,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnB,CAAC;CACF,CAAA;AAhCY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,eAAM,EAAC,uBAAW,CAAC,CAAA;;GADrB,cAAc,CAgC1B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./local.strategy"), exports);
|
|
19
|
+
__exportStar(require("./google.strategy"), exports);
|
|
20
|
+
__exportStar(require("./dev.strategy"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/strategies/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,mDAAgC;AAChC,oDAAiC;AACjC,iDAA8B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthConfig } from '../interfaces';
|
|
2
|
+
import { JwtPayloadInterface } from '@loopstack/shared';
|
|
3
|
+
declare const JwtStrategy_base: new (...args: any) => any;
|
|
4
|
+
export declare class JwtStrategy extends JwtStrategy_base {
|
|
5
|
+
constructor(config: AuthConfig);
|
|
6
|
+
private static extractJWTFromCookie;
|
|
7
|
+
validate(payload: JwtPayloadInterface): Promise<{
|
|
8
|
+
userId: string;
|
|
9
|
+
email: string;
|
|
10
|
+
roles: string[];
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
var JwtStrategy_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.JwtStrategy = void 0;
|
|
17
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
18
|
+
const passport_1 = require("@nestjs/passport");
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const constants_1 = require("../constants");
|
|
21
|
+
let JwtStrategy = JwtStrategy_1 = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
22
|
+
constructor(config) {
|
|
23
|
+
super({
|
|
24
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromExtractors([
|
|
25
|
+
JwtStrategy_1.extractJWTFromCookie,
|
|
26
|
+
passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
27
|
+
]),
|
|
28
|
+
ignoreExpiration: false,
|
|
29
|
+
secretOrKey: config.jwt?.secret,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static extractJWTFromCookie(req) {
|
|
33
|
+
if (req.cookies && req.cookies.accessToken) {
|
|
34
|
+
return req.cookies.accessToken;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
async validate(payload) {
|
|
39
|
+
return {
|
|
40
|
+
userId: payload.sub,
|
|
41
|
+
email: payload.email,
|
|
42
|
+
roles: payload.roles,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.JwtStrategy = JwtStrategy;
|
|
47
|
+
exports.JwtStrategy = JwtStrategy = JwtStrategy_1 = __decorate([
|
|
48
|
+
(0, common_1.Injectable)(),
|
|
49
|
+
__param(0, (0, common_1.Inject)(constants_1.AUTH_CONFIG)),
|
|
50
|
+
__metadata("design:paramtypes", [Object])
|
|
51
|
+
], JwtStrategy);
|
|
52
|
+
//# sourceMappingURL=jwt.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../../src/strategies/jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,+CAAoD;AACpD,2CAAoD;AAGpD,4CAA2C;AAIpC,IAAM,WAAW,mBAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD,YAAiC,MAAkB;QACjD,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,cAAc,CAAC;gBACxC,aAAW,CAAC,oBAAoB;gBAChC,yBAAU,CAAC,2BAA2B,EAAE;aACzC,CAAC;YACF,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM;SAChC,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,GAAY;QAC9C,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAA4B;QACzC,OAAO;YACL,MAAM,EAAE,OAAO,CAAC,GAAG;YACnB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC;IACJ,CAAC;CACF,CAAA;AA1BY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,eAAM,EAAC,uBAAW,CAAC,CAAA;;GADrB,WAAW,CA0BvB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AuthService } from '../services';
|
|
2
|
+
declare const LocalStrategy_base: new (...args: any) => any;
|
|
3
|
+
export declare class LocalStrategy extends LocalStrategy_base {
|
|
4
|
+
private authService;
|
|
5
|
+
constructor(authService: AuthService);
|
|
6
|
+
validate(email: string, password: string): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LocalStrategy = void 0;
|
|
13
|
+
const passport_local_1 = require("passport-local");
|
|
14
|
+
const passport_1 = require("@nestjs/passport");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const services_1 = require("../services");
|
|
17
|
+
let LocalStrategy = class LocalStrategy extends (0, passport_1.PassportStrategy)(passport_local_1.Strategy) {
|
|
18
|
+
authService;
|
|
19
|
+
constructor(authService) {
|
|
20
|
+
super({ usernameField: 'email' });
|
|
21
|
+
this.authService = authService;
|
|
22
|
+
}
|
|
23
|
+
async validate(email, password) {
|
|
24
|
+
const user = await this.authService.validateUser(email, password);
|
|
25
|
+
if (!user) {
|
|
26
|
+
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
27
|
+
}
|
|
28
|
+
return user;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.LocalStrategy = LocalStrategy;
|
|
32
|
+
exports.LocalStrategy = LocalStrategy = __decorate([
|
|
33
|
+
(0, common_1.Injectable)(),
|
|
34
|
+
__metadata("design:paramtypes", [services_1.AuthService])
|
|
35
|
+
], LocalStrategy);
|
|
36
|
+
//# sourceMappingURL=local.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.strategy.js","sourceRoot":"","sources":["../../src/strategies/local.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA0C;AAC1C,+CAAoD;AACpD,2CAAmE;AACnE,0CAA0C;AAGnC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,IAAA,2BAAgB,EAAC,yBAAQ,CAAC;IACvC;IAApB,YAAoB,WAAwB;QAC1C,KAAK,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;QADhB,gBAAW,GAAX,WAAW,CAAa;IAE5C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAa,EAAE,QAAgB;QAC5C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAZY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAEsB,sBAAW;GADjC,aAAa,CAYzB"}
|