Closed kayomarz closed 8 years ago
Solution: If 5 parameters are passed to the callback of the strategy, the 4th parameter has this info. Found this solution here: https://github.com/jaredhanson/passport-google-oauth/issues/6#issuecomment-11054352
passport.use(new passportGoogleOAuth2.OAuth2Strategy(
{...}, // credentials
function(accessToken, refreshToken, X, profile, done) {
// X.id_token
}));
wow thx man u saved my life...cheers!!
how to pass id_token in httprequest is it with headers or body or query or parms or what ?
kayomarz , You saved My day
Someone knows how to solve this in nestjs? because in nestjs I am using the validate method but I cannot acces the params param in the validate method :'c
This is my class:
@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
constructor(private readonly authService: AuthService) {
super({
clientID:
'xxxxx',
clientSecret: 'xxxxxx',
callbackURL: 'http://localhost:8080/auth/google/callback',
scope: ['email', 'profile'],
});
}
async validate(
accessToken: string,
refreshToken: string,
profile: IProfile,
done: VerifyCallback,
): Promise<void> {
console.log({ accessToken, refreshToken, profile, done });
const { name, emails, photos } = profile;
const googleUser = {
email: emails[0].value,
firstName: name.givenName,
lastName: name.familyName,
picture: photos[0].value,
accessToken,
};
const user = await this.authService.googleLogin(googleUser);
console.log(user);
done(null, { ...googleUser, _id: user._id });
}
}
Using Google OAuth2, how do you get hold of the id_token apart from the access_token or refresh_token?