-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgoogle.strategy.ts
More file actions
43 lines (36 loc) · 1.24 KB
/
google.strategy.ts
File metadata and controls
43 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Inject, Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
private static logger = new Logger(GoogleStrategy.name);
constructor(
@Inject(ConfigService)
configService: ConfigService,
) {
const GOOGLE_CLIENT_ID =
configService.getOrThrow<string>('GOOGLE_CLIENT_ID');
const GOOGLE_CLIENT_SECRET = configService.getOrThrow<string>(
'GOOGLE_CLIENT_SECRET',
);
const SERVER_URL = configService.getOrThrow<string>('SERVER_URL');
const callbackURL = `${SERVER_URL}/api/v1/auth/google/callback`;
GoogleStrategy.logger.debug(`Google Login callbackURL ${callbackURL}`);
super({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: callbackURL,
scope: ['email', 'profile'],
});
}
validate(
accessToken: string,
refreshToken: string,
profile: any,
done: VerifyCallback,
): any {
GoogleStrategy.logger.debug(`Google Login Data ${JSON.stringify(profile)}`);
done(null, profile);
}
}