Skip to content

Commit ab8f30f

Browse files
committed
Authorization header not parsed correctly if it contains extra spaces
1 parent a847812 commit ab8f30f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/passport-http-oauth/strategies/consumer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,12 @@ ConsumerStrategy.prototype.authenticate = function(req) {
144144

145145
if (req.headers && req.headers['authorization']) {
146146
var parts = req.headers['authorization'].split(' ');
147-
if (parts.length == 2) {
148-
var scheme = parts[0]
149-
, credentials = parts[1];
147+
if (parts.length >= 2) {
148+
var scheme = parts[0];
149+
var credentials = null;
150+
151+
parts.shift();
152+
credentials = parts.join(' ');
150153

151154
if (/OAuth/i.test(scheme)) {
152155
params = utils.parseHeader(credentials);
@@ -233,6 +236,7 @@ ConsumerStrategy.prototype.authenticate = function(req) {
233236
return self.success(consumer, info);
234237
});
235238
} else {
239+
236240
// An `oauth_token` is present, containing a request token. In order to
237241
// validate the request, the corresponding token secret needs to be
238242
// retrieved. The application can supply additional `info` about the

lib/passport-http-oauth/strategies/token.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ TokenStrategy.prototype.authenticate = function(req) {
136136

137137
if (req.headers && req.headers['authorization']) {
138138
var parts = req.headers['authorization'].split(' ');
139-
if (parts.length == 2) {
140-
var scheme = parts[0]
141-
, credentials = parts[1];
139+
if (parts.length >= 2) {
140+
var scheme = parts[0];
141+
var credentials = null;
142+
143+
parts.shift();
144+
credentials = parts.join(' ');
142145

143146
if (/OAuth/i.test(scheme)) {
144147
params = utils.parseHeader(credentials);

0 commit comments

Comments
 (0)