jaredhanson / passport-google-oauth

Google authentication strategies for Passport and Node.js.
https://www.passportjs.org/packages/passport-google-oauth/?utm_source=github&utm_medium=referral&utm_campaign=passport-google-oauth&utm_content=about
MIT License
776 stars 327 forks source link

id_token Google OAuth2 #108

Closed kayomarz closed 8 years ago

kayomarz commented 8 years ago

Using Google OAuth2, how do you get hold of the id_token apart from the access_token or refresh_token?

kayomarz commented 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
  }));
prabhakarupadhyay commented 7 years ago

wow thx man u saved my life...cheers!!

gharShaddi commented 4 years ago

how to pass id_token in httprequest is it with headers or body or query or parms or what ?

nayefmhmd85 commented 3 years ago

kayomarz , You saved My day

Jmiguel14 commented 2 years ago

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 });
  }
}