@vynelix/nestjs-multi-auth 0.0.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 +760 -0
- package/bin/cli.js +152 -0
- package/dist/auth/auth-type.enum.d.ts +22 -0
- package/dist/auth/auth-type.enum.js +32 -0
- package/dist/auth/auth-type.enum.js.map +1 -0
- package/dist/auth/auth.controller.d.ts +70 -0
- package/dist/auth/auth.controller.js +434 -0
- package/dist/auth/auth.controller.js.map +1 -0
- package/dist/auth/auth.module.d.ts +9 -0
- package/dist/auth/auth.module.js +193 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/auth/auth.service.d.ts +180 -0
- package/dist/auth/auth.service.js +695 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/auth/core/auth-mapper.d.ts +6 -0
- package/dist/auth/core/auth-mapper.js +17 -0
- package/dist/auth/core/auth-mapper.js.map +1 -0
- package/dist/auth/core/jwt.strategy.d.ts +13 -0
- package/dist/auth/core/jwt.strategy.js +59 -0
- package/dist/auth/core/jwt.strategy.js.map +1 -0
- package/dist/auth/core/registration.d.ts +3 -0
- package/dist/auth/core/registration.js +60 -0
- package/dist/auth/core/registration.js.map +1 -0
- package/dist/auth/current-user-interface.d.ts +4 -0
- package/dist/auth/current-user-interface.js +4 -0
- package/dist/auth/current-user-interface.js.map +1 -0
- package/dist/auth/current-user.decorator.d.ts +2 -0
- package/dist/auth/current-user.decorator.js +16 -0
- package/dist/auth/current-user.decorator.js.map +1 -0
- package/dist/auth/decorator/current-user.decorator.d.ts +2 -0
- package/dist/auth/decorator/current-user.decorator.js +13 -0
- package/dist/auth/decorator/current-user.decorator.js.map +1 -0
- package/dist/auth/decorator/email-or-phone.decorator.d.ts +2 -0
- package/dist/auth/decorator/email-or-phone.decorator.js +26 -0
- package/dist/auth/decorator/email-or-phone.decorator.js.map +1 -0
- package/dist/auth/decorator/optional.decorator.d.ts +2 -0
- package/dist/auth/decorator/optional.decorator.js +9 -0
- package/dist/auth/decorator/optional.decorator.js.map +1 -0
- package/dist/auth/decorator/public.decorator.d.ts +2 -0
- package/dist/auth/decorator/public.decorator.js +9 -0
- package/dist/auth/decorator/public.decorator.js.map +1 -0
- package/dist/auth/dto/auth-response.dto.d.ts +17 -0
- package/dist/auth/dto/auth-response.dto.js +83 -0
- package/dist/auth/dto/auth-response.dto.js.map +1 -0
- package/dist/auth/dto/identifier-response.dto.d.ts +8 -0
- package/dist/auth/dto/identifier-response.dto.js +46 -0
- package/dist/auth/dto/identifier-response.dto.js.map +1 -0
- package/dist/auth/dto/login.dto.d.ts +11 -0
- package/dist/auth/dto/login.dto.js +68 -0
- package/dist/auth/dto/login.dto.js.map +1 -0
- package/dist/auth/dto/mfa.dto.d.ts +8 -0
- package/dist/auth/dto/mfa.dto.js +51 -0
- package/dist/auth/dto/mfa.dto.js.map +1 -0
- package/dist/auth/dto/oauth-provider-response.dto.d.ts +5 -0
- package/dist/auth/dto/oauth-provider-response.dto.js +30 -0
- package/dist/auth/dto/oauth-provider-response.dto.js.map +1 -0
- package/dist/auth/dto/refresh-token.dto.d.ts +3 -0
- package/dist/auth/dto/refresh-token.dto.js +28 -0
- package/dist/auth/dto/refresh-token.dto.js.map +1 -0
- package/dist/auth/dto/requests/forgot-password.dto.d.ts +5 -0
- package/dist/auth/dto/requests/forgot-password.dto.js +36 -0
- package/dist/auth/dto/requests/forgot-password.dto.js.map +1 -0
- package/dist/auth/dto/requests/login.dto.d.ts +11 -0
- package/dist/auth/dto/requests/login.dto.js +68 -0
- package/dist/auth/dto/requests/login.dto.js.map +1 -0
- package/dist/auth/dto/requests/magic-link.dto.d.ts +6 -0
- package/dist/auth/dto/requests/magic-link.dto.js +33 -0
- package/dist/auth/dto/requests/magic-link.dto.js.map +1 -0
- package/dist/auth/dto/requests/mfa.dto.d.ts +8 -0
- package/dist/auth/dto/requests/mfa.dto.js +51 -0
- package/dist/auth/dto/requests/mfa.dto.js.map +1 -0
- package/dist/auth/dto/requests/refresh-token.dto.d.ts +3 -0
- package/dist/auth/dto/requests/refresh-token.dto.js +29 -0
- package/dist/auth/dto/requests/refresh-token.dto.js.map +1 -0
- package/dist/auth/dto/requests/reset-password.dto.d.ts +5 -0
- package/dist/auth/dto/requests/reset-password.dto.js +36 -0
- package/dist/auth/dto/requests/reset-password.dto.js.map +1 -0
- package/dist/auth/dto/requests/secure-account.dto.d.ts +3 -0
- package/dist/auth/dto/requests/secure-account.dto.js +24 -0
- package/dist/auth/dto/requests/secure-account.dto.js.map +1 -0
- package/dist/auth/dto/requests/signup.dto.d.ts +13 -0
- package/dist/auth/dto/requests/signup.dto.js +70 -0
- package/dist/auth/dto/requests/signup.dto.js.map +1 -0
- package/dist/auth/dto/requests/update-password.dto.d.ts +4 -0
- package/dist/auth/dto/requests/update-password.dto.js +30 -0
- package/dist/auth/dto/requests/update-password.dto.js.map +1 -0
- package/dist/auth/dto/requests/verify.dto.d.ts +7 -0
- package/dist/auth/dto/requests/verify.dto.js +48 -0
- package/dist/auth/dto/requests/verify.dto.js.map +1 -0
- package/dist/auth/dto/responses/auth-response.dto.d.ts +17 -0
- package/dist/auth/dto/responses/auth-response.dto.js +83 -0
- package/dist/auth/dto/responses/auth-response.dto.js.map +1 -0
- package/dist/auth/dto/responses/identifier-response.dto.d.ts +10 -0
- package/dist/auth/dto/responses/identifier-response.dto.js +56 -0
- package/dist/auth/dto/responses/identifier-response.dto.js.map +1 -0
- package/dist/auth/dto/responses/oauth-provider-response.dto.d.ts +10 -0
- package/dist/auth/dto/responses/oauth-provider-response.dto.js +55 -0
- package/dist/auth/dto/responses/oauth-provider-response.dto.js.map +1 -0
- package/dist/auth/dto/signup.dto.d.ts +13 -0
- package/dist/auth/dto/signup.dto.js +70 -0
- package/dist/auth/dto/signup.dto.js.map +1 -0
- package/dist/auth/dto/verify.dto.d.ts +7 -0
- package/dist/auth/dto/verify.dto.js +48 -0
- package/dist/auth/dto/verify.dto.js.map +1 -0
- package/dist/auth/entities/auth-identify.entity.d.ts +33 -0
- package/dist/auth/entities/auth-identify.entity.js +73 -0
- package/dist/auth/entities/auth-identify.entity.js.map +1 -0
- package/dist/auth/entities/auth.entity.d.ts +45 -0
- package/dist/auth/entities/auth.entity.js +129 -0
- package/dist/auth/entities/auth.entity.js.map +1 -0
- package/dist/auth/entities/base.entity.d.ts +6 -0
- package/dist/auth/entities/base.entity.js +41 -0
- package/dist/auth/entities/base.entity.js.map +1 -0
- package/dist/auth/entities/mfa-method.entity.d.ts +23 -0
- package/dist/auth/entities/mfa-method.entity.js +69 -0
- package/dist/auth/entities/mfa-method.entity.js.map +1 -0
- package/dist/auth/entities/oauth-provider.entity.d.ts +38 -0
- package/dist/auth/entities/oauth-provider.entity.js +88 -0
- package/dist/auth/entities/oauth-provider.entity.js.map +1 -0
- package/dist/auth/entities/otp-token.entity.d.ts +22 -0
- package/dist/auth/entities/otp-token.entity.js +61 -0
- package/dist/auth/entities/otp-token.entity.js.map +1 -0
- package/dist/auth/entities/session.entity.d.ts +19 -0
- package/dist/auth/entities/session.entity.js +65 -0
- package/dist/auth/entities/session.entity.js.map +1 -0
- package/dist/auth/enums/auth-type.enum.d.ts +23 -0
- package/dist/auth/enums/auth-type.enum.js +34 -0
- package/dist/auth/enums/auth-type.enum.js.map +1 -0
- package/dist/auth/guards/jwt-auth.guard.d.ts +10 -0
- package/dist/auth/guards/jwt-auth.guard.js +68 -0
- package/dist/auth/guards/jwt-auth.guard.js.map +1 -0
- package/dist/auth/guards/optional-auth.guard.d.ts +8 -0
- package/dist/auth/guards/optional-auth.guard.js +45 -0
- package/dist/auth/guards/optional-auth.guard.js.map +1 -0
- package/dist/auth/guards/ws-jwt-auth.guard.d.ts +0 -0
- package/dist/auth/guards/ws-jwt-auth.guard.js +31 -0
- package/dist/auth/guards/ws-jwt-auth.guard.js.map +1 -0
- package/dist/auth/interfaces/auth-module-async-options.interface.d.ts +7 -0
- package/dist/auth/interfaces/auth-module-async-options.interface.js +3 -0
- package/dist/auth/interfaces/auth-module-async-options.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-module-options.interface.d.ts +132 -0
- package/dist/auth/interfaces/auth-module-options.interface.js +5 -0
- package/dist/auth/interfaces/auth-module-options.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-notification-provider.interface.d.ts +29 -0
- package/dist/auth/interfaces/auth-notification-provider.interface.js +5 -0
- package/dist/auth/interfaces/auth-notification-provider.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-user-service.interface.d.ts +13 -0
- package/dist/auth/interfaces/auth-user-service.interface.js +7 -0
- package/dist/auth/interfaces/auth-user-service.interface.js.map +1 -0
- package/dist/auth/interfaces/current-user-interface.d.ts +4 -0
- package/dist/auth/interfaces/current-user-interface.js +4 -0
- package/dist/auth/interfaces/current-user-interface.js.map +1 -0
- package/dist/auth/interfaces/current-user.decorator.d.ts +2 -0
- package/dist/auth/interfaces/current-user.decorator.js +16 -0
- package/dist/auth/interfaces/current-user.decorator.js.map +1 -0
- package/dist/auth/interfaces/jwt-payload-interface.d.ts +4 -0
- package/dist/auth/interfaces/jwt-payload-interface.js +3 -0
- package/dist/auth/interfaces/jwt-payload-interface.js.map +1 -0
- package/dist/auth/interfaces/oauth-strategy.interface.d.ts +14 -0
- package/dist/auth/interfaces/oauth-strategy.interface.js +3 -0
- package/dist/auth/interfaces/oauth-strategy.interface.js.map +1 -0
- package/dist/auth/jwt-payload-interface.d.ts +4 -0
- package/dist/auth/jwt-payload-interface.js +3 -0
- package/dist/auth/jwt-payload-interface.js.map +1 -0
- package/dist/auth/jwt.strategy.d.ts +13 -0
- package/dist/auth/jwt.strategy.js +60 -0
- package/dist/auth/jwt.strategy.js.map +1 -0
- package/dist/auth/strategies/company.strategy.d.ts +0 -0
- package/dist/auth/strategies/company.strategy.js +1 -0
- package/dist/auth/strategies/company.strategy.js.map +1 -0
- package/dist/auth/strategies/google.strategy.d.ts +7 -0
- package/dist/auth/strategies/google.strategy.js +23 -0
- package/dist/auth/strategies/google.strategy.js.map +1 -0
- package/dist/auth/strategies/local-auth.strategy.d.ts +24 -0
- package/dist/auth/strategies/local-auth.strategy.js +244 -0
- package/dist/auth/strategies/local-auth.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/apple.strategy.d.ts +27 -0
- package/dist/auth/strategies/oauth/apple.strategy.js +176 -0
- package/dist/auth/strategies/oauth/apple.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/facebook.strategy.d.ts +24 -0
- package/dist/auth/strategies/oauth/facebook.strategy.js +150 -0
- package/dist/auth/strategies/oauth/facebook.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/google.strategy.d.ts +25 -0
- package/dist/auth/strategies/oauth/google.strategy.js +225 -0
- package/dist/auth/strategies/oauth/google.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/oauth-strategy.interface.d.ts +14 -0
- package/dist/auth/strategies/oauth/oauth-strategy.interface.js +3 -0
- package/dist/auth/strategies/oauth/oauth-strategy.interface.js.map +1 -0
- package/dist/auth/strategies/oauth/oauth.strategy.d.ts +25 -0
- package/dist/auth/strategies/oauth/oauth.strategy.js +70 -0
- package/dist/auth/strategies/oauth/oauth.strategy.js.map +1 -0
- package/dist/auth/strategies/otp.strategy.d.ts +7 -0
- package/dist/auth/strategies/otp.strategy.js +23 -0
- package/dist/auth/strategies/otp.strategy.js.map +1 -0
- package/dist/auth/strategies/password.strategy.d.ts +14 -0
- package/dist/auth/strategies/password.strategy.js +130 -0
- package/dist/auth/strategies/password.strategy.js.map +1 -0
- package/dist/auth/utils/duration.util.d.ts +8 -0
- package/dist/auth/utils/duration.util.js +29 -0
- package/dist/auth/utils/duration.util.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/auth-entities.d.ts +7 -0
- package/dist/migrations/auth-entities.js +18 -0
- package/dist/migrations/auth-entities.js.map +1 -0
- package/dist/migrations/auth-schema.initializer.d.ts +9 -0
- package/dist/migrations/auth-schema.initializer.js +36 -0
- package/dist/migrations/auth-schema.initializer.js.map +1 -0
- package/dist/migrations/auth.migration.v1.d.ts +12 -0
- package/dist/migrations/auth.migration.v1.js +157 -0
- package/dist/migrations/auth.migration.v1.js.map +1 -0
- package/dist/migrations/auth.migration.v2.d.ts +8 -0
- package/dist/migrations/auth.migration.v2.js +39 -0
- package/dist/migrations/auth.migration.v2.js.map +1 -0
- package/dist/migrations/auth.migrations.d.ts +2 -0
- package/dist/migrations/auth.migrations.js +8 -0
- package/dist/migrations/auth.migrations.js.map +1 -0
- package/dist/migrations/migration.runner.d.ts +9 -0
- package/dist/migrations/migration.runner.js +67 -0
- package/dist/migrations/migration.runner.js.map +1 -0
- package/dist/migrations/migration.service.d.ts +9 -0
- package/dist/migrations/migration.service.js +71 -0
- package/dist/migrations/migration.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DataSource, Repository } from 'typeorm';
|
|
2
|
+
import { LoginDto } from '../../dto/requests/login.dto';
|
|
3
|
+
import { SignupDto } from '../../dto/requests/signup.dto';
|
|
4
|
+
import { Auth } from '../../entities/auth.entity';
|
|
5
|
+
import { OAuthProvider } from '../../entities/oauth-provider.entity';
|
|
6
|
+
import { AuthIdentifier } from '../../entities/auth-identify.entity';
|
|
7
|
+
import { AuthModuleOptions } from '../../interfaces/auth-module-options.interface';
|
|
8
|
+
import { IOAuthStrategy } from '../../interfaces/oauth-strategy.interface';
|
|
9
|
+
export declare class FacebookAuthStrategy implements IOAuthStrategy {
|
|
10
|
+
private readonly dataSource;
|
|
11
|
+
private authRepo;
|
|
12
|
+
private oauthProviderRepo;
|
|
13
|
+
private options;
|
|
14
|
+
constructor(dataSource: DataSource, authRepo: Repository<Auth>, oauthProviderRepo: Repository<OAuthProvider>, options: AuthModuleOptions);
|
|
15
|
+
private verifyToken;
|
|
16
|
+
registerCredentials(dto: SignupDto, uid?: string): Promise<{
|
|
17
|
+
auth: Auth;
|
|
18
|
+
identifier?: AuthIdentifier;
|
|
19
|
+
}>;
|
|
20
|
+
login(dto: LoginDto): Promise<{
|
|
21
|
+
auth: Auth;
|
|
22
|
+
identifier?: AuthIdentifier;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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.FacebookAuthStrategy = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("typeorm");
|
|
18
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
19
|
+
const auth_entity_1 = require("../../entities/auth.entity");
|
|
20
|
+
const oauth_provider_entity_1 = require("../../entities/oauth-provider.entity");
|
|
21
|
+
const auth_identify_entity_1 = require("../../entities/auth-identify.entity");
|
|
22
|
+
const auth_type_enum_1 = require("../../enums/auth-type.enum");
|
|
23
|
+
const auth_module_options_interface_1 = require("../../interfaces/auth-module-options.interface");
|
|
24
|
+
const crypto_1 = require("crypto");
|
|
25
|
+
let FacebookAuthStrategy = class FacebookAuthStrategy {
|
|
26
|
+
constructor(dataSource, authRepo, oauthProviderRepo, options) {
|
|
27
|
+
this.dataSource = dataSource;
|
|
28
|
+
this.authRepo = authRepo;
|
|
29
|
+
this.oauthProviderRepo = oauthProviderRepo;
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
async verifyToken(token) {
|
|
33
|
+
try {
|
|
34
|
+
// Create App Secret Proof for security if secret is provided
|
|
35
|
+
let appSecretProof = '';
|
|
36
|
+
if (this.options.facebookAppSecret) {
|
|
37
|
+
appSecretProof = (0, crypto_1.createHmac)('sha256', this.options.facebookAppSecret)
|
|
38
|
+
.update(token)
|
|
39
|
+
.digest('hex');
|
|
40
|
+
}
|
|
41
|
+
const url = `https://graph.facebook.com/me?fields=id,email,first_name,last_name&access_token=${token}${appSecretProof ? `&appsecret_proof=${appSecretProof}` : ''}`;
|
|
42
|
+
const response = await fetch(url);
|
|
43
|
+
const data = await response.json();
|
|
44
|
+
if (data.error) {
|
|
45
|
+
throw new common_1.BadRequestException(`Facebook error: ${data.error.message}`);
|
|
46
|
+
}
|
|
47
|
+
if (!data.id) {
|
|
48
|
+
throw new common_1.BadRequestException('Invalid Facebook token payload');
|
|
49
|
+
}
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof common_1.BadRequestException)
|
|
54
|
+
throw error;
|
|
55
|
+
throw new common_1.BadRequestException('Failed to verify Facebook token');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async registerCredentials(dto, uid) {
|
|
59
|
+
if (!dto.token) {
|
|
60
|
+
throw new common_1.BadRequestException('Facebook access token is required');
|
|
61
|
+
}
|
|
62
|
+
const payload = await this.verifyToken(dto.token);
|
|
63
|
+
const facebookId = payload.id;
|
|
64
|
+
const email = payload.email?.toLowerCase();
|
|
65
|
+
return this.dataSource.transaction(async (manager) => {
|
|
66
|
+
const authRepo = manager.getRepository(auth_entity_1.Auth);
|
|
67
|
+
const oauthProviderRepo = manager.getRepository(oauth_provider_entity_1.OAuthProvider);
|
|
68
|
+
const identifierRepo = manager.getRepository(auth_identify_entity_1.AuthIdentifier);
|
|
69
|
+
// Check if this Facebook account is already linked
|
|
70
|
+
const existingProvider = await oauthProviderRepo.findOne({
|
|
71
|
+
where: { provider: auth_type_enum_1.OAuthProviderType.FACEBOOK, providerUserId: facebookId },
|
|
72
|
+
relations: ['auth'],
|
|
73
|
+
});
|
|
74
|
+
if (existingProvider) {
|
|
75
|
+
throw new common_1.BadRequestException('This Facebook account is already linked to a user');
|
|
76
|
+
}
|
|
77
|
+
// Check if email identifier is already taken
|
|
78
|
+
if (email) {
|
|
79
|
+
const existingIdentifier = await identifierRepo.findOne({
|
|
80
|
+
where: { value: email, type: auth_identify_entity_1.IdentifierType.EMAIL },
|
|
81
|
+
});
|
|
82
|
+
if (existingIdentifier) {
|
|
83
|
+
throw new common_1.BadRequestException('A user with this email already exists');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const identityUid = uid || (0, crypto_1.randomUUID)();
|
|
87
|
+
const newAuth = authRepo.create({
|
|
88
|
+
uid: identityUid,
|
|
89
|
+
strategy: auth_type_enum_1.AuthStrategy.OAUTH,
|
|
90
|
+
isActive: true,
|
|
91
|
+
isVerified: true, // Facebook verifies emails
|
|
92
|
+
isPrimary: true,
|
|
93
|
+
});
|
|
94
|
+
const identifiers = [];
|
|
95
|
+
if (email) {
|
|
96
|
+
identifiers.push(identifierRepo.create({
|
|
97
|
+
type: auth_identify_entity_1.IdentifierType.EMAIL,
|
|
98
|
+
value: email,
|
|
99
|
+
isVerified: true,
|
|
100
|
+
source: auth_identify_entity_1.IdentifierSource.FACEBOOK,
|
|
101
|
+
verifiedBy: 'PROVIDER',
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
newAuth.identifiers = identifiers;
|
|
105
|
+
const oauthProvider = oauthProviderRepo.create({
|
|
106
|
+
provider: auth_type_enum_1.OAuthProviderType.FACEBOOK,
|
|
107
|
+
providerUserId: facebookId,
|
|
108
|
+
expiresAt: payload.exp ? new Date(payload.exp * 1000) : undefined,
|
|
109
|
+
rawProfile: payload,
|
|
110
|
+
emailVerified: payload.email_verified === 'true' || payload.email_verified === true,
|
|
111
|
+
displayName: payload.name,
|
|
112
|
+
avatarUrl: payload.picture,
|
|
113
|
+
});
|
|
114
|
+
newAuth.oauthProviders = [...(newAuth.oauthProviders || []), oauthProvider];
|
|
115
|
+
const savedAuth = await authRepo.save(newAuth);
|
|
116
|
+
return { auth: savedAuth, identifier: savedAuth.identifiers?.[0] };
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async login(dto) {
|
|
120
|
+
if (!dto.token) {
|
|
121
|
+
throw new common_1.BadRequestException('Facebook access token is required');
|
|
122
|
+
}
|
|
123
|
+
const payload = await this.verifyToken(dto.token);
|
|
124
|
+
const facebookId = payload.id;
|
|
125
|
+
const oauthProvider = await this.oauthProviderRepo.findOne({
|
|
126
|
+
where: { provider: auth_type_enum_1.OAuthProviderType.FACEBOOK, providerUserId: facebookId },
|
|
127
|
+
relations: ['auth', 'auth.identifiers'],
|
|
128
|
+
});
|
|
129
|
+
if (!oauthProvider || !oauthProvider.auth) {
|
|
130
|
+
throw new common_1.BadRequestException('No account found linked to this Facebook account');
|
|
131
|
+
}
|
|
132
|
+
const auth = oauthProvider.auth;
|
|
133
|
+
auth.lastUsedAt = new Date();
|
|
134
|
+
await this.authRepo.save(auth);
|
|
135
|
+
const email = payload.email?.toLowerCase();
|
|
136
|
+
const identifier = auth.identifiers?.find(id => id.value === email);
|
|
137
|
+
return { auth, identifier };
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
exports.FacebookAuthStrategy = FacebookAuthStrategy;
|
|
141
|
+
exports.FacebookAuthStrategy = FacebookAuthStrategy = __decorate([
|
|
142
|
+
(0, common_1.Injectable)(),
|
|
143
|
+
__param(1, (0, typeorm_2.InjectRepository)(auth_entity_1.Auth)),
|
|
144
|
+
__param(2, (0, typeorm_2.InjectRepository)(oauth_provider_entity_1.OAuthProvider)),
|
|
145
|
+
__param(3, (0, common_1.Inject)(auth_module_options_interface_1.AUTH_MODULE_OPTIONS)),
|
|
146
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource,
|
|
147
|
+
typeorm_1.Repository,
|
|
148
|
+
typeorm_1.Repository, Object])
|
|
149
|
+
], FacebookAuthStrategy);
|
|
150
|
+
//# sourceMappingURL=facebook.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facebook.strategy.js","sourceRoot":"","sources":["../../../../src/auth/strategies/oauth/facebook.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyE;AACzE,qCAAiD;AACjD,6CAAmD;AAGnD,4DAAkD;AAClD,gFAAqE;AACrE,8EAAuG;AACvG,+DAA6E;AAC7E,kGAAwG;AAExG,mCAAgD;AAGzC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC7B,YACqB,UAAsB,EACP,QAA0B,EACjB,iBAA4C,EAChD,OAA0B;QAH9C,eAAU,GAAV,UAAU,CAAY;QACP,aAAQ,GAAR,QAAQ,CAAkB;QACjB,sBAAiB,GAAjB,iBAAiB,CAA2B;QAChD,YAAO,GAAP,OAAO,CAAmB;IAC/D,CAAC;IAEG,KAAK,CAAC,WAAW,CAAC,KAAa;QACnC,IAAI,CAAC;YACD,6DAA6D;YAC7D,IAAI,cAAc,GAAG,EAAE,CAAC;YACxB,IAAI,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;gBACjC,cAAc,GAAG,IAAA,mBAAU,EAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;qBAChE,MAAM,CAAC,KAAK,CAAC;qBACb,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;YAED,MAAM,GAAG,GAAG,mFAAmF,KAAK,GA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iBAAiB,CAAC,OAAO,CAAC;YACvD,KAAK,EAAE,EAAE,QAAQ,EAAE,kCAAiB,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE;YAC3E,SAAS,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC;SAC1C,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,4BAAmB,CAAC,kDAAkD,CAAC,CAAC;QACtF,CAAC;QAED,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE/B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC;QAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QAEpE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IAChC,CAAC;CACJ,CAAA;AA5IY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,0BAAgB,EAAC,kBAAI,CAAC,CAAA;IACtB,WAAA,IAAA,0BAAgB,EAAC,qCAAa,CAAC,CAAA;IAC/B,WAAA,IAAA,eAAM,EAAC,mDAAmB,CAAC,CAAA;qCAHC,oBAAU;QACG,oBAAU;QACQ,oBAAU;GAJjE,oBAAoB,CA4IhC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DataSource, Repository } from 'typeorm';
|
|
2
|
+
import { Auth } from '../../entities/auth.entity';
|
|
3
|
+
import { OAuthProvider } from '../../entities/oauth-provider.entity';
|
|
4
|
+
import { AuthIdentifier } from '../../entities/auth-identify.entity';
|
|
5
|
+
import { AuthModuleOptions } from '../../interfaces/auth-module-options.interface';
|
|
6
|
+
import { IOAuthStrategy } from '../../interfaces/oauth-strategy.interface';
|
|
7
|
+
import { LoginDto } from '../../dto/requests/login.dto';
|
|
8
|
+
import { SignupDto } from '../../dto/requests/signup.dto';
|
|
9
|
+
export declare class GoogleAuthStrategy implements IOAuthStrategy {
|
|
10
|
+
private readonly dataSource;
|
|
11
|
+
private authRepo;
|
|
12
|
+
private oauthProviderRepo;
|
|
13
|
+
private options;
|
|
14
|
+
private client;
|
|
15
|
+
constructor(dataSource: DataSource, authRepo: Repository<Auth>, oauthProviderRepo: Repository<OAuthProvider>, options: AuthModuleOptions);
|
|
16
|
+
private verifyToken;
|
|
17
|
+
registerCredentials(dto: SignupDto, uid?: string): Promise<{
|
|
18
|
+
auth: Auth;
|
|
19
|
+
identifier?: AuthIdentifier;
|
|
20
|
+
}>;
|
|
21
|
+
login(dto: LoginDto): Promise<{
|
|
22
|
+
auth: Auth;
|
|
23
|
+
identifier?: AuthIdentifier;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
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.GoogleAuthStrategy = void 0;
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("typeorm");
|
|
19
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
20
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
21
|
+
const auth_entity_1 = require("../../entities/auth.entity");
|
|
22
|
+
const oauth_provider_entity_1 = require("../../entities/oauth-provider.entity");
|
|
23
|
+
const auth_identify_entity_1 = require("../../entities/auth-identify.entity");
|
|
24
|
+
const auth_module_options_interface_1 = require("../../interfaces/auth-module-options.interface");
|
|
25
|
+
const crypto_1 = require("crypto");
|
|
26
|
+
const auth_type_enum_1 = require("../../enums/auth-type.enum");
|
|
27
|
+
let GoogleAuthStrategy = class GoogleAuthStrategy {
|
|
28
|
+
constructor(dataSource, authRepo, oauthProviderRepo, options) {
|
|
29
|
+
this.dataSource = dataSource;
|
|
30
|
+
this.authRepo = authRepo;
|
|
31
|
+
this.oauthProviderRepo = oauthProviderRepo;
|
|
32
|
+
this.options = options;
|
|
33
|
+
this.client = new google_auth_library_1.OAuth2Client(this.options.googleClientId);
|
|
34
|
+
}
|
|
35
|
+
async verifyToken(token) {
|
|
36
|
+
try {
|
|
37
|
+
const ticket = await this.client.verifyIdToken({
|
|
38
|
+
idToken: token,
|
|
39
|
+
audience: this.options.googleClientId,
|
|
40
|
+
});
|
|
41
|
+
const payload = ticket.getPayload();
|
|
42
|
+
if (!payload) {
|
|
43
|
+
throw new common_1.BadRequestException('Invalid Google token payload');
|
|
44
|
+
}
|
|
45
|
+
return payload;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new common_1.BadRequestException('Invalid Google token');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async registerCredentials(dto, uid) {
|
|
52
|
+
if (!dto.token) {
|
|
53
|
+
throw new common_1.BadRequestException('Google ID token is required');
|
|
54
|
+
}
|
|
55
|
+
const payload = await this.verifyToken(dto.token);
|
|
56
|
+
const googleId = payload.sub;
|
|
57
|
+
const email = payload.email?.toLowerCase();
|
|
58
|
+
return this.dataSource.transaction(async (manager) => {
|
|
59
|
+
const authRepo = manager.getRepository(auth_entity_1.Auth);
|
|
60
|
+
const oauthProviderRepo = manager.getRepository(oauth_provider_entity_1.OAuthProvider);
|
|
61
|
+
const identifierRepo = manager.getRepository(auth_identify_entity_1.AuthIdentifier);
|
|
62
|
+
// Check if this Google account is already linked
|
|
63
|
+
const existingProvider = await oauthProviderRepo.findOne({
|
|
64
|
+
where: { provider: auth_type_enum_1.OAuthProviderType.GOOGLE, providerUserId: googleId },
|
|
65
|
+
relations: ['auth'],
|
|
66
|
+
});
|
|
67
|
+
if (existingProvider) {
|
|
68
|
+
throw new common_1.BadRequestException('This Google account is already linked to a user');
|
|
69
|
+
}
|
|
70
|
+
// Check if email identifier is already taken
|
|
71
|
+
if (email) {
|
|
72
|
+
const existingIdentifier = await identifierRepo.findOne({
|
|
73
|
+
where: { value: email, type: auth_identify_entity_1.IdentifierType.EMAIL },
|
|
74
|
+
});
|
|
75
|
+
if (existingIdentifier) {
|
|
76
|
+
throw new common_1.BadRequestException('A user with this email already exists. Please login instead.');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const identityUid = uid || (0, crypto_1.randomUUID)();
|
|
80
|
+
const newAuth = authRepo.create({
|
|
81
|
+
uid: identityUid,
|
|
82
|
+
strategy: auth_type_enum_1.AuthStrategy.OAUTH,
|
|
83
|
+
isActive: true,
|
|
84
|
+
isVerified: payload.email_verified || false,
|
|
85
|
+
isPrimary: true,
|
|
86
|
+
});
|
|
87
|
+
const identifiers = [];
|
|
88
|
+
if (email) {
|
|
89
|
+
identifiers.push(identifierRepo.create({
|
|
90
|
+
type: auth_identify_entity_1.IdentifierType.EMAIL,
|
|
91
|
+
value: email,
|
|
92
|
+
isVerified: payload.email_verified || false,
|
|
93
|
+
source: auth_identify_entity_1.IdentifierSource.GOOGLE,
|
|
94
|
+
verifiedBy: payload.email_verified ? 'PROVIDER' : undefined,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
newAuth.identifiers = identifiers;
|
|
98
|
+
const oauthProvider = oauthProviderRepo.create({
|
|
99
|
+
provider: auth_type_enum_1.OAuthProviderType.GOOGLE,
|
|
100
|
+
providerUserId: googleId,
|
|
101
|
+
rawProfile: payload,
|
|
102
|
+
displayName: payload.name,
|
|
103
|
+
avatarUrl: payload.picture,
|
|
104
|
+
emailVerified: payload.email_verified,
|
|
105
|
+
expiresAt: payload.exp ? new Date(payload.exp * 1000) : undefined,
|
|
106
|
+
});
|
|
107
|
+
newAuth.oauthProviders = [...(newAuth.oauthProviders || []), oauthProvider];
|
|
108
|
+
return { auth: await authRepo.save(newAuth), identifier: newAuth.identifiers?.[0] };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// async login(dto: LoginDto): Promise<{ auth: Auth; identifier?: AuthIdentifier }> {
|
|
112
|
+
// if (!dto.token) {
|
|
113
|
+
// throw new BadRequestException('Google ID token is required');
|
|
114
|
+
// }
|
|
115
|
+
// const payload = await this.verifyToken(dto.token);
|
|
116
|
+
// const googleId = payload.sub;
|
|
117
|
+
// const oauthProvider = await this.oauthProviderRepo.findOne({
|
|
118
|
+
// where: { provider: OAuthProviderType.GOOGLE, providerUserId: googleId },
|
|
119
|
+
// relations: ['auth', 'auth.identifiers'],
|
|
120
|
+
// });
|
|
121
|
+
// if (!oauthProvider || !oauthProvider.auth) {
|
|
122
|
+
// throw new BadRequestException('No account found linked to this Google account. Please sign up.');
|
|
123
|
+
// }
|
|
124
|
+
// const auth = oauthProvider.auth;
|
|
125
|
+
// auth.lastUsedAt = new Date();
|
|
126
|
+
// await this.authRepo.save(auth);
|
|
127
|
+
// // Find the identifier that matches the email from Google
|
|
128
|
+
// const email = payload.email?.toLowerCase();
|
|
129
|
+
// const identifier = auth.identifiers?.find(id => id.value === email);
|
|
130
|
+
// return { auth, identifier };
|
|
131
|
+
// }
|
|
132
|
+
async login(dto) {
|
|
133
|
+
if (!dto.token) {
|
|
134
|
+
throw new common_1.BadRequestException('Google ID token is required');
|
|
135
|
+
}
|
|
136
|
+
const payload = await this.verifyToken(dto.token);
|
|
137
|
+
const googleId = payload.sub;
|
|
138
|
+
const email = payload.email?.toLowerCase();
|
|
139
|
+
const result = await this.dataSource.transaction(async (manager) => {
|
|
140
|
+
const oauthRepo = manager.getRepository(oauth_provider_entity_1.OAuthProvider);
|
|
141
|
+
const authRepo = manager.getRepository(auth_entity_1.Auth);
|
|
142
|
+
const identifierRepo = manager.getRepository(auth_identify_entity_1.AuthIdentifier);
|
|
143
|
+
// -------------------------
|
|
144
|
+
// 1. Load OAuth Provider INSIDE transaction
|
|
145
|
+
// -------------------------
|
|
146
|
+
const oauthProvider = await oauthRepo.findOne({
|
|
147
|
+
where: {
|
|
148
|
+
provider: auth_type_enum_1.OAuthProviderType.GOOGLE,
|
|
149
|
+
providerUserId: googleId,
|
|
150
|
+
},
|
|
151
|
+
relations: ['auth', 'auth.identifiers'],
|
|
152
|
+
});
|
|
153
|
+
if (!oauthProvider || !oauthProvider.auth) {
|
|
154
|
+
throw new common_1.BadRequestException('No account found linked to this Google account. Please sign up.');
|
|
155
|
+
}
|
|
156
|
+
const auth = oauthProvider.auth;
|
|
157
|
+
// -------------------------
|
|
158
|
+
// 2. Update OAuth Provider
|
|
159
|
+
// -------------------------
|
|
160
|
+
oauthProvider.rawProfile = payload;
|
|
161
|
+
oauthProvider.displayName = payload.name ?? null;
|
|
162
|
+
oauthProvider.avatarUrl = payload.picture ?? null;
|
|
163
|
+
oauthProvider.emailVerified = payload.email_verified ?? false;
|
|
164
|
+
// -------------------------
|
|
165
|
+
// 3. Update Auth
|
|
166
|
+
// -------------------------
|
|
167
|
+
auth.lastUsedAt = new Date();
|
|
168
|
+
// -------------------------
|
|
169
|
+
// 4. Handle Identifier (EMAIL)
|
|
170
|
+
// -------------------------
|
|
171
|
+
let identifier = null;
|
|
172
|
+
if (email) {
|
|
173
|
+
identifier = await identifierRepo.findOne({
|
|
174
|
+
where: {
|
|
175
|
+
auth: { id: auth.id },
|
|
176
|
+
type: auth_identify_entity_1.IdentifierType.EMAIL,
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
if (!identifier) {
|
|
180
|
+
identifier = identifierRepo.create({
|
|
181
|
+
auth,
|
|
182
|
+
type: auth_identify_entity_1.IdentifierType.EMAIL,
|
|
183
|
+
value: email,
|
|
184
|
+
isVerified: false,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// always normalize + update
|
|
188
|
+
identifier.value = email;
|
|
189
|
+
identifier.isVerified = payload.email_verified ?? false;
|
|
190
|
+
identifier.verifiedBy = payload.email_verified ? 'PROVIDER' : identifier.verifiedBy;
|
|
191
|
+
identifier.source = auth_identify_entity_1.IdentifierSource.GOOGLE;
|
|
192
|
+
await identifierRepo.save(identifier);
|
|
193
|
+
}
|
|
194
|
+
// -------------------------
|
|
195
|
+
// 5. Save core entities
|
|
196
|
+
// -------------------------
|
|
197
|
+
await oauthRepo.save(oauthProvider);
|
|
198
|
+
await authRepo.save(auth);
|
|
199
|
+
return { auth, identifier };
|
|
200
|
+
});
|
|
201
|
+
// -------------------------
|
|
202
|
+
// 6. Reload fresh state (important for consistency)
|
|
203
|
+
// -------------------------
|
|
204
|
+
const updatedAuth = await this.authRepo.findOne({
|
|
205
|
+
where: { id: result.auth.id },
|
|
206
|
+
relations: ['identifiers', 'oauthProviders'],
|
|
207
|
+
});
|
|
208
|
+
const identifier = updatedAuth?.identifiers?.find((i) => i.type === auth_identify_entity_1.IdentifierType.EMAIL && i.value === email);
|
|
209
|
+
return {
|
|
210
|
+
auth: updatedAuth,
|
|
211
|
+
identifier,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
exports.GoogleAuthStrategy = GoogleAuthStrategy;
|
|
216
|
+
exports.GoogleAuthStrategy = GoogleAuthStrategy = __decorate([
|
|
217
|
+
(0, common_1.Injectable)(),
|
|
218
|
+
__param(1, (0, typeorm_2.InjectRepository)(auth_entity_1.Auth)),
|
|
219
|
+
__param(2, (0, typeorm_2.InjectRepository)(oauth_provider_entity_1.OAuthProvider)),
|
|
220
|
+
__param(3, (0, common_1.Inject)(auth_module_options_interface_1.AUTH_MODULE_OPTIONS)),
|
|
221
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource,
|
|
222
|
+
typeorm_1.Repository,
|
|
223
|
+
typeorm_1.Repository, Object])
|
|
224
|
+
], GoogleAuthStrategy);
|
|
225
|
+
//# sourceMappingURL=google.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.strategy.js","sourceRoot":"","sources":["../../../../src/auth/strategies/oauth/google.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,2CAAyE;AACzE,qCAAqD;AACrD,6CAAmD;AACnD,6DAAmD;AACnD,4DAAkD;AAClD,gFAAqE;AACrE,8EAAuG;AACvG,kGAAwG;AAExG,mCAAoC;AAGpC,+DAA6E;AAGtE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAG7B,YACmB,UAAsB,EACP,QAA0B,EACjB,iBAA4C,EAChD,OAA0B;QAH9C,eAAU,GAAV,UAAU,CAAY;QACP,aAAQ,GAAR,QAAQ,CAAkB;QACjB,sBAAiB,GAAjB,iBAAiB,CAA2B;QAChD,YAAO,GAAP,OAAO,CAAmB;QAE/D,IAAI,CAAC,MAAM,GAAG,IAAI,kCAAY,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9D,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,KAAa;QACrC,IAAI,CAAC;YACH,MAAM,MAAM,GA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C,OAAO,CAAC;YAC9C,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE;YAC7B,SAAS,EAAE,CAAC,aAAa,EAAE,gBAAgB,CAAC;SAC7C,CAAC,CAAC;QAEH,MAAM,UAAU,GAAG,WAAW,EAAE,WAAW,EAAE,IAAI,CAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,qCAAc,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAC5D,CAAC;QAEF,OAAO;YACL,IAAI,EAAE,WAAY;YAClB,UAAU;SACX,CAAC;IACJ,CAAC;CACF,CAAA;AA7OY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,0BAAgB,EAAC,kBAAI,CAAC,CAAA;IACtB,WAAA,IAAA,0BAAgB,EAAC,qCAAa,CAAC,CAAA;IAC/B,WAAA,IAAA,eAAM,EAAC,mDAAmB,CAAC,CAAA;qCAHC,oBAAU;QACG,oBAAU;QACQ,oBAAU;GAN7D,kBAAkB,CA6O9B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SignupDto } from '../../dto/requests/signup.dto';
|
|
2
|
+
import { LoginDto } from '../../dto/requests/login.dto';
|
|
3
|
+
import { Auth } from '../../entities/auth.entity';
|
|
4
|
+
import { AuthIdentifier } from '../../entities/auth-identify.entity';
|
|
5
|
+
export interface IOAuthStrategy {
|
|
6
|
+
registerCredentials(dto: SignupDto, uid?: string): Promise<{
|
|
7
|
+
auth: Auth;
|
|
8
|
+
identifier?: AuthIdentifier;
|
|
9
|
+
}>;
|
|
10
|
+
login(dto: LoginDto): Promise<{
|
|
11
|
+
auth: Auth;
|
|
12
|
+
identifier?: AuthIdentifier;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-strategy.interface.js","sourceRoot":"","sources":["../../../../src/auth/strategies/oauth/oauth-strategy.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SignupDto } from '../../dto/requests/signup.dto';
|
|
2
|
+
import { LoginDto } from '../../dto/requests/login.dto';
|
|
3
|
+
import { Auth } from '../../entities/auth.entity';
|
|
4
|
+
import { AuthIdentifier } from '../../entities/auth-identify.entity';
|
|
5
|
+
import { GoogleAuthStrategy } from './google.strategy';
|
|
6
|
+
import { FacebookAuthStrategy } from './facebook.strategy';
|
|
7
|
+
import { AppleAuthStrategy } from './apple.strategy';
|
|
8
|
+
import { IOAuthStrategy } from '../../interfaces/oauth-strategy.interface';
|
|
9
|
+
import { AuthModuleOptions } from '../../interfaces/auth-module-options.interface';
|
|
10
|
+
export declare class OAuthAuthStrategy implements IOAuthStrategy {
|
|
11
|
+
private googleStrategy;
|
|
12
|
+
private facebookStrategy;
|
|
13
|
+
private appleStrategy;
|
|
14
|
+
private options;
|
|
15
|
+
constructor(googleStrategy: GoogleAuthStrategy, facebookStrategy: FacebookAuthStrategy, appleStrategy: AppleAuthStrategy, options: AuthModuleOptions);
|
|
16
|
+
private getStrategy;
|
|
17
|
+
registerCredentials(dto: SignupDto, uid?: string): Promise<{
|
|
18
|
+
auth: Auth;
|
|
19
|
+
identifier?: AuthIdentifier;
|
|
20
|
+
}>;
|
|
21
|
+
login(dto: LoginDto): Promise<{
|
|
22
|
+
auth: Auth;
|
|
23
|
+
identifier?: AuthIdentifier;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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.OAuthAuthStrategy = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const auth_type_enum_1 = require("../../enums/auth-type.enum");
|
|
18
|
+
const google_strategy_1 = require("./google.strategy");
|
|
19
|
+
const facebook_strategy_1 = require("./facebook.strategy");
|
|
20
|
+
const apple_strategy_1 = require("./apple.strategy");
|
|
21
|
+
const auth_module_options_interface_1 = require("../../interfaces/auth-module-options.interface");
|
|
22
|
+
const common_2 = require("@nestjs/common");
|
|
23
|
+
const auth_type_enum_2 = require("../../enums/auth-type.enum");
|
|
24
|
+
let OAuthAuthStrategy = class OAuthAuthStrategy {
|
|
25
|
+
constructor(googleStrategy, facebookStrategy, appleStrategy, options) {
|
|
26
|
+
this.googleStrategy = googleStrategy;
|
|
27
|
+
this.facebookStrategy = facebookStrategy;
|
|
28
|
+
this.appleStrategy = appleStrategy;
|
|
29
|
+
this.options = options;
|
|
30
|
+
}
|
|
31
|
+
getStrategy(provider) {
|
|
32
|
+
const enabledStrategies = this.options.enabledStrategies || Object.values(auth_type_enum_2.AuthStrategy);
|
|
33
|
+
if (provider === auth_type_enum_1.OAuthProviderType.GOOGLE && !enabledStrategies.includes(auth_type_enum_2.AuthStrategy.GOOGLE) && !enabledStrategies.includes(auth_type_enum_2.AuthStrategy.OAUTH)) {
|
|
34
|
+
throw new common_1.BadRequestException('Google authentication is currently disabled.');
|
|
35
|
+
}
|
|
36
|
+
if (provider === auth_type_enum_1.OAuthProviderType.FACEBOOK && !enabledStrategies.includes(auth_type_enum_2.AuthStrategy.FACEBOOK) && !enabledStrategies.includes(auth_type_enum_2.AuthStrategy.OAUTH)) {
|
|
37
|
+
throw new common_1.BadRequestException('Facebook authentication is currently disabled.');
|
|
38
|
+
}
|
|
39
|
+
if (provider === auth_type_enum_1.OAuthProviderType.APPLE && !enabledStrategies.includes(auth_type_enum_2.AuthStrategy.APPLE) && !enabledStrategies.includes(auth_type_enum_2.AuthStrategy.OAUTH)) {
|
|
40
|
+
throw new common_1.BadRequestException('Apple authentication is currently disabled.');
|
|
41
|
+
}
|
|
42
|
+
switch (provider) {
|
|
43
|
+
case auth_type_enum_1.OAuthProviderType.GOOGLE:
|
|
44
|
+
return this.googleStrategy;
|
|
45
|
+
case auth_type_enum_1.OAuthProviderType.FACEBOOK:
|
|
46
|
+
return this.facebookStrategy;
|
|
47
|
+
case auth_type_enum_1.OAuthProviderType.APPLE:
|
|
48
|
+
return this.appleStrategy;
|
|
49
|
+
default:
|
|
50
|
+
throw new common_1.BadRequestException(`Unsupported or missing OAuth provider: ${provider}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async registerCredentials(dto, uid) {
|
|
54
|
+
const strategy = this.getStrategy(dto.provider);
|
|
55
|
+
return strategy.registerCredentials(dto, uid);
|
|
56
|
+
}
|
|
57
|
+
async login(dto) {
|
|
58
|
+
const strategy = this.getStrategy(dto.provider);
|
|
59
|
+
return strategy.login(dto);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.OAuthAuthStrategy = OAuthAuthStrategy;
|
|
63
|
+
exports.OAuthAuthStrategy = OAuthAuthStrategy = __decorate([
|
|
64
|
+
(0, common_1.Injectable)(),
|
|
65
|
+
__param(3, (0, common_2.Inject)(auth_module_options_interface_1.AUTH_MODULE_OPTIONS)),
|
|
66
|
+
__metadata("design:paramtypes", [google_strategy_1.GoogleAuthStrategy,
|
|
67
|
+
facebook_strategy_1.FacebookAuthStrategy,
|
|
68
|
+
apple_strategy_1.AppleAuthStrategy, Object])
|
|
69
|
+
], OAuthAuthStrategy);
|
|
70
|
+
//# sourceMappingURL=oauth.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.strategy.js","sourceRoot":"","sources":["../../../../src/auth/strategies/oauth/oauth.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAiE;AAKjE,+DAA+D;AAC/D,uDAAuD;AACvD,2DAA2D;AAC3D,qDAAqD;AAErD,kGAAwG;AACxG,2CAAwC;AACxC,+DAA0D;AAGnD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC1B,YACY,cAAkC,EAClC,gBAAsC,EACtC,aAAgC,EACH,OAA0B;QAHvD,mBAAc,GAAd,cAAc,CAAoB;QAClC,qBAAgB,GAAhB,gBAAgB,CAAsB;QACtC,kBAAa,GAAb,aAAa,CAAmB;QACH,YAAO,GAAP,OAAO,CAAmB;IAC/D,CAAC;IAEG,WAAW,CAAC,QAA4B;QAC5C,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI,MAAM,CAAC,MAAM,CAAC,6BAAY,CAAC,CAAC;QAExF,IAAI,QAAQ,KAAK,kCAAiB,CAAC,MAAM,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,6BAAY,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,6BAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/I,MAAM,IAAI,4BAAmB,CAAC,8CAA8C,CAAC,CAAC;QAClF,CAAC;QACD,IAAI,QAAQ,KAAK,kCAAiB,CAAC,QAAQ,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,6BAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ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,oCAAkB;QAChB,wCAAoB;QACvB,kCAAiB;GAJnC,iBAAiB,CA0C7B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoginDto } from '../dto/login.dto';
|
|
2
|
+
import { SignupDto } from '../dto/signup.dto';
|
|
3
|
+
import { Auth } from '../entities/auth.entity';
|
|
4
|
+
export declare class OtpAuthStrategy {
|
|
5
|
+
registerCredentials(dto: SignupDto, uid?: string): Promise<Auth>;
|
|
6
|
+
login(dto: LoginDto): Promise<Auth>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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.OtpAuthStrategy = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let OtpAuthStrategy = class OtpAuthStrategy {
|
|
12
|
+
async registerCredentials(dto, uid) {
|
|
13
|
+
throw new Error('Not implemented');
|
|
14
|
+
}
|
|
15
|
+
async login(dto) {
|
|
16
|
+
throw new Error('Not implemented');
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.OtpAuthStrategy = OtpAuthStrategy;
|
|
20
|
+
exports.OtpAuthStrategy = OtpAuthStrategy = __decorate([
|
|
21
|
+
(0, common_1.Injectable)()
|
|
22
|
+
], OtpAuthStrategy);
|
|
23
|
+
//# sourceMappingURL=otp.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp.strategy.js","sourceRoot":"","sources":["../../../src/auth/strategies/otp.strategy.ts"],"names":[],"mappings":";;;;;;;;;AAEA,2CAA4C;AAMrC,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,KAAK,CAAC,mBAAmB,CAAC,GAAc,EAAE,GAAY;QAEpD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAa;QAEvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AAVY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;GACA,eAAe,CAU3B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DataSource, Repository } from 'typeorm';
|
|
2
|
+
import { LoginDto } from '../dto/login.dto';
|
|
3
|
+
import { SignupDto } from '../dto/signup.dto';
|
|
4
|
+
import { Auth } from '../entities/auth.entity';
|
|
5
|
+
import { AuthIdentifier } from '../entities/auth-identify.entity';
|
|
6
|
+
export declare class LocalAuthStrategy {
|
|
7
|
+
private readonly dataSource;
|
|
8
|
+
private authRepo;
|
|
9
|
+
private identifierRepo;
|
|
10
|
+
constructor(dataSource: DataSource, authRepo: Repository<Auth>, identifierRepo: Repository<AuthIdentifier>);
|
|
11
|
+
private readonly logger;
|
|
12
|
+
registerCredentials(dto: SignupDto, uid?: string): Promise<Auth>;
|
|
13
|
+
login(dto: LoginDto): Promise<Auth>;
|
|
14
|
+
}
|