Google oauth not returning email passport authentication

前端 未结 4 967
小鲜肉
小鲜肉 2021-01-04 03:28

I am trying to make a sign in with google button using passport module of node js. I am trying to get person\'s email id, name, profile pic. I am trying to download pic to l

相关标签:
4条回答
  • 2021-01-04 03:33

    According to google documentation for oauth, the first parameter has to be openid and the second can be email or profile, or both

    app.get('/auth/google',
        passport.authenticate('google', {scope: ['openid', 'email', 'profile']})
    );
    

    documentation

    0 讨论(0)
  • 2021-01-04 03:34

    Add the line of code after callbackUrl.

    userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo"
    
    0 讨论(0)
  • 2021-01-04 03:51

    The above answer definitely works, there is also one more way to approach this.

    app.get('/auth/google',
      passport.authenticate('google', { scope: ['profile', 'email'] })
    );
    

    In your routes.js with the profile add email.

    This should resolve your issue.

    0 讨论(0)
  • 2021-01-04 03:56

    I had the same problem and wrote the scope in this way:

    app.get('/connect/google', passport.authenticate('google', {
        scope: [
            'https://www.googleapis.com/auth/userinfo.profile',
            'https://www.googleapis.com/auth/userinfo.email'
        ]
    }));
    

    And you will get the email:

    function(accessToken, refreshToken, profile, done) {
        console.log(profile.emails[0].value);
    }); 
    

    I hope this helps you.

    0 讨论(0)
提交回复
热议问题