Skip to content

Commit 4dd9d75

Browse files
committed
Add unsupported_grant_type error
See spec: http://tools.ietf.org/html/rfc6749#section-5.2
1 parent 61e922e commit 4dd9d75

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
@@ -31,6 +31,7 @@ function OAuth2Error (error, description, err) {
3131
switch (error) {
3232
case 'invalid_grant':
3333
case 'invalid_request':
34+
case 'unsupported_grant_type':
3435
this.code = 400;
3536
break;
3637
case 'invalid_client':

lib/grant.js

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

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

8082
// Extract credentials
@@ -162,8 +164,7 @@ function checkGrantType (done) {
162164
case 'refresh_token':
163165
return useRefreshTokenGrant.call(this, done);
164166
default:
165-
done(error('invalid_request',
166-
'Invalid grant_type parameter or parameter missing'));
167+
done(error('unsupported_grant_type', 'Unsupported grant type'));
167168
}
168169
}
169170

test/grant.extended.js

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

6565
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
@@ -82,7 +82,7 @@ describe('Grant', function() {
8282
.post('/oauth/token')
8383
.set('Content-Type', 'application/x-www-form-urlencoded')
8484
.send({ grant_type: 'password' })
85-
.expect(400, /invalid or missing grant_type parameter/i, done);
85+
.expect(400, /unsupported grant type/i, done);
8686
});
8787

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

0 commit comments

Comments
 (0)