Code Monkey home page Code Monkey logo

passport-token-google's People

Contributors

davidep87 avatar karlosq avatar mdslab87 avatar razvancristian avatar satyarth-upadhyaya avatar svindler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

passport-token-google's Issues

The id field of profile returned is undefined

According to google developer guide:
https://developers.google.com/identity/sign-in/web/backend-auth

The id is returned in the payload as sub. A small fix is needed in strategy.js as
profile.id = json.id || json.sub;

GoogleTokenStrategy.prototype.userprofile becomes something like

GoogleTokenStrategy.prototype.userProfile = function(accessToken, done) {
  var profileUrl = 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token='+accessToken;
  this._oauth2.get(profileUrl, null, function (err, body, res) {
    if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }

    try {
      var json = JSON.parse(body);

      var profile = { provider: 'google' };
      profile.id = json.id || json.sub;
      profile.displayName = json.name;
      profile.name = { familyName: json.family_name,
                       givenName: json.given_name };
      profile.emails = [{ value: json.email }];

      profile._raw = body;
      profile._json = json;

      done(null, profile);
    } catch(e) {
      done(e);
    }
  });
}

Sent a pull request for the fix.

Issue with profileUrl

Hello, i spent some time debugging why this wasn't working and I found out that this line:
var profileUrl = 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token='+accessToken;
should actually be
var profileUrl = 'https://www.googleapis.com/oauth2/v3/tokeninfo?access_token='+accessToken;

Maybe the google api has changed? Id token does nothing and it fails with an unauthorized code.

Edit: Actually, I confused the id_token with the access_token. The module expects an id_token apparently. You should update the documentation to specify that the id_token should be used or use the https://www.googleapis.com/oauth2/v3/userinfo?access_token= url.

profileUrl incorrectly has a query parameter of id_token

According to the readme, any requests to authenticate require a access_token parameter. However, the profileUrl has a parameter of id_token. Passing in an access token does not work.

CodeRef:
GoogleTokenStrategy.prototype.userProfile = function(accessToken, done) { var profileUrl = 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token='+accessToken; this._oauth2.get(profileUrl, null, function (err, body, res) {...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.