Skip to content

Commit 332cde3

Browse files
committed
Merge pull request oauthjs#143 from thomseddon/fix/expose-validated-client-creds-to-extended-grant
Expose validated client for extended grant
2 parents 5cf4504 + 9c4e9b1 commit 332cde3

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

lib/grant.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var fns = [
3131
checkClient,
3232
checkGrantTypeAllowed,
3333
checkGrantType,
34-
exposeParams,
34+
exposeUser,
3535
generateAccessToken,
3636
saveAccessToken,
3737
generateRefreshToken,
@@ -132,6 +132,7 @@ function credsFromBody (req) {
132132
* @this OAuth
133133
*/
134134
function checkClient (done) {
135+
var self = this;
135136
this.model.getClient(this.client.clientId, this.client.clientSecret,
136137
function (err, client) {
137138
if (err) return done(error('server_error', false, err));
@@ -140,6 +141,9 @@ function checkClient (done) {
140141
return done(error('invalid_client', 'Client credentials are invalid'));
141142
}
142143

144+
// Expose validated client
145+
self.req.oauth = { client: client };
146+
143147
done();
144148
});
145149
}
@@ -344,17 +348,12 @@ function checkGrantTypeAllowed (done) {
344348
}
345349

346350
/**
347-
* Expose user and client params
351+
* Expose user
348352
*
349353
* @param {Function} done
350354
* @this OAuth
351355
*/
352-
function exposeParams (done) {
353-
this.req.oauth = this.req.oauth || {};
354-
this.req.oauth.client = {
355-
id: this.client.clientId,
356-
secret: this.client.clientSecret
357-
};
356+
function exposeUser (done) {
358357
this.req.user = this.user;
359358

360359
done();

test/grant.extended.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ describe('Granting with extended grant type', function () {
121121
var app = bootstrap({
122122
model: {
123123
getClient: function (id, secret, callback) {
124-
callback(false, true);
124+
callback(false, { clientId: 'thom', clientSecret: 'nightworld' });
125125
},
126126
grantTypeAllowed: function (clientId, grantType, callback) {
127127
callback(false, true);
128128
},
129129
extendedGrant: function (grantType, req, callback) {
130+
req.oauth.client.clientId.should.equal('thom');
131+
req.oauth.client.clientSecret.should.equal('nightworld');
130132
callback(false, true, { id: 3 });
131133
},
132134
saveAccessToken: function () {

test/grant.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ describe('Grant', function() {
256256
var app = bootstrap({
257257
model: {
258258
getClient: function (id, secret, callback) {
259-
callback(false, true);
259+
callback(false, { clientId: 'thom', clientSecret: 'nightworld' });
260260
},
261261
grantTypeAllowed: function (clientId, grantType, callback) {
262262
callback(false, true);
@@ -265,8 +265,8 @@ describe('Grant', function() {
265265
callback(false, { id: 1 });
266266
},
267267
generateToken: function (type, req, callback) {
268-
req.oauth.client.id.should.equal('thom');
269-
req.oauth.client.secret.should.equal('nightworld');
268+
req.oauth.client.clientId.should.equal('thom');
269+
req.oauth.client.clientSecret.should.equal('nightworld');
270270
req.user.id.should.equal(1);
271271
callback(false, 'thommy');
272272
},

0 commit comments

Comments
 (0)