Created
November 11, 2019 22:50
-
-
Save lakinwecker/29f6838790682cf93011884118fa45b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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