@solidxai/core 0.1.9-beta.10 → 0.1.9-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/passport-strategies/facebook-oauth.strategy.d.ts +5 -3
- package/dist/passport-strategies/facebook-oauth.strategy.d.ts.map +1 -1
- package/dist/passport-strategies/facebook-oauth.strategy.js +41 -18
- package/dist/passport-strategies/facebook-oauth.strategy.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +1 -1
- package/dist/services/authentication.service.d.ts +12 -13
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +40 -16
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/settings/default-settings-provider.service.d.ts +16 -0
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +75 -12
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/services/user.service.d.ts +10 -8
- package/dist/services/user.service.d.ts.map +1 -1
- package/dist/services/user.service.js +85 -46
- package/dist/services/user.service.js.map +1 -1
- package/package.json +1 -1
- package/src/passport-strategies/facebook-oauth.strategy.ts +82 -31
- package/src/seeders/seed-data/solid-core-metadata.json +1 -1
- package/src/services/authentication.service.ts +217 -141
- package/src/services/settings/default-settings-provider.service.ts +80 -17
- package/src/services/user.service.ts +149 -77
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Strategy } from
|
|
2
|
-
import {
|
|
1
|
+
import { Strategy } from "passport-facebook";
|
|
2
|
+
import { SettingService } from "../services/setting.service";
|
|
3
|
+
import { UserService } from "../services/user.service";
|
|
3
4
|
declare const FacebookOauthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
4
5
|
export declare class FacebookOauthGuard extends FacebookOauthGuard_base {
|
|
5
6
|
}
|
|
6
7
|
declare const FacebookOAuthStrategy_base: new (...args: any[]) => Strategy;
|
|
7
8
|
export declare class FacebookOAuthStrategy extends FacebookOAuthStrategy_base {
|
|
8
9
|
private readonly userService;
|
|
10
|
+
private readonly settingService;
|
|
9
11
|
private readonly logger;
|
|
10
|
-
constructor(userService: UserService);
|
|
12
|
+
constructor(userService: UserService, settingService: SettingService);
|
|
11
13
|
validate(_accessToken: string, _refreshToken: string, profile: any, done: any): Promise<any>;
|
|
12
14
|
}
|
|
13
15
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facebook-oauth.strategy.d.ts","sourceRoot":"","sources":["../../src/passport-strategies/facebook-oauth.strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"facebook-oauth.strategy.d.ts","sourceRoot":"","sources":["../../src/passport-strategies/facebook-oauth.strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAO7C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;;AAMvD,qBACa,kBAAmB,SAAQ,uBAAqB;CAAG;;AAEhE,qBACa,qBAAsB,SAAQ,0BAG1C;IAIG,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0C;gBAG9C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc;IAgD3C,QAAQ,CACZ,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,GAAG,EACZ,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,GAAG,CAAC;CAiChB"}
|
|
@@ -16,43 +16,65 @@ const passport_1 = require("@nestjs/passport");
|
|
|
16
16
|
const passport_facebook_1 = require("passport-facebook");
|
|
17
17
|
const facebook_oauth_helper_1 = require("../helpers/facebook-oauth.helper");
|
|
18
18
|
const uuid_1 = require("uuid");
|
|
19
|
+
const setting_service_1 = require("../services/setting.service");
|
|
19
20
|
const user_service_1 = require("../services/user.service");
|
|
20
|
-
const DUMMY_CLIENT_ID =
|
|
21
|
-
const DUMMY_CLIENT_SECRET =
|
|
22
|
-
const DUMMY_CALLBACK_URL =
|
|
23
|
-
let FacebookOauthGuard = class FacebookOauthGuard extends (0, passport_1.AuthGuard)(
|
|
21
|
+
const DUMMY_CLIENT_ID = "DUMMY_CLIENT_ID";
|
|
22
|
+
const DUMMY_CLIENT_SECRET = "DUMMY_CLIENT_SECRET";
|
|
23
|
+
const DUMMY_CALLBACK_URL = "DUMMY_CALLBACK_URL";
|
|
24
|
+
let FacebookOauthGuard = class FacebookOauthGuard extends (0, passport_1.AuthGuard)("facebook") {
|
|
24
25
|
};
|
|
25
26
|
exports.FacebookOauthGuard = FacebookOauthGuard;
|
|
26
27
|
exports.FacebookOauthGuard = FacebookOauthGuard = __decorate([
|
|
27
28
|
(0, common_1.Injectable)()
|
|
28
29
|
], FacebookOauthGuard);
|
|
29
|
-
let FacebookOAuthStrategy = FacebookOAuthStrategy_1 = class FacebookOAuthStrategy extends (0, passport_1.PassportStrategy)(passport_facebook_1.Strategy,
|
|
30
|
-
constructor(userService) {
|
|
31
|
-
const clientID =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
30
|
+
let FacebookOAuthStrategy = FacebookOAuthStrategy_1 = class FacebookOAuthStrategy extends (0, passport_1.PassportStrategy)(passport_facebook_1.Strategy, "facebook") {
|
|
31
|
+
constructor(userService, settingService) {
|
|
32
|
+
const clientID = settingService.getConfigValue("FACEBOOK_CLIENT_ID") ??
|
|
33
|
+
process.env.IAM_FACEBOOK_OAUTH_CLIENT_ID ??
|
|
34
|
+
DUMMY_CLIENT_ID;
|
|
35
|
+
const clientSecret = settingService.getConfigValue("FACEBOOK_CLIENT_SECRET") ??
|
|
36
|
+
process.env.IAM_FACEBOOK_OAUTH_CLIENT_SECRET ??
|
|
37
|
+
DUMMY_CLIENT_SECRET;
|
|
38
|
+
const callbackURL = settingService.getConfigValue("FACEBOOK_CALLBACK_URL") ??
|
|
39
|
+
process.env.IAM_FACEBOOK_OAUTH_CALLBACK_URL ??
|
|
40
|
+
DUMMY_CALLBACK_URL;
|
|
41
|
+
const redirectURL = settingService.getConfigValue("FACEBOOK_REDIRECT_URL") ?? process.env.IAM_FACEBOOK_OAUTH_REDIRECT_URL;
|
|
35
42
|
super({
|
|
36
43
|
clientID,
|
|
37
44
|
clientSecret,
|
|
38
45
|
callbackURL,
|
|
39
|
-
scope: [
|
|
40
|
-
profileFields: [
|
|
46
|
+
scope: ["email"],
|
|
47
|
+
profileFields: ["id", "name", "email", "picture.type(large)"],
|
|
41
48
|
});
|
|
42
49
|
this.userService = userService;
|
|
50
|
+
this.settingService = settingService;
|
|
43
51
|
this.logger = new common_1.Logger(FacebookOAuthStrategy_1.name);
|
|
44
|
-
const facebookOauth = {
|
|
52
|
+
const facebookOauth = {
|
|
53
|
+
clientID,
|
|
54
|
+
clientSecret,
|
|
55
|
+
callbackURL,
|
|
56
|
+
redirectURL,
|
|
57
|
+
};
|
|
45
58
|
if (!(0, facebook_oauth_helper_1.isFacebookOAuthConfigured)(facebookOauth)) {
|
|
46
|
-
this.logger.debug(
|
|
59
|
+
this.logger.debug("Facebook OAuth strategy is not configured");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.logger.debug(`Facebook OAuth configured with callbackURL=${callbackURL}`);
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
async validate(_accessToken, _refreshToken, profile, done) {
|
|
50
66
|
const { id, name, emails, photos } = profile;
|
|
51
67
|
const loginAccessCode = (0, uuid_1.v4)();
|
|
68
|
+
const email = emails && emails.length > 0 ? emails[0].value : null;
|
|
69
|
+
const firstName = name?.givenName || "";
|
|
70
|
+
const lastName = name?.familyName || "";
|
|
71
|
+
const fullName = firstName || lastName
|
|
72
|
+
? `${firstName} ${lastName}`.trim()
|
|
73
|
+
: profile.displayName;
|
|
52
74
|
const user = {
|
|
53
|
-
provider:
|
|
75
|
+
provider: "facebook",
|
|
54
76
|
providerId: id,
|
|
55
|
-
email:
|
|
77
|
+
email: email,
|
|
56
78
|
name: `${name.givenName} ${name.familyName}`,
|
|
57
79
|
picture: photos?.[0]?.value,
|
|
58
80
|
accessCode: loginAccessCode,
|
|
@@ -60,7 +82,7 @@ let FacebookOAuthStrategy = FacebookOAuthStrategy_1 = class FacebookOAuthStrateg
|
|
|
60
82
|
await this.userService.resolveUserOnOauthFacebook({
|
|
61
83
|
...user,
|
|
62
84
|
accessToken: _accessToken,
|
|
63
|
-
refreshToken: null
|
|
85
|
+
refreshToken: null,
|
|
64
86
|
});
|
|
65
87
|
done(null, user);
|
|
66
88
|
}
|
|
@@ -68,6 +90,7 @@ let FacebookOAuthStrategy = FacebookOAuthStrategy_1 = class FacebookOAuthStrateg
|
|
|
68
90
|
exports.FacebookOAuthStrategy = FacebookOAuthStrategy;
|
|
69
91
|
exports.FacebookOAuthStrategy = FacebookOAuthStrategy = FacebookOAuthStrategy_1 = __decorate([
|
|
70
92
|
(0, common_1.Injectable)(),
|
|
71
|
-
__metadata("design:paramtypes", [user_service_1.UserService
|
|
93
|
+
__metadata("design:paramtypes", [user_service_1.UserService,
|
|
94
|
+
setting_service_1.SettingService])
|
|
72
95
|
], FacebookOAuthStrategy);
|
|
73
96
|
//# sourceMappingURL=facebook-oauth.strategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facebook-oauth.strategy.js","sourceRoot":"","sources":["../../src/passport-strategies/facebook-oauth.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,+CAA+D;AAC/D,yDAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"facebook-oauth.strategy.js","sourceRoot":"","sources":["../../src/passport-strategies/facebook-oauth.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;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E,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK;YAC3B,UAAU,EAAE,eAAe;SAC5B,CAAC;QAGF,MAAM,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAC;YAChD,GAAG,IAAI;YACP,WAAW,EAAE,YAAY;YACzB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnB,CAAC;CACF,CAAA;AA9FY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAQqB,0BAAW;QACR,gCAAc;GARtC,qBAAqB,CA8FjC","sourcesContent":["import { Injectable, Logger } from \"@nestjs/common\";\nimport { AuthGuard, PassportStrategy } from \"@nestjs/passport\";\nimport { Strategy } from \"passport-facebook\";\nimport {\n FacebookAuthConfiguration,\n isFacebookOAuthConfigured,\n} from \"src/helpers/facebook-oauth.helper\";\nimport { v4 as uuid } from \"uuid\";\nimport type { SolidCoreSetting } from \"../services/settings/default-settings-provider.service\";\nimport { SettingService } from \"../services/setting.service\";\nimport { UserService } from \"../services/user.service\";\n\nconst DUMMY_CLIENT_ID = \"DUMMY_CLIENT_ID\";\nconst DUMMY_CLIENT_SECRET = \"DUMMY_CLIENT_SECRET\";\nconst DUMMY_CALLBACK_URL = \"DUMMY_CALLBACK_URL\";\n\n@Injectable()\nexport class FacebookOauthGuard extends AuthGuard(\"facebook\") {}\n\n@Injectable()\nexport class FacebookOAuthStrategy extends PassportStrategy(\n Strategy,\n \"facebook\",\n) {\n private readonly logger = new Logger(FacebookOAuthStrategy.name);\n\n constructor(\n private readonly userService: UserService,\n private readonly settingService: SettingService,\n ) {\n // Prefer settings cache (same source used by controller validation), fall back to env.\n const clientID =\n settingService.getConfigValue<SolidCoreSetting>(\"FACEBOOK_CLIENT_ID\") ??\n process.env.IAM_FACEBOOK_OAUTH_CLIENT_ID ??\n DUMMY_CLIENT_ID;\n const clientSecret =\n settingService.getConfigValue<SolidCoreSetting>(\n \"FACEBOOK_CLIENT_SECRET\",\n ) ??\n process.env.IAM_FACEBOOK_OAUTH_CLIENT_SECRET ??\n DUMMY_CLIENT_SECRET;\n const callbackURL =\n settingService.getConfigValue<SolidCoreSetting>(\n \"FACEBOOK_CALLBACK_URL\",\n ) ??\n process.env.IAM_FACEBOOK_OAUTH_CALLBACK_URL ??\n DUMMY_CALLBACK_URL;\n const redirectURL =\n settingService.getConfigValue<SolidCoreSetting>(\n \"FACEBOOK_REDIRECT_URL\",\n ) ?? process.env.IAM_FACEBOOK_OAUTH_REDIRECT_URL;\n\n super({\n clientID,\n clientSecret,\n callbackURL,\n scope: [\"email\"],\n // Facebook Graph API expects \"email\" and \"picture\", not \"emails\"/\"photos\".\n profileFields: [\"id\", \"name\", \"email\", \"picture.type(large)\"],\n });\n\n const facebookOauth: FacebookAuthConfiguration = {\n clientID,\n clientSecret,\n callbackURL,\n redirectURL,\n };\n if (!isFacebookOAuthConfigured(facebookOauth)) {\n this.logger.debug(\"Facebook OAuth strategy is not configured\");\n } else {\n this.logger.debug(\n `Facebook OAuth configured with callbackURL=${callbackURL}`,\n );\n }\n }\n\n async validate(\n _accessToken: string,\n _refreshToken: string,\n profile: any,\n done: any,\n ): Promise<any> {\n const { id, name, emails, photos } = profile;\n\n // generate a unique access code.\n const loginAccessCode: string = uuid();\n\n const email = emails && emails.length > 0 ? emails[0].value : null;\n\n const firstName = name?.givenName || \"\";\n const lastName = name?.familyName || \"\";\n const fullName =\n firstName || lastName\n ? `${firstName} ${lastName}`.trim()\n : profile.displayName;\n\n const user = {\n provider: \"facebook\",\n providerId: id,\n email: email,\n name: `${name.givenName} ${name.familyName}`,\n picture: photos?.[0]?.value,\n accessCode: loginAccessCode,\n };\n\n // store the access code and the access token in the database.\n await this.userService.resolveUserOnOauthFacebook({\n ...user,\n accessToken: _accessToken,\n refreshToken: null,\n });\n\n done(null, user);\n }\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { HttpService } from "@nestjs/axios";
|
|
2
2
|
import { EventEmitter2 } from "@nestjs/event-emitter";
|
|
3
3
|
import { JwtService } from "@nestjs/jwt";
|
|
4
|
-
import { CreateUserDto } from "../dtos/create-user.dto";
|
|
5
4
|
import { MailFactory } from "../factories/mail.factory";
|
|
6
5
|
import { UserRepository } from "../repository/user.repository";
|
|
7
|
-
import { DataSource, Repository } from "typeorm";
|
|
6
|
+
import { DataSource, DeepPartial, Repository } from "typeorm";
|
|
8
7
|
import { ChangePasswordDto } from "../dtos/change-password.dto";
|
|
9
8
|
import { ConfirmForgotPasswordDto } from "../dtos/confirm-forgot-password.dto";
|
|
10
9
|
import { InitiateForgotPasswordDto } from "../dtos/initiate-forgot-password.dto";
|
|
@@ -15,16 +14,16 @@ import { RefreshTokenDto } from "../dtos/refresh-token.dto";
|
|
|
15
14
|
import { SignInDto } from "../dtos/sign-in.dto";
|
|
16
15
|
import { SignUpDto } from "../dtos/sign-up.dto";
|
|
17
16
|
import { User } from "../entities/user.entity";
|
|
18
|
-
import { ActiveUserData } from
|
|
19
|
-
import { HashingService } from
|
|
20
|
-
import { RefreshTokenIdsStorageService } from
|
|
21
|
-
import { SsoCodeStorageService } from
|
|
22
|
-
import { RoleMetadataService } from
|
|
23
|
-
import { SettingService } from
|
|
24
|
-
import { UserActivityHistoryService } from
|
|
25
|
-
import { UserService } from
|
|
26
|
-
import { SmsFactory } from
|
|
27
|
-
import { SolidRegistry } from
|
|
17
|
+
import { ActiveUserData } from "../interfaces/active-user-data.interface";
|
|
18
|
+
import { HashingService } from "./hashing.service";
|
|
19
|
+
import { RefreshTokenIdsStorageService } from "./refresh-token-ids-storage.service";
|
|
20
|
+
import { SsoCodeStorageService } from "./sso-code-storage.service";
|
|
21
|
+
import { RoleMetadataService } from "./role-metadata.service";
|
|
22
|
+
import { SettingService } from "./setting.service";
|
|
23
|
+
import { UserActivityHistoryService } from "./user-activity-history.service";
|
|
24
|
+
import { UserService } from "./user.service";
|
|
25
|
+
import { SmsFactory } from "../factories/sms.factory";
|
|
26
|
+
import { SolidRegistry } from "../helpers/solid-registry";
|
|
28
27
|
export declare class AuthenticationService {
|
|
29
28
|
private readonly userService;
|
|
30
29
|
private readonly userRepository;
|
|
@@ -52,7 +51,7 @@ export declare class AuthenticationService {
|
|
|
52
51
|
private static readonly SIGNUP_DTO_KEYS;
|
|
53
52
|
signUp(signUpDto: SignUpDto & Record<string, any>, activeUser?: ActiveUserData): Promise<User>;
|
|
54
53
|
private performSignUp;
|
|
55
|
-
signupForExtensionUser<T extends User
|
|
54
|
+
signupForExtensionUser<T extends User>(signUpDto: SignUpDto, extensionUserDto: DeepPartial<T>, extensionUserRepo: Repository<T>): Promise<T>;
|
|
56
55
|
private populateForSignup;
|
|
57
56
|
private handlePostSignup;
|
|
58
57
|
generatePassword(length?: number): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../../src/services/authentication.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY5C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../../src/services/authentication.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY5C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAO9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,E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B,yBAAyB,EAAE,yBAAyB;;;;;;;;;;;YAsDxC,0BAA0B;IA8DlC,qBAAqB,CACzB,wBAAwB,EAAE,wBAAwB;;;;;;;YA+DtC,2BAA2B;IA8DnC,cAAc,CAAC,IAAI,EAAE,IAAI;;;;IAYzB,mBAAmB,CAAC,IAAI,EAAE,IAAI;IAe9B,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,oBAAoB,CAAC,EAAE,MAAM;IAkB9D,aAAa,CAAC,eAAe,EAAE,eAAe;;;;YA4DtC,SAAS;IAuBjB,uBAAuB,CAAC,IAAI,EAAE,IAAI;IAyBlC,iBAAiB,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;IAqCpC,yBAAyB,CAAC,IAAI,EAAE,IAAI;IAiCpC,mBAAmB,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;IAoCtC,0BAA0B,CAAC,IAAI,EAAE,IAAI;IA0BrC,oBAAoB,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;IAoCvC,gBAAgB,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;YAkC3B,iCAAiC;IAO/C,OAAO,CAAC,mBAAmB;YAab,uBAAuB;YAQvB,mBAAmB;IAa3B,MAAM,CAAC,YAAY,EAAE,MAAM;;;IAuC3B,YAAY,CAAC,MAAM,EAAE,MAAM;IAS3B,EAAE,CAAC,UAAU,EAAE,cAAc;;;;;;;;;;IA+B7B,eAAe,CACnB,UAAU,EAAE,cAAc,EAC1B,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAgBzB,eAAe,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;;CAYnC"}
|
|
@@ -111,11 +111,11 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
async signUp(signUpDto, activeUser = null) {
|
|
114
|
-
const hasExtensionFields = Object.keys(signUpDto).some(k => !AuthenticationService_1.SIGNUP_DTO_KEYS.has(k));
|
|
114
|
+
const hasExtensionFields = Object.keys(signUpDto).some((k) => !AuthenticationService_1.SIGNUP_DTO_KEYS.has(k));
|
|
115
115
|
if (hasExtensionFields) {
|
|
116
116
|
const provider = this.solidRegistry.getExtensionUserCreationProvider();
|
|
117
117
|
if (!provider) {
|
|
118
|
-
throw new common_1.InternalServerErrorException(
|
|
118
|
+
throw new common_1.InternalServerErrorException("No ExtensionUserCreationProvider registered. Register one to handle extension user creation.");
|
|
119
119
|
}
|
|
120
120
|
const entity = await provider.buildExtensionEntity(signUpDto);
|
|
121
121
|
const effectiveDto = { ...signUpDto, roles: provider.roles(signUpDto) };
|
|
@@ -125,9 +125,9 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
125
125
|
}
|
|
126
126
|
async performSignUp(signUpDto, entity, repo) {
|
|
127
127
|
try {
|
|
128
|
-
const onForcePasswordChange = this.settingService.getConfigValue(
|
|
129
|
-
const activateUserOnRegistration = this.settingService.getConfigValue(
|
|
130
|
-
const defaultRole = this.settingService.getConfigValue(
|
|
128
|
+
const onForcePasswordChange = this.settingService.getConfigValue("forceChangePasswordOnFirstLogin");
|
|
129
|
+
const activateUserOnRegistration = this.settingService.getConfigValue("activateUserOnRegistration");
|
|
130
|
+
const defaultRole = this.settingService.getConfigValue("defaultRole");
|
|
131
131
|
var { user, pwd, autoGeneratedPwd } = await this.populateForSignup(entity, signUpDto, activateUserOnRegistration, onForcePasswordChange);
|
|
132
132
|
const privateDto = signUpDto;
|
|
133
133
|
if (privateDto.isAllowedToGenerateApiKeys !== undefined) {
|
|
@@ -135,14 +135,16 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
135
135
|
}
|
|
136
136
|
const savedUser = await repo.save(user);
|
|
137
137
|
const userRoles = signUpDto.roles ?? [];
|
|
138
|
-
if ((signUpDto.roles?.length ?? 0) === 0 &&
|
|
138
|
+
if ((signUpDto.roles?.length ?? 0) === 0 &&
|
|
139
|
+
signUpDto.username !== "sa" &&
|
|
140
|
+
defaultRole) {
|
|
139
141
|
userRoles.push(defaultRole);
|
|
140
142
|
}
|
|
141
143
|
await this.handlePostSignup(savedUser, userRoles, pwd, autoGeneratedPwd);
|
|
142
144
|
return savedUser;
|
|
143
145
|
}
|
|
144
146
|
catch (err) {
|
|
145
|
-
const pgUniqueViolationErrorCode =
|
|
147
|
+
const pgUniqueViolationErrorCode = "23505";
|
|
146
148
|
if (err.code === pgUniqueViolationErrorCode) {
|
|
147
149
|
throw new common_1.ConflictException(parseUniqueConstraintError(err.detail || error_messages_1.ERROR_MESSAGES.UNIQUE_CONSTRAINT_VIOLATION));
|
|
148
150
|
}
|
|
@@ -150,7 +152,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
async signupForExtensionUser(signUpDto, extensionUserDto, extensionUserRepo) {
|
|
153
|
-
const entity = extensionUserRepo.
|
|
155
|
+
const entity = extensionUserRepo.create(extensionUserDto);
|
|
154
156
|
return this.performSignUp(signUpDto, entity, extensionUserRepo);
|
|
155
157
|
}
|
|
156
158
|
async populateForSignup(user, signUpDto, isUserActive = true, onForcePasswordChange) {
|
|
@@ -312,7 +314,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
312
314
|
user.active = false;
|
|
313
315
|
await this.assignRegistrationOtp(validationSource, user);
|
|
314
316
|
await this.userRepository.save(user);
|
|
315
|
-
await this.userService.addRoleToUser(user.username, this.settingService.getConfigValue(
|
|
317
|
+
await this.userService.addRoleToUser(user.username, this.settingService.getConfigValue("defaultRole"));
|
|
316
318
|
}
|
|
317
319
|
else {
|
|
318
320
|
await this.assignRegistrationOtp(validationSource, user);
|
|
@@ -1018,8 +1020,16 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1018
1020
|
};
|
|
1019
1021
|
}
|
|
1020
1022
|
async validateUserUsingFacebook(user) {
|
|
1023
|
+
if (!user.facebookAccessToken || !user.facebookId) {
|
|
1024
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
1025
|
+
}
|
|
1021
1026
|
try {
|
|
1022
|
-
const response = await this.httpService.axiosRef.get(`https://graph.facebook.com/me
|
|
1027
|
+
const response = await this.httpService.axiosRef.get(`https://graph.facebook.com/me`, {
|
|
1028
|
+
params: { fields: "id,name,email" },
|
|
1029
|
+
headers: {
|
|
1030
|
+
Authorization: `Bearer ${user.facebookAccessToken}`,
|
|
1031
|
+
},
|
|
1032
|
+
});
|
|
1023
1033
|
const userProfile = response.data;
|
|
1024
1034
|
if (userProfile.id === user.facebookId &&
|
|
1025
1035
|
(!user.email || !userProfile.email || userProfile.email === user.email)) {
|
|
@@ -1030,7 +1040,10 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1030
1040
|
}
|
|
1031
1041
|
}
|
|
1032
1042
|
catch (error) {
|
|
1033
|
-
|
|
1043
|
+
if (error instanceof common_1.UnauthorizedException) {
|
|
1044
|
+
throw error;
|
|
1045
|
+
}
|
|
1046
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
1034
1047
|
}
|
|
1035
1048
|
}
|
|
1036
1049
|
async signInUsingFacebook(accessCode) {
|
|
@@ -1216,7 +1229,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1216
1229
|
mobile: user.mobile,
|
|
1217
1230
|
username: user.username,
|
|
1218
1231
|
id: user.id,
|
|
1219
|
-
roles: user.roles.map((role) => role.name)
|
|
1232
|
+
roles: user.roles.map((role) => role.name),
|
|
1220
1233
|
},
|
|
1221
1234
|
refreshToken: refreshTokenState.currentRefreshToken,
|
|
1222
1235
|
};
|
|
@@ -1225,22 +1238,33 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1225
1238
|
async generateSsoCode(activeUser, rawAccessToken) {
|
|
1226
1239
|
const refreshTokenState = await this.refreshTokenIdsStorage.getCurrentRefreshTokenState(activeUser.sub);
|
|
1227
1240
|
if (!refreshTokenState?.currentRefreshToken) {
|
|
1228
|
-
throw new common_1.UnauthorizedException(
|
|
1241
|
+
throw new common_1.UnauthorizedException("No active session found");
|
|
1229
1242
|
}
|
|
1230
1243
|
const ssoCode = await this.ssoCodeStorage.generateCode(activeUser.sub, rawAccessToken, refreshTokenState.currentRefreshToken);
|
|
1231
1244
|
return { ssoCode };
|
|
1232
1245
|
}
|
|
1233
1246
|
async exchangeSsoCode(code) {
|
|
1234
1247
|
const { userId, accessToken, refreshToken } = await this.ssoCodeStorage.consumeCode(code);
|
|
1235
|
-
const user = await this.userRepository.findOne({
|
|
1248
|
+
const user = await this.userRepository.findOne({
|
|
1249
|
+
where: { id: userId },
|
|
1250
|
+
relations: { roles: true },
|
|
1251
|
+
});
|
|
1236
1252
|
if (!user) {
|
|
1237
|
-
throw new common_1.UnauthorizedException(
|
|
1253
|
+
throw new common_1.UnauthorizedException("User not found");
|
|
1238
1254
|
}
|
|
1239
1255
|
return { accessToken, refreshToken, user: this.buildUserPayload(user) };
|
|
1240
1256
|
}
|
|
1241
1257
|
};
|
|
1242
1258
|
exports.AuthenticationService = AuthenticationService;
|
|
1243
|
-
AuthenticationService.SIGNUP_DTO_KEYS = new Set([
|
|
1259
|
+
AuthenticationService.SIGNUP_DTO_KEYS = new Set([
|
|
1260
|
+
"username",
|
|
1261
|
+
"email",
|
|
1262
|
+
"password",
|
|
1263
|
+
"fullName",
|
|
1264
|
+
"mobile",
|
|
1265
|
+
"roles",
|
|
1266
|
+
"forcePasswordChange",
|
|
1267
|
+
]);
|
|
1244
1268
|
exports.AuthenticationService = AuthenticationService = AuthenticationService_1 = __decorate([
|
|
1245
1269
|
(0, common_1.Injectable)(),
|
|
1246
1270
|
__param(13, (0, typeorm_1.InjectDataSource)()),
|