diff --git a/lib/passport-http-oauth/strategies/consumer.js b/lib/passport-http-oauth/strategies/consumer.js index 678796f..f73e984 100644 --- a/lib/passport-http-oauth/strategies/consumer.js +++ b/lib/passport-http-oauth/strategies/consumer.js @@ -122,6 +122,8 @@ function ConsumerStrategy(options, consumer, token, validate) { this._consumer = consumer; this._token = token; this._validate = validate; + this._scheme = options.scheme || 'http'; + this._secureScheme = options.secureScheme || 'https'; this._host = options.host || null; this._realm = options.realm || 'Clients'; this._ignoreVersion = options.ignoreVersion || false; @@ -273,7 +275,7 @@ ConsumerStrategy.prototype.authenticate = function(req) { } function validate(tokenSecret, ok) { - var url = utils.originalURL(req, self._host) + var url = utils.originalURL(req, self._host, self._scheme, self._secureScheme) , query = req.query , body = req.body; diff --git a/lib/passport-http-oauth/strategies/utils.js b/lib/passport-http-oauth/strategies/utils.js index 8572623..c5429d1 100644 --- a/lib/passport-http-oauth/strategies/utils.js +++ b/lib/passport-http-oauth/strategies/utils.js @@ -20,14 +20,17 @@ var url = require('url') * @return {String} * @api private */ -exports.originalURL = function(req, defaultHost) { +exports.originalURL = function(req, defaultHost, scheme, secureScheme) { var headers = req.headers , protocol = (req.connection.encrypted || req.headers['x-forwarded-proto'] == 'https') - ? 'https' - : 'http' + ? secureScheme + : scheme , host = defaultHost || headers.host , path = req.url || ''; - return protocol + '://' + host + path; + let port = req.headers['x-forwarded-port'] + ? req.headers['x-forwarded-port'] + : (req.connection.encrypted ? 443 : 80) + return protocol + '://' + host + ':' + port + path; }; /**