Skip to content

Add https option in case some Load Balancer such GCE can not proxy HT… #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function OAuth2Strategy(options, verify) {
}
}
this._trustProxy = options.proxy;
this._https = options.https;
this._passReqToCallback = options.passReqToCallback;
this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile;
}
Expand Down Expand Up @@ -138,7 +139,7 @@ OAuth2Strategy.prototype.authenticate = function(req, options) {
if (!parsed.protocol) {
// The callback URL is relative, resolve a fully qualified URL from the
// URL of the originating request.
callbackURL = url.resolve(utils.originalURL(req, { proxy: this._trustProxy }), callbackURL);
callbackURL = url.resolve(utils.originalURL(req, { proxy: this._trustProxy, https: this._https }), callbackURL);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ exports.originalURL = function(req, options) {
options.proxy = true;
}
var trustProxy = options.proxy;
var https = options.https;

var proto = (req.headers['x-forwarded-proto'] || '').toLowerCase()
, tls = req.connection.encrypted || (trustProxy && 'https' == proto.split(/\s*,\s*/)[0])
, tls = req.connection.encrypted || (trustProxy && 'https' == proto.split(/\s*,\s*/)[0]) || https
, host = (trustProxy && req.headers['x-forwarded-host']) || req.headers.host
, protocol = tls ? 'https' : 'http'
, path = req.url || '';
Expand Down