Comments (11)
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.
My PR that fixes this has been open since march :(
from passport-google-oauth.
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.
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.
This is getting a bit crazy. Does anyone know where @jaredhanson has gone?
from passport-google-oauth.
+1 ?
from passport-google-oauth.
+1 ?
from passport-google-oauth.
+1
from passport-google-oauth.
Still there
from passport-google-oauth.
callbackURL should be configurable
from passport-google-oauth.
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)
- OAuth2Strategy requires a verify callback how to fix it? HOT 12
- InternalOAuthError "message": "failed to obtained request token" HOT 2
- Support include_granted_scopes [feature request] HOT 1
- how to get the idtoken in the callback for googleStrategy
- Getting user birthday HOT 3
- passReqToCallback slightly inconsistent with Express, doc update? HOT 1
- Passport session not store on google login HOT 1
- Missing required parameter: scope" in app serverless HOT 2
- Changelog for version 2? HOT 1
- Can not get user domain with version 2.0 HOT 4
- howto solve this?
- Disconnecting app from Google account
- PWA and auth link
- id_token
- Restrict To Server Side validation (Needed Feature to verify idToken )
- Error 400: invalid_request Missing required parameter: redirect_uri HOT 1
- InternalOAuthError: Failed to obtain access token HOT 3
- Error 403: disallowed_useragent for a node.js web-site
- Race Condition , accepting new requests before the session of first user finishes HOT 1
- Failed to serialize user into session
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from passport-google-oauth.