Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 10x 2x 2x 2x 2x | import { Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Strategy, VerifyCallback, Profile } from 'passport-google-oauth20'
import { ConfigService } from '@nestjs/config'
import { GoogleAuthUser } from './providers/auth-provider.interface'
@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
constructor(configService: ConfigService) {
super({
clientID: configService.get<string>('GOOGLE_CLIENT_ID') || 'mock_client_id',
clientSecret: configService.get<string>('GOOGLE_CLIENT_SECRET') || 'mock_client_secret',
callbackURL:
configService.get<string>('GOOGLE_CALLBACK_URL') ||
'http://localhost:3000/auth/google/callback',
scope: ['email', 'profile'],
})
}
validate(
accessToken: string,
refreshToken: string,
profile: Profile,
done: VerifyCallback,
): GoogleAuthUser {
const { name, emails, photos } = profile
const user: GoogleAuthUser = {
email: emails && emails[0] ? emails[0].value : '',
firstName: name ? name.givenName : '',
lastName: name ? name.familyName : '',
picture: photos && photos[0] ? photos[0].value : '',
accessToken,
}
done(null, user)
return user
}
}
|