Skip to content

Commit aaf9a6d

Browse files
authored
Merge pull request #404 from robertjustjones/empty-client-secret
Allow missing or empty clientSecret when not required
2 parents 3e0196c + c268446 commit aaf9a6d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/handlers/token-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TokenHandler.prototype.getClient = function(request, response) {
128128
throw new InvalidRequestError('Invalid parameter: `client_id`');
129129
}
130130

131-
if (!is.vschar(credentials.clientSecret)) {
131+
if (credentials.clientSecret && !is.vschar(credentials.clientSecret)) {
132132
throw new InvalidRequestError('Invalid parameter: `client_secret`');
133133
}
134134

test/integration/handlers/token-handler_test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,38 @@ describe('TokenHandler integration', function() {
553553
});
554554
});
555555

556+
describe('with `password` grant type and `requireClientAuthentication` is false and Authorization header', function() {
557+
558+
it('should return a client ', function() {
559+
var client = { id: 12345, grants: [] };
560+
var model = {
561+
getClient: function() { return client; },
562+
saveToken: function() {}
563+
};
564+
565+
var handler = new TokenHandler({
566+
accessTokenLifetime: 120,
567+
model: model,
568+
refreshTokenLifetime: 120,
569+
requireClientAuthentication: {
570+
password: false
571+
}
572+
});
573+
var request = new Request({
574+
body: { grant_type: 'password'},
575+
headers: { 'authorization': util.format('Basic %s', new Buffer('blah:').toString('base64')) },
576+
method: {},
577+
query: {}
578+
});
579+
580+
return handler.getClient(request)
581+
.then(function(data) {
582+
data.should.equal(client);
583+
})
584+
.catch(should.fail);
585+
});
586+
});
587+
556588
it('should support promises', function() {
557589
var model = {
558590
getClient: function() { return Promise.resolve({ grants: [] }); },

0 commit comments

Comments
 (0)