80f9cc8797
* Remove hasura and hasura-auth * Implement authentication
30 lines
979 B
TypeScript
30 lines
979 B
TypeScript
import { PassportStrategy } from '@nestjs/passport';
|
|
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
|
@Injectable()
|
|
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
|
|
|
constructor(configService: ConfigService) {
|
|
super({
|
|
clientID: configService.get<string>('AUTH_GOOGLE_CLIENT_ID'),
|
|
clientSecret: configService.get<string>('AUTH_GOOGLE_SECRET'),
|
|
callbackURL: configService.get<string>('AUTH_GOOGLE_CALLBACK_URL'),
|
|
scope: ['email', 'profile'],
|
|
});
|
|
}
|
|
|
|
async validate (accessToken: string, refreshToken: string, profile: any, done: VerifyCallback): Promise<any> {
|
|
const { name, emails, photos } = profile
|
|
const user = {
|
|
email: emails[0].value,
|
|
firstName: name.givenName,
|
|
lastName: name.familyName,
|
|
picture: photos[0].value,
|
|
accessToken
|
|
}
|
|
done(null, user);
|
|
}
|
|
} |