@solidstarters/solid-core 1.2.10 → 1.2.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/controllers/google-authentication.controller.d.ts +1 -0
- package/dist/controllers/google-authentication.controller.d.ts.map +1 -1
- package/dist/controllers/google-authentication.controller.js +12 -1
- package/dist/controllers/google-authentication.controller.js.map +1 -1
- package/dist/helpers/google-oauth.helper.d.ts +4 -0
- package/dist/helpers/google-oauth.helper.d.ts.map +1 -0
- package/dist/helpers/google-oauth.helper.js +9 -0
- package/dist/helpers/google-oauth.helper.js.map +1 -0
- package/dist/passport-strategies/google-oauth.strategy.d.ts +3 -4
- package/dist/passport-strategies/google-oauth.strategy.d.ts.map +1 -1
- package/dist/passport-strategies/google-oauth.strategy.js +19 -14
- package/dist/passport-strategies/google-oauth.strategy.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/controllers/google-authentication.controller.ts +14 -2
- package/src/helpers/google-oauth.helper.ts +9 -0
- package/src/passport-strategies/google-oauth.strategy.ts +18 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidstarters/solid-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.11",
|
|
4
4
|
"description": "This module is a NestJS module containing all the required core providers required by a Solid application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Controller, Get, Inject, Query, Req, Res, UseGuards } from '@nestjs/common';
|
|
1
|
+
import { Controller, Get, Inject, InternalServerErrorException, Query, Req, Res, UseGuards } from '@nestjs/common';
|
|
2
2
|
import { AuthenticationService } from '../services/authentication.service';
|
|
3
3
|
import { Auth } from '../decorators/auth.decorator';
|
|
4
4
|
import { AuthType } from '../enums/auth-type.enum';
|
|
@@ -9,6 +9,7 @@ import { ConfigType } from '@nestjs/config';
|
|
|
9
9
|
import { UserService } from '../services/user.service';
|
|
10
10
|
import { Public } from '../decorators/public.decorator';
|
|
11
11
|
import { iamConfig } from '../config/iam.config';
|
|
12
|
+
import { isGoogleOAuthConfigured } from 'src/helpers/google-oauth.helper';
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
@Auth(AuthType.None)
|
|
@@ -24,12 +25,21 @@ export class GoogleAuthenticationController {
|
|
|
24
25
|
@Public()
|
|
25
26
|
@UseGuards(GoogleOauthGuard)
|
|
26
27
|
@Get('connect')
|
|
27
|
-
async connect() {
|
|
28
|
+
async connect() {
|
|
29
|
+
this.validateConfiguration();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private validateConfiguration() {
|
|
33
|
+
if (!isGoogleOAuthConfigured(this.iamConfiguration)) {
|
|
34
|
+
throw new InternalServerErrorException('Google OAuth is not configured');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
28
37
|
|
|
29
38
|
@Public()
|
|
30
39
|
@Get('connect/callback')
|
|
31
40
|
@UseGuards(GoogleOauthGuard)
|
|
32
41
|
googleAuthCallback(@Req() req: Request, @Res() res: Response) {
|
|
42
|
+
this.validateConfiguration();
|
|
33
43
|
const user = req.user;
|
|
34
44
|
|
|
35
45
|
// console.log(`Found user: ${JSON.stringify(user)}`);
|
|
@@ -55,6 +65,7 @@ export class GoogleAuthenticationController {
|
|
|
55
65
|
@Public()
|
|
56
66
|
@Get('dummy-redirect')
|
|
57
67
|
async dummyGoogleAuthRedirect(@Query('accessCode') accessCode) {
|
|
68
|
+
this.validateConfiguration();
|
|
58
69
|
const user = await this.userService.findOneByAccessCode(accessCode);
|
|
59
70
|
|
|
60
71
|
delete user['password'];
|
|
@@ -73,6 +84,7 @@ export class GoogleAuthenticationController {
|
|
|
73
84
|
@Get('authenticate')
|
|
74
85
|
@ApiQuery({ name: 'accessCode', required: true, type: String })
|
|
75
86
|
async googleAuth(@Query('accessCode') accessCode) {
|
|
87
|
+
this.validateConfiguration();
|
|
76
88
|
return this.authService.signInUsingGoogle(accessCode);
|
|
77
89
|
}
|
|
78
90
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConfigType } from "@nestjs/config";
|
|
2
|
+
import { iamConfig } from "src/config/iam.config";
|
|
3
|
+
|
|
4
|
+
export function isGoogleOAuthConfigured(iamConfiguration: ConfigType<typeof iamConfig>): boolean {
|
|
5
|
+
const googleOauthConfig = iamConfiguration.googleOauth;
|
|
6
|
+
|
|
7
|
+
return !!googleOauthConfig.clientID
|
|
8
|
+
&& !!googleOauthConfig.clientSecret && !!googleOauthConfig.callbackURL && !!googleOauthConfig.redirectURL;
|
|
9
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { Inject, Injectable, Logger } from '@nestjs/common';
|
|
1
2
|
import { ConfigType } from '@nestjs/config';
|
|
2
|
-
import { PassportStrategy } from '@nestjs/passport';
|
|
3
|
+
import { AuthGuard, PassportStrategy } from '@nestjs/passport';
|
|
3
4
|
import { Strategy, VerifyCallback } from 'passport-google-oauth2';
|
|
4
|
-
import {
|
|
5
|
-
import { AuthGuard } from '@nestjs/passport';
|
|
5
|
+
import { isGoogleOAuthConfigured } from 'src/helpers/google-oauth.helper';
|
|
6
6
|
import { v4 as uuid } from 'uuid';
|
|
7
|
-
import { AuthenticationService } from '../services/authentication.service';
|
|
8
|
-
import { UserService } from '../services/user.service';
|
|
9
7
|
import { iamConfig } from '../config/iam.config';
|
|
8
|
+
import { UserService } from '../services/user.service';
|
|
10
9
|
|
|
10
|
+
const DUMMY_CLIENT_ID = 'DUMMY_CLIENT_ID';
|
|
11
|
+
const DUMMY_CLIENT_SECRET = 'DUMMY_CLIENT_SECRET';
|
|
12
|
+
const DUMMY_CALLBACK_URL = 'DUMMY_CALLBACK_URL';
|
|
11
13
|
|
|
12
14
|
@Injectable()
|
|
13
15
|
export class GoogleOauthGuard extends AuthGuard('google') { }
|
|
@@ -15,17 +17,23 @@ export class GoogleOauthGuard extends AuthGuard('google') { }
|
|
|
15
17
|
|
|
16
18
|
@Injectable()
|
|
17
19
|
export class GoogleOauthStrategy extends PassportStrategy(Strategy, 'google') {
|
|
20
|
+
private readonly logger = new Logger(GoogleOauthStrategy.name);
|
|
18
21
|
constructor(
|
|
19
22
|
@Inject(iamConfig.KEY) private iamConfiguration: ConfigType<typeof iamConfig>,
|
|
20
|
-
private readonly authService: AuthenticationService,
|
|
21
23
|
private readonly userService: UserService
|
|
22
24
|
) {
|
|
25
|
+
// TODO: Have added default dummy values for the configuration, since the configuration is not mandatory.
|
|
26
|
+
// Perhaps a cleaner way needs to be figured out
|
|
23
27
|
super({
|
|
24
|
-
clientID: iamConfiguration.googleOauth.clientID,
|
|
25
|
-
clientSecret: iamConfiguration.googleOauth.clientSecret,
|
|
26
|
-
callbackURL: iamConfiguration.googleOauth.callbackURL,
|
|
28
|
+
clientID: iamConfiguration.googleOauth.clientID ?? DUMMY_CLIENT_ID,
|
|
29
|
+
clientSecret: iamConfiguration.googleOauth.clientSecret ?? DUMMY_CLIENT_SECRET,
|
|
30
|
+
callbackURL: iamConfiguration.googleOauth.callbackURL ?? DUMMY_CALLBACK_URL,
|
|
27
31
|
scope: ['profile', 'email'],
|
|
28
32
|
});
|
|
33
|
+
|
|
34
|
+
if (!isGoogleOAuthConfigured(iamConfiguration)) {
|
|
35
|
+
this.logger.debug('Google OAuth strategy is not configured');
|
|
36
|
+
}
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
async validate(
|
|
@@ -55,4 +63,5 @@ export class GoogleOauthStrategy extends PassportStrategy(Strategy, 'google') {
|
|
|
55
63
|
|
|
56
64
|
done(null, user);
|
|
57
65
|
}
|
|
66
|
+
|
|
58
67
|
}
|