Skip to content

Commit 24fdd8a

Browse files
committed
Add unsupported_grant_type error
See spec: http://tools.ietf.org/html/rfc6749#section-5.2
1 parent 14d44ae commit 24fdd8a

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

lib/error.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function OAuth2Error (error, description, err) {
4343
switch (error) {
4444
case 'invalid_grant':
4545
case 'invalid_request':
46+
case 'unsupported_grant_type':
4647
this.code = 400;
4748
break;
4849
case 'invalid_client':

lib/grant.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ function extractCredentials (done) {
7373

7474
// Grant type
7575
this.grantType = this.req.body && this.req.body.grant_type;
76-
if (!this.grantType || !this.grantType.match(this.config.regex.grantType)) {
76+
if (!this.grantType) {
7777
return done(error('invalid_request',
7878
'Invalid or missing grant_type parameter'));
79+
} else if (!this.grantType.match(this.config.regex.grantType)) {
80+
return done(error('unsupported_grant_type', 'Unsupported grant type'));
7981
}
8082

8183
// Extract credentials
@@ -165,8 +167,7 @@ function checkGrantType (done) {
165167
case 'client_credentials':
166168
return useClientCredentialsGrant.call(this, done);
167169
default:
168-
done(error('invalid_request',
169-
'Invalid grant_type parameter or parameter missing'));
170+
done(error('unsupported_grant_type', 'Unsupported grant type'));
170171
}
171172
}
172173

test/grant.extended.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Granting with extended grant type', function () {
6060
client_id: 'thom',
6161
client_secret: 'nightworld'
6262
})
63-
.expect(400, /invalid grant_type/i, done);
63+
.expect(400, /unsupported grant type/i, done);
6464
});
6565

6666
it('should still detect unsupported grant_type', function (done) {

test/grant.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('Grant', function() {
8383
.post('/oauth/token')
8484
.set('Content-Type', 'application/x-www-form-urlencoded')
8585
.send({ grant_type: 'password' })
86-
.expect(400, /invalid or missing grant_type parameter/i, done);
86+
.expect(400, /unsupported grant type/i, done);
8787
});
8888

8989
it('should check client_id exists', function (done) {
@@ -179,7 +179,7 @@ describe('Grant', function() {
179179
.post('/oauth/token')
180180
.set('Content-Type', 'application/x-www-form-urlencoded')
181181
.send({ grant_type: 'password', client_id: 'thom', client_secret: 'nightworld' })
182-
.expect(400, /invalid or missing grant_type/i, done);
182+
.expect(400, /unsupported grant type/i, done);
183183
});
184184
});
185185

0 commit comments

Comments
 (0)