Skip to content

Instantly share code, notes, and snippets.

@lakinwecker
Created November 11, 2019 22:50
Show Gist options
  • Save lakinwecker/29f6838790682cf93011884118fa45b7 to your computer and use it in GitHub Desktop.
Save lakinwecker/29f6838790682cf93011884118fa45b7 to your computer and use it in GitHub Desktop.
import { Injectable } from '@nestjs/common';
import { OAuth2Strategy } from 'passport-google-oauth';
import * as passport from 'passport';
@Injectable()
export class GoogleStrategy extends OAuth2Strategy {
constructor() {
// http://www.passportjs.org/docs/google/
super({
clientID: YOUR_GOOGLE_CLIENT_ID,
clientSecret: YOUR_GOOGLE_CLIENT_SECRET,
callbackURL: 'http://YOUR_SERVER:YOUR_PORT/auth/google/callback',
passReqToCallback: true,
}, (req, accessToken, refreshToken, profile, done) => {
const user: any = {
email: profile.emails[0].value,
photo: profile.photos[0].value.replace(/sz=50/gi, 'sz=250'),
image: profile._json.image.url,
displayName: profile.displayName,
googleAccount: {
googleId: profile.id,
googleToken: accessToken,
},
};
return done(null, user);
});
passport.use(this);
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment