Giter VIP home page Giter VIP logo

Comments (11)

WaldoJeffers avatar WaldoJeffers commented on August 15, 2024

Any update on this ? This is quite frustrating, as this is used in Client-Side & Hybrid flow. And also, this is what Google encourages developpers to do.

from passport-google-oauth.

tamird avatar tamird commented on August 15, 2024

My PR that fixes this has been open since march :(

from passport-google-oauth.

resoliwan avatar resoliwan commented on August 15, 2024

it is ugly hack but not modify library it self;

var googleStrategy = new GoogleStrategy({
    clientID: Config.google_client_id,
    clientSecret: Config.google_client_secret,
    callbackURL: Config.google_callback_url
  },
  function (accessToken, refreshToken, profile, done) {
    process.nextTick(function () {
      profile.accessToken = accessToken;
      return done(null, profile);
    });
  }
)

googleStrategy.authenticate  = function(req, options) {
  var url = require('url');
  function originalURL(req) {
    var headers = req.headers
      , protocol = (req.connection.encrypted || req.headers['x-forwarded-proto'] == 'https')
        ? 'https'
        : 'http'
      , host = headers.host
      , path = req.url || '';
    return protocol + '://' + host + path;
  };

  options = options || {};
  var self = this;

  if (req.query && req.query.error) {
    // TODO: Error information pertaining to OAuth 2.0 flows is encoded in the
    //       query parameters, and should be propagated to the application.
    return this.fail();
  }
  var callbackURL = options.callbackURL;
  if (callbackURL) {
    var parsed = url.parse(callbackURL);
    if (!parsed.protocol) {
      // The callback URL is relative, resolve a fully qualified URL from the
      // URL of the originating request.
      callbackURL = url.resolve(originalURL(req), callbackURL);
    }
  }
  if (req.query && req.query.code) {
    var code = req.query.code;
    // NOTE: The module oauth (0.9.5), which is a dependency, automatically adds
    //       a 'type=web_server' parameter to the percent-encoded data sent in
    //       the body of the access token request.  This appears to be an
    //       artifact from an earlier draft of OAuth 2.0 (draft 22, as of the
    //       time of this writing).  This parameter is not necessary, but its
    //       presence does not appear to cause any issues.

    var params = {grant_type: 'authorization_code'};
    if(options.hasOwnProperty('callbackURL')) params.redirect_uri = callbackURL;
    this._oauth2.getOAuthAccessToken(code, params,
      function(err, accessToken, refreshToken, params) {
        if (err) { return self.error(new Error('failed to obtain access token', err)); }

        self._loadUserProfile(accessToken, function(err, profile) {
          if (err) { return self.error(err); };

          function verified(err, user, info) {
            if (err) { return self.error(err); }
            if (!user) { return self.fail(info); }
            self.success(user, info);
          }

          if (self._passReqToCallback) {
            var arity = self._verify.length;
            if (arity == 6) {
              self._verify(req, accessToken, refreshToken, params, profile, verified);
            } else { // arity == 5
              self._verify(req, accessToken, refreshToken, profile, verified);
            }
          } else {
            var arity = self._verify.length;
            if (arity == 5) {
              self._verify(accessToken, refreshToken, params, profile, verified);
            } else { // arity == 4
              self._verify(accessToken, refreshToken, profile, verified);
            }
          }
        });
      }
    );
  } else {
    // NOTE: The module oauth (0.9.5), which is a dependency, automatically adds
    //       a 'type=web_server' parameter to the query portion of the URL.
    //       This appears to be an artifact from an earlier draft of OAuth 2.0
    //       (draft 22, as of the time of this writing).  This parameter is not
    //       necessary, but its presence does not appear to cause any issues.

    var params = this.authorizationParams(options);
    params['response_type'] = 'code';
    params['redirect_uri'] = callbackURL;
    var scope = options.scope || this._scope;
    if (scope) {
      if (Array.isArray(scope)) { scope = scope.join(this._scopeSeparator); }
      params.scope = scope;
    }
    var state = options.state;
    if (state) { params.state = state; }

    var location = this._oauth2.getAuthorizeUrl(params);
    this.redirect(location);
  }
}

passport.use(googleStrategy);


//using at controller

passport.authenticate('google', {scope: ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'] }, function (err, profile, info) {
    logger.debug(profile);
    var error = err || info;
    if(err) return res.send(200, common.ERROR(req, err));

    return loginBySns(profile, req, res, next);

  })(req, res, next);

from passport-google-oauth.

WaldoJeffers avatar WaldoJeffers commented on August 15, 2024

Thanks for the feedback ! But I still find it crazy to have to do this kind of hack just to get passport to work with Google's most popular authentication flow. I'm thinking about switching to another module, since @jaredhanson doesn't seem to care about this issue. In my opinion, it's not even close to a feature request, it's a gigantic bug.

The other day, I came across passport-google-plus module, but it's not by Jared, and it hasn't been updated for 6 months, so I'm not feeling comfortable using it.

from passport-google-oauth.

neurotech avatar neurotech commented on August 15, 2024

This is getting a bit crazy. Does anyone know where @jaredhanson has gone?

from passport-google-oauth.

iDVB avatar iDVB commented on August 15, 2024

+1 ?

from passport-google-oauth.

tobernguyen avatar tobernguyen commented on August 15, 2024

+1 ?

from passport-google-oauth.

AndrejGajdos avatar AndrejGajdos commented on August 15, 2024

+1

from passport-google-oauth.

glazs avatar glazs commented on August 15, 2024

Still there

from passport-google-oauth.

praneshkmr avatar praneshkmr commented on August 15, 2024

callbackURL should be configurable

from passport-google-oauth.

iamgabrielsoft avatar iamgabrielsoft commented on August 15, 2024

I had the issue at first doing some reasearch i found the problem

The problem lies how your defining your URL in the config, Make sure your url is the same with the one at your Google Console

🤞🤞🤞🤞🤞🤞🤞🤞🤞🤞🤞🤞🤞🤞

from passport-google-oauth.

Related Issues (20)

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.