@hed-hog/core 0.0.7 → 0.0.10
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/auth/auth.service.d.ts +1 -4
- package/dist/auth/auth.service.d.ts.map +1 -1
- package/dist/auth/auth.service.js +9 -19
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/challenge/challenge.service.d.ts +1 -4
- package/dist/challenge/challenge.service.d.ts.map +1 -1
- package/dist/challenge/challenge.service.js +26 -16
- package/dist/challenge/challenge.service.js.map +1 -1
- package/dist/file/file.service.d.ts +2 -5
- package/dist/file/file.service.d.ts.map +1 -1
- package/dist/file/file.service.js +40 -16
- package/dist/file/file.service.js.map +1 -1
- package/dist/mail/mail.service.d.ts +1 -4
- package/dist/mail/mail.service.d.ts.map +1 -1
- package/dist/mail/mail.service.js +10 -9
- package/dist/mail/mail.service.js.map +1 -1
- package/dist/oauth/interfaces/OAuthProvider.d.ts +1 -1
- package/dist/oauth/interfaces/OAuthProvider.d.ts.map +1 -1
- package/dist/oauth/oauth.service.d.ts +2 -5
- package/dist/oauth/oauth.service.d.ts.map +1 -1
- package/dist/oauth/oauth.service.js +12 -15
- package/dist/oauth/oauth.service.js.map +1 -1
- package/dist/oauth/providers/abstract.provider.d.ts +1 -1
- package/dist/oauth/providers/abstract.provider.d.ts.map +1 -1
- package/dist/oauth/providers/facebook.provider.d.ts +2 -5
- package/dist/oauth/providers/facebook.provider.d.ts.map +1 -1
- package/dist/oauth/providers/facebook.provider.js +18 -15
- package/dist/oauth/providers/facebook.provider.js.map +1 -1
- package/dist/oauth/providers/github.provider.d.ts +2 -5
- package/dist/oauth/providers/github.provider.d.ts.map +1 -1
- package/dist/oauth/providers/github.provider.js +17 -14
- package/dist/oauth/providers/github.provider.js.map +1 -1
- package/dist/oauth/providers/google.provider.d.ts +2 -5
- package/dist/oauth/providers/google.provider.d.ts.map +1 -1
- package/dist/oauth/providers/google.provider.js +18 -15
- package/dist/oauth/providers/google.provider.js.map +1 -1
- package/dist/oauth/providers/microsoft.provider.d.ts +2 -5
- package/dist/oauth/providers/microsoft.provider.d.ts.map +1 -1
- package/dist/oauth/providers/microsoft.provider.js +17 -14
- package/dist/oauth/providers/microsoft.provider.js.map +1 -1
- package/dist/profile/profile.service.d.ts +0 -2
- package/dist/profile/profile.service.d.ts.map +1 -1
- package/dist/profile/profile.service.js +41 -20
- package/dist/profile/profile.service.js.map +1 -1
- package/dist/session/session.service.d.ts +1 -4
- package/dist/session/session.service.d.ts.map +1 -1
- package/dist/session/session.service.js +4 -7
- package/dist/session/session.service.js.map +1 -1
- package/dist/setting/setting.controller.d.ts +3 -4
- package/dist/setting/setting.controller.d.ts.map +1 -1
- package/dist/setting/setting.controller.js +7 -3
- package/dist/setting/setting.controller.js.map +1 -1
- package/dist/setting/setting.service.d.ts +2 -4
- package/dist/setting/setting.service.d.ts.map +1 -1
- package/dist/setting/setting.service.js +45 -5
- package/dist/setting/setting.service.js.map +1 -1
- package/dist/token/token.service.d.ts +1 -4
- package/dist/token/token.service.d.ts.map +1 -1
- package/dist/token/token.service.js +8 -11
- package/dist/token/token.service.js.map +1 -1
- package/hedhog/data/setting_group.yaml +11 -20
- package/package.json +7 -5
- package/src/auth/auth.service.ts +11 -22
- package/src/challenge/challenge.service.ts +35 -19
- package/src/file/file.service.ts +45 -20
- package/src/mail/mail.service.ts +16 -12
- package/src/oauth/interfaces/OAuthProvider.ts +1 -1
- package/src/oauth/oauth.service.ts +16 -19
- package/src/oauth/providers/abstract.provider.ts +1 -1
- package/src/oauth/providers/facebook.provider.ts +22 -18
- package/src/oauth/providers/github.provider.ts +22 -18
- package/src/oauth/providers/google.provider.ts +23 -17
- package/src/oauth/providers/microsoft.provider.ts +23 -18
- package/src/profile/profile.service.ts +52 -27
- package/src/session/session.service.ts +6 -11
- package/src/setting/setting.controller.ts +9 -3
- package/src/setting/setting.service.ts +18 -9
- package/src/token/token.service.ts +12 -15
package/src/file/file.service.ts
CHANGED
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
forwardRef,
|
|
6
6
|
Inject,
|
|
7
7
|
Injectable,
|
|
8
|
-
NotFoundException
|
|
9
|
-
OnModuleInit,
|
|
8
|
+
NotFoundException
|
|
10
9
|
} from '@nestjs/common';
|
|
11
10
|
import { JwtService } from '@nestjs/jwt';
|
|
12
11
|
import { SettingService } from '../setting/setting.service';
|
|
@@ -16,10 +15,9 @@ import { EnumProvider } from './provider/provider.enum';
|
|
|
16
15
|
import { ProviderFactory } from './provider/provider.factory';
|
|
17
16
|
|
|
18
17
|
@Injectable()
|
|
19
|
-
export class FileService
|
|
18
|
+
export class FileService {
|
|
20
19
|
private providerId: number;
|
|
21
20
|
private mimetypes: Record<string, number> = {};
|
|
22
|
-
private setting: Record<string, string>;
|
|
23
21
|
|
|
24
22
|
constructor(
|
|
25
23
|
@Inject(forwardRef(() => PrismaService))
|
|
@@ -32,12 +30,8 @@ export class FileService implements OnModuleInit {
|
|
|
32
30
|
private readonly jwtService: JwtService,
|
|
33
31
|
) { }
|
|
34
32
|
|
|
35
|
-
async onModuleInit() {
|
|
36
|
-
await this.getProvider();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
33
|
async getProvider(): Promise<AbstractProvider> {
|
|
40
|
-
|
|
34
|
+
const settings = await this.settingService.getSettingValues([
|
|
41
35
|
'storage',
|
|
42
36
|
'storage-local-path',
|
|
43
37
|
'storage-s3-key',
|
|
@@ -52,16 +46,16 @@ export class FileService implements OnModuleInit {
|
|
|
52
46
|
'storage-gcs-keyfile',
|
|
53
47
|
]);
|
|
54
48
|
|
|
55
|
-
if (!
|
|
49
|
+
if (!settings['storage']) {
|
|
56
50
|
throw new BadRequestException(
|
|
57
51
|
`You must set the storage provider in the setting.`,
|
|
58
52
|
);
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
const providerName =
|
|
55
|
+
const providerName = settings['storage'];
|
|
62
56
|
const provider = ProviderFactory.create(
|
|
63
57
|
providerName as EnumProvider,
|
|
64
|
-
|
|
58
|
+
settings ,
|
|
65
59
|
);
|
|
66
60
|
|
|
67
61
|
const providerData = await this.prismaService.file_provider.findFirst({
|
|
@@ -114,10 +108,24 @@ export class FileService implements OnModuleInit {
|
|
|
114
108
|
throw new BadRequestException(`No mimetype provided`);
|
|
115
109
|
}
|
|
116
110
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
await this.getProvider();
|
|
112
|
+
|
|
113
|
+
const settings = await this.settingService.getSettingValues([
|
|
114
|
+
'storage',
|
|
115
|
+
'storage-local-path',
|
|
116
|
+
'storage-s3-key',
|
|
117
|
+
'storage-s3-secret',
|
|
118
|
+
'storage-s3-region',
|
|
119
|
+
'storage-s3-bucket',
|
|
120
|
+
'storage-max-size',
|
|
121
|
+
'storage-accept-mimetype',
|
|
122
|
+
'storage-abs-account',
|
|
123
|
+
'storage-abs-key',
|
|
124
|
+
'storage-abs-container',
|
|
125
|
+
'storage-gcs-keyfile',
|
|
126
|
+
]);
|
|
127
|
+
|
|
128
|
+
const acceptMimetypes = settings['storage-accept-mimetype'];
|
|
121
129
|
return acceptMimetypes.indexOf(mimetype) !== -1;
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -127,11 +135,24 @@ export class FileService implements OnModuleInit {
|
|
|
127
135
|
throw new BadRequestException(`No size provided`);
|
|
128
136
|
}
|
|
129
137
|
|
|
130
|
-
if (!this.setting || !this.setting['storage-max-size']) {
|
|
131
138
|
await this.getProvider();
|
|
132
|
-
|
|
139
|
+
|
|
140
|
+
const settings = await this.settingService.getSettingValues([
|
|
141
|
+
'storage',
|
|
142
|
+
'storage-local-path',
|
|
143
|
+
'storage-s3-key',
|
|
144
|
+
'storage-s3-secret',
|
|
145
|
+
'storage-s3-region',
|
|
146
|
+
'storage-s3-bucket',
|
|
147
|
+
'storage-max-size',
|
|
148
|
+
'storage-accept-mimetype',
|
|
149
|
+
'storage-abs-account',
|
|
150
|
+
'storage-abs-key',
|
|
151
|
+
'storage-abs-container',
|
|
152
|
+
'storage-gcs-keyfile',
|
|
153
|
+
]);
|
|
133
154
|
|
|
134
|
-
const maxSize =
|
|
155
|
+
const maxSize = settings['storage-max-size'];
|
|
135
156
|
|
|
136
157
|
return size <= Number(maxSize);
|
|
137
158
|
}
|
|
@@ -183,7 +204,11 @@ export class FileService implements OnModuleInit {
|
|
|
183
204
|
}
|
|
184
205
|
|
|
185
206
|
async getStorage() {
|
|
186
|
-
|
|
207
|
+
const settings = await this.settingService.getSettingValues([
|
|
208
|
+
'storage',
|
|
209
|
+
]);
|
|
210
|
+
|
|
211
|
+
return settings['storage'];
|
|
187
212
|
}
|
|
188
213
|
|
|
189
214
|
async getBuffer(fileId: number) {
|
package/src/mail/mail.service.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
Inject,
|
|
9
9
|
Injectable,
|
|
10
10
|
Logger,
|
|
11
|
-
OnModuleInit,
|
|
12
11
|
forwardRef,
|
|
13
12
|
} from '@nestjs/common';
|
|
14
13
|
import * as Handlebars from 'handlebars';
|
|
@@ -20,9 +19,8 @@ import { TestMailDTO } from './dto/test-mail.dto';
|
|
|
20
19
|
import { UpdateDTO } from './dto/update.dto';
|
|
21
20
|
|
|
22
21
|
@Injectable()
|
|
23
|
-
export class MailService
|
|
22
|
+
export class MailService {
|
|
24
23
|
private readonly logger = new Logger(MailService.name);
|
|
25
|
-
public settings: Record<string, any> = {};
|
|
26
24
|
private readonly modelName = 'mail';
|
|
27
25
|
|
|
28
26
|
constructor(
|
|
@@ -38,12 +36,6 @@ export class MailService implements OnModuleInit {
|
|
|
38
36
|
private readonly setting: SettingService,
|
|
39
37
|
) { }
|
|
40
38
|
|
|
41
|
-
async onModuleInit() {
|
|
42
|
-
this.settings = await this.setting.getSettingValues([
|
|
43
|
-
'configured-mail',
|
|
44
|
-
]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
39
|
async list(locale: string, paginationParams: PaginationDTO) {
|
|
48
40
|
const result = await this.localeService.listModelWithLocale(
|
|
49
41
|
locale,
|
|
@@ -256,7 +248,13 @@ export class MailService implements OnModuleInit {
|
|
|
256
248
|
{ email, slug, variables }: SendTemplatedMailDTO,
|
|
257
249
|
) {
|
|
258
250
|
|
|
259
|
-
|
|
251
|
+
const settings = await this.setting.getSettingValues([
|
|
252
|
+
'configured-mail',
|
|
253
|
+
]);
|
|
254
|
+
|
|
255
|
+
console.log({settings});
|
|
256
|
+
|
|
257
|
+
if (!settings['configured-mail']) {
|
|
260
258
|
this.logger.warn('Mail service is not configured. Aborting sending email.');
|
|
261
259
|
return;
|
|
262
260
|
}
|
|
@@ -288,7 +286,6 @@ export class MailService implements OnModuleInit {
|
|
|
288
286
|
} catch (error) {
|
|
289
287
|
this.logger.error('Error sending templated mail:', error);
|
|
290
288
|
await this.setting.setValue('configured-mail', 'false');
|
|
291
|
-
this.onModuleInit();
|
|
292
289
|
}
|
|
293
290
|
}
|
|
294
291
|
|
|
@@ -346,7 +343,14 @@ export class MailService implements OnModuleInit {
|
|
|
346
343
|
body,
|
|
347
344
|
variables,
|
|
348
345
|
}: TestMailDTO) {
|
|
349
|
-
|
|
346
|
+
|
|
347
|
+
const settings = await this.setting.getSettingValues([
|
|
348
|
+
'configured-mail',
|
|
349
|
+
]);
|
|
350
|
+
|
|
351
|
+
console.log({settings});
|
|
352
|
+
|
|
353
|
+
if (!settings['configured-mail']) {
|
|
350
354
|
throw new BadRequestException('Mail service is not configured.');
|
|
351
355
|
}
|
|
352
356
|
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
forwardRef,
|
|
6
6
|
Inject,
|
|
7
7
|
Injectable,
|
|
8
|
-
NotFoundException
|
|
9
|
-
OnModuleInit,
|
|
8
|
+
NotFoundException
|
|
10
9
|
} from '@nestjs/common';
|
|
11
10
|
import { AuthService } from '../auth/auth.service';
|
|
12
11
|
import { FileService } from '../file/file.service';
|
|
@@ -34,9 +33,8 @@ type HandleCallbackProps = {
|
|
|
34
33
|
};
|
|
35
34
|
|
|
36
35
|
@Injectable()
|
|
37
|
-
export class OAuthService
|
|
36
|
+
export class OAuthService {
|
|
38
37
|
private providers: Map<string, OAuthProvider> = new Map();
|
|
39
|
-
public settings: Record<string, any> = {};
|
|
40
38
|
|
|
41
39
|
constructor(
|
|
42
40
|
google: GoogleProvider,
|
|
@@ -60,16 +58,6 @@ export class OAuthService implements OnModuleInit {
|
|
|
60
58
|
this.providers.set(github.getProviderType(), github);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
async onModuleInit() {
|
|
64
|
-
this.settings = await this.setting.getSettingValues([
|
|
65
|
-
'oauth-mfa',
|
|
66
|
-
'google_scopes',
|
|
67
|
-
'facebook_scopes',
|
|
68
|
-
'github_scopes',
|
|
69
|
-
'microsoft_scopes',
|
|
70
|
-
]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
61
|
getAuthUrl(provider: user_account_provider_enum, callbackPath: string) {
|
|
74
62
|
return this.getProvider(provider).getAuthUrl(callbackPath);
|
|
75
63
|
}
|
|
@@ -110,9 +98,18 @@ export class OAuthService implements OnModuleInit {
|
|
|
110
98
|
return prov;
|
|
111
99
|
}
|
|
112
100
|
|
|
113
|
-
private getProviderScopes(provider: user_account_provider_enum)
|
|
101
|
+
private async getProviderScopes(provider: user_account_provider_enum) {
|
|
114
102
|
const settingKey = `${provider.toLowerCase()}_scopes`;
|
|
115
|
-
|
|
103
|
+
|
|
104
|
+
const settings = await this.setting.getSettingValues([
|
|
105
|
+
'oauth-mfa',
|
|
106
|
+
'google_scopes',
|
|
107
|
+
'facebook_scopes',
|
|
108
|
+
'github_scopes',
|
|
109
|
+
'microsoft_scopes',
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
return settings[settingKey].join(',') || '';
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
private async handleLogin(res: Response, locale: string, ipAddress: string, userAgent: string, provider: user_account_provider_enum, profile: any) {
|
|
@@ -143,7 +140,7 @@ export class OAuthService implements OnModuleInit {
|
|
|
143
140
|
} else {
|
|
144
141
|
if (profile.oauth_tokens?.refresh_token) {
|
|
145
142
|
const encryptedRefreshToken = this.security.encrypt(profile.oauth_tokens.refresh_token);
|
|
146
|
-
const scopes = this.getProviderScopes(provider);
|
|
143
|
+
const scopes = await this.getProviderScopes(provider);
|
|
147
144
|
await this.prisma.user_account.update({
|
|
148
145
|
where: { id: userAccount.id },
|
|
149
146
|
data: {
|
|
@@ -183,7 +180,7 @@ export class OAuthService implements OnModuleInit {
|
|
|
183
180
|
}
|
|
184
181
|
|
|
185
182
|
const encryptedRefreshToken = this.security.encrypt(profile.oauth_tokens.refresh_token)
|
|
186
|
-
const scopes = this.getProviderScopes(provider);
|
|
183
|
+
const scopes = await this.getProviderScopes(provider);
|
|
187
184
|
const user = await this.prisma.user.create({
|
|
188
185
|
data: {
|
|
189
186
|
name: profile.name,
|
|
@@ -261,7 +258,7 @@ export class OAuthService implements OnModuleInit {
|
|
|
261
258
|
}
|
|
262
259
|
|
|
263
260
|
const encryptedRefreshToken = this.security.encrypt(profile.oauth_tokens.refresh_token)
|
|
264
|
-
const scopes = this.getProviderScopes(provider);
|
|
261
|
+
const scopes = await this.getProviderScopes(provider);
|
|
265
262
|
await this.prisma.user_account.create({
|
|
266
263
|
data: {
|
|
267
264
|
user_id: userId,
|
|
@@ -5,7 +5,7 @@ import { OAuthProvider } from '../interfaces/OAuthProvider';
|
|
|
5
5
|
export abstract class BaseOAuthProvider implements OAuthProvider {
|
|
6
6
|
constructor(protected readonly http: HttpService) {}
|
|
7
7
|
|
|
8
|
-
abstract getAuthUrl(callbackPath: string): string
|
|
8
|
+
abstract getAuthUrl(callbackPath: string): Promise<string>;
|
|
9
9
|
abstract getProfile(code: string, type?: string): Promise<any>;
|
|
10
10
|
abstract getProviderType(): string;
|
|
11
11
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { HttpService } from '@nestjs/axios';
|
|
2
|
-
import { forwardRef, Inject, Injectable
|
|
2
|
+
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
|
3
3
|
import { SettingService } from '../../setting/setting.service';
|
|
4
4
|
import { BaseOAuthProvider } from './abstract.provider';
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
7
|
export class FacebookProvider
|
|
8
|
-
extends BaseOAuthProvider
|
|
9
|
-
implements OnModuleInit {
|
|
10
|
-
public settings: Record<string, any> = {};
|
|
8
|
+
extends BaseOAuthProvider {
|
|
11
9
|
|
|
12
10
|
constructor(
|
|
13
11
|
http: HttpService,
|
|
@@ -17,27 +15,25 @@ export class FacebookProvider
|
|
|
17
15
|
super(http);
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
getProviderType() {
|
|
19
|
+
return 'FACEBOOK';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getAuthUrl(callbackPath: string) {
|
|
23
|
+
const settings = await this.setting.getSettingValues([
|
|
22
24
|
'facebook_client_id',
|
|
23
25
|
'facebook_client_secret',
|
|
24
26
|
'facebook_scopes',
|
|
25
27
|
'url',
|
|
26
28
|
]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getProviderType() {
|
|
30
|
-
return 'FACEBOOK';
|
|
31
|
-
}
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
const redirectURI = new URL(callbackPath, this.settings['url']).toString();
|
|
30
|
+
const redirectURI = new URL(callbackPath, settings['url']).toString();
|
|
35
31
|
|
|
36
32
|
const params = new URLSearchParams({
|
|
37
|
-
client_id:
|
|
33
|
+
client_id: settings['facebook_client_id'],
|
|
38
34
|
redirect_uri: redirectURI,
|
|
39
35
|
response_type: 'code',
|
|
40
|
-
scope: (
|
|
36
|
+
scope: (settings['facebook_scopes'] ?? ['email']).join(','),
|
|
41
37
|
auth_type: 'rerequest',
|
|
42
38
|
});
|
|
43
39
|
|
|
@@ -45,12 +41,20 @@ export class FacebookProvider
|
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
async getProfile(code: string, type: string): Promise<any> {
|
|
44
|
+
|
|
45
|
+
const settings = await this.setting.getSettingValues([
|
|
46
|
+
'facebook_client_id',
|
|
47
|
+
'facebook_client_secret',
|
|
48
|
+
'facebook_scopes',
|
|
49
|
+
'url',
|
|
50
|
+
]);
|
|
51
|
+
|
|
48
52
|
const token = await this.fetchToken({
|
|
49
53
|
code,
|
|
50
54
|
url: 'https://graph.facebook.com/v17.0/oauth/access_token',
|
|
51
|
-
clientId:
|
|
52
|
-
clientSecret:
|
|
53
|
-
redirectUri: `${
|
|
55
|
+
clientId: settings['facebook_client_id'],
|
|
56
|
+
clientSecret: settings['facebook_client_secret'],
|
|
57
|
+
redirectUri: `${settings['url']}/oauth/facebook/callback/${type}`,
|
|
54
58
|
});
|
|
55
59
|
const profile = await this.fetchProfile(
|
|
56
60
|
token.access_token,
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { HttpService } from '@nestjs/axios';
|
|
2
|
-
import { forwardRef, Inject, Injectable
|
|
2
|
+
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
|
3
3
|
import { SettingService } from '../../setting/setting.service';
|
|
4
4
|
import { BaseOAuthProvider } from './abstract.provider';
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
7
|
export class GithubProvider
|
|
8
|
-
extends BaseOAuthProvider
|
|
9
|
-
implements OnModuleInit {
|
|
10
|
-
public settings: Record<string, any> = {};
|
|
8
|
+
extends BaseOAuthProvider {
|
|
11
9
|
|
|
12
10
|
constructor(
|
|
13
11
|
http: HttpService,
|
|
@@ -17,26 +15,25 @@ export class GithubProvider
|
|
|
17
15
|
super(http);
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
getProviderType() {
|
|
19
|
+
return 'GITHUB';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getAuthUrl(callbackPath: string) {
|
|
23
|
+
|
|
24
|
+
const settings = await this.setting.getSettingValues([
|
|
22
25
|
'github_client_id',
|
|
23
26
|
'github_client_secret',
|
|
24
27
|
'github_scopes',
|
|
25
28
|
'api-url',
|
|
26
29
|
]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getProviderType() {
|
|
30
|
-
return 'GITHUB';
|
|
31
|
-
}
|
|
32
30
|
|
|
33
|
-
getAuthUrl(callbackPath: string): string {
|
|
34
31
|
const fixedCallbackPath = '/oauth/github/callback';
|
|
35
|
-
const redirectURI = new URL(fixedCallbackPath,
|
|
36
|
-
const scopes =
|
|
32
|
+
const redirectURI = new URL(fixedCallbackPath, settings['api-url']).toString();
|
|
33
|
+
const scopes = settings['github_scopes'];
|
|
37
34
|
const type = callbackPath.split('/').pop() || 'login';
|
|
38
35
|
const params = new URLSearchParams({
|
|
39
|
-
client_id:
|
|
36
|
+
client_id: settings['github_client_id'],
|
|
40
37
|
redirect_uri: redirectURI,
|
|
41
38
|
scope: scopes.join(' '),
|
|
42
39
|
allow_signup: 'true',
|
|
@@ -47,13 +44,20 @@ export class GithubProvider
|
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
async getProfile(code: string) {
|
|
47
|
+
const settings = await this.setting.getSettingValues([
|
|
48
|
+
'github_client_id',
|
|
49
|
+
'github_client_secret',
|
|
50
|
+
'github_scopes',
|
|
51
|
+
'api-url',
|
|
52
|
+
]);
|
|
53
|
+
|
|
50
54
|
const fixedCallbackPath = '/oauth/github/callback';
|
|
51
|
-
const redirectURI = new URL(fixedCallbackPath,
|
|
55
|
+
const redirectURI = new URL(fixedCallbackPath, settings['api-url'].replace(":3200", ":3100")).toString();
|
|
52
56
|
const tokenResponse = await this.http.axiosRef.post(
|
|
53
57
|
'https://github.com/login/oauth/access_token',
|
|
54
58
|
{
|
|
55
|
-
client_id:
|
|
56
|
-
client_secret:
|
|
59
|
+
client_id: settings['github_client_id'],
|
|
60
|
+
client_secret: settings['github_client_secret'],
|
|
57
61
|
code,
|
|
58
62
|
redirect_uri: redirectURI,
|
|
59
63
|
},
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { HttpService } from '@nestjs/axios';
|
|
2
|
-
import { forwardRef, Inject, Injectable
|
|
2
|
+
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
|
3
3
|
import { SettingService } from '../../setting/setting.service';
|
|
4
4
|
import { BaseOAuthProvider } from './abstract.provider';
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
|
-
export class GoogleProvider extends BaseOAuthProvider
|
|
8
|
-
public settings: Record<string, any> = {};
|
|
7
|
+
export class GoogleProvider extends BaseOAuthProvider {
|
|
9
8
|
|
|
10
9
|
constructor(
|
|
11
10
|
http: HttpService,
|
|
@@ -15,27 +14,26 @@ export class GoogleProvider extends BaseOAuthProvider implements OnModuleInit {
|
|
|
15
14
|
super(http);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
getProviderType() {
|
|
18
|
+
return 'GOOGLE';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getAuthUrl(callbackPath: string) {
|
|
22
|
+
|
|
23
|
+
const settings = await this.setting.getSettingValues([
|
|
20
24
|
'google_client_id',
|
|
21
25
|
'google_client_secret',
|
|
22
26
|
'google_scopes',
|
|
23
27
|
'url',
|
|
24
28
|
]);
|
|
25
|
-
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
return 'GOOGLE';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getAuthUrl(callbackPath: string): string {
|
|
32
|
-
const redirectURI = new URL(callbackPath, this.settings['url']).toString();
|
|
30
|
+
const redirectURI = new URL(callbackPath, settings['url']).toString();
|
|
33
31
|
|
|
34
32
|
const params = new URLSearchParams({
|
|
35
|
-
client_id:
|
|
33
|
+
client_id: settings['google_client_id'],
|
|
36
34
|
redirect_uri: redirectURI,
|
|
37
35
|
response_type: 'code',
|
|
38
|
-
scope: (
|
|
36
|
+
scope: (settings['google_scopes'] ?? []).join(' '),
|
|
39
37
|
access_type: 'offline',
|
|
40
38
|
prompt: 'consent',
|
|
41
39
|
});
|
|
@@ -44,12 +42,20 @@ export class GoogleProvider extends BaseOAuthProvider implements OnModuleInit {
|
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
async getProfile(code: string, type: string) {
|
|
45
|
+
|
|
46
|
+
const settings = await this.setting.getSettingValues([
|
|
47
|
+
'google_client_id',
|
|
48
|
+
'google_client_secret',
|
|
49
|
+
'google_scopes',
|
|
50
|
+
'url',
|
|
51
|
+
]);
|
|
52
|
+
|
|
47
53
|
const token = await this.fetchToken({
|
|
48
54
|
code,
|
|
49
55
|
url: 'https://oauth2.googleapis.com/token',
|
|
50
|
-
clientId:
|
|
51
|
-
clientSecret:
|
|
52
|
-
redirectUri: `${
|
|
56
|
+
clientId: settings['google_client_id'],
|
|
57
|
+
clientSecret: settings['google_client_secret'],
|
|
58
|
+
redirectUri: `${settings['url']}/callback/google/${type}`,
|
|
53
59
|
});
|
|
54
60
|
|
|
55
61
|
const basicProfile = await this.fetchProfile(
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { HttpService } from '@nestjs/axios';
|
|
2
|
-
import { forwardRef, Inject, Injectable
|
|
2
|
+
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
|
3
3
|
import { SettingService } from '../../setting/setting.service';
|
|
4
4
|
import { BaseOAuthProvider } from './abstract.provider';
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
7
|
export class MicrosoftProvider
|
|
8
|
-
extends BaseOAuthProvider
|
|
9
|
-
implements OnModuleInit {
|
|
10
|
-
public settings: Record<string, any> = {};
|
|
8
|
+
extends BaseOAuthProvider {
|
|
11
9
|
|
|
12
10
|
constructor(
|
|
13
11
|
http: HttpService,
|
|
@@ -17,24 +15,23 @@ export class MicrosoftProvider
|
|
|
17
15
|
super(http);
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
getProviderType() {
|
|
19
|
+
return 'MICROSOFT';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getAuthUrl(callbackPath: string) {
|
|
23
|
+
|
|
24
|
+
const settings = await this.setting.getSettingValues([
|
|
22
25
|
'microsoft_client_id',
|
|
23
26
|
'microsoft_client_secret',
|
|
24
27
|
'microsoft_scopes',
|
|
25
28
|
'url',
|
|
26
29
|
]);
|
|
27
|
-
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getAuthUrl(callbackPath: string): string {
|
|
34
|
-
const redirectURI = new URL(callbackPath, this.settings['url']).toString();
|
|
35
|
-
const scopes = this.settings['microsoft_scopes']
|
|
31
|
+
const redirectURI = new URL(callbackPath, settings['url']).toString();
|
|
32
|
+
const scopes = settings['microsoft_scopes']
|
|
36
33
|
const params = new URLSearchParams({
|
|
37
|
-
client_id:
|
|
34
|
+
client_id: settings['microsoft_client_id'],
|
|
38
35
|
redirect_uri: redirectURI,
|
|
39
36
|
response_type: 'code',
|
|
40
37
|
scope: scopes.join(' '),
|
|
@@ -46,12 +43,20 @@ export class MicrosoftProvider
|
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
async getProfile(code: string, type: string): Promise<any> {
|
|
46
|
+
|
|
47
|
+
const settings = await this.setting.getSettingValues([
|
|
48
|
+
'microsoft_client_id',
|
|
49
|
+
'microsoft_client_secret',
|
|
50
|
+
'microsoft_scopes',
|
|
51
|
+
'url',
|
|
52
|
+
]);
|
|
53
|
+
|
|
49
54
|
const token = await this.fetchToken({
|
|
50
55
|
code,
|
|
51
56
|
url: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
|
|
52
|
-
clientId:
|
|
53
|
-
clientSecret:
|
|
54
|
-
redirectUri: `${
|
|
57
|
+
clientId: settings['microsoft_client_id'],
|
|
58
|
+
clientSecret: settings['microsoft_client_secret'],
|
|
59
|
+
redirectUri: `${settings['url']}/callback/microsoft/${type}`,
|
|
55
60
|
});
|
|
56
61
|
|
|
57
62
|
const profile = await this.fetchProfile(
|