Skip to content

Commit 0050abf

Browse files
committed
Expose user and client to generateToken.
Closes oauthjs#120 Closes oauthjs#124 Closes oauthjs#132
1 parent a5b3135 commit 0050abf

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/grant.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var fns = [
3131
checkClient,
3232
checkGrantTypeAllowed,
3333
checkGrantType,
34+
exposeParams,
3435
generateAccessToken,
3536
saveAccessToken,
3637
generateRefreshToken,
@@ -342,6 +343,23 @@ function checkGrantTypeAllowed (done) {
342343
});
343344
}
344345

346+
/**
347+
* Expose user and client params
348+
*
349+
* @param {Function} done
350+
* @this OAuth
351+
*/
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+
};
358+
this.req.user = this.user;
359+
360+
done();
361+
}
362+
345363
/**
346364
* Generate an access token
347365
*

test/grant.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,40 @@ describe('Grant', function() {
252252

253253
});
254254

255+
it('should include client and user in request', function (done) {
256+
var app = bootstrap({
257+
model: {
258+
getClient: function (id, secret, callback) {
259+
callback(false, true);
260+
},
261+
grantTypeAllowed: function (clientId, grantType, callback) {
262+
callback(false, true);
263+
},
264+
getUser: function (uname, pword, callback) {
265+
callback(false, { id: 1 });
266+
},
267+
generateToken: function (type, req, callback) {
268+
req.oauth.client.id.should.equal('thom');
269+
req.oauth.client.secret.should.equal('nightworld');
270+
req.user.id.should.equal(1);
271+
callback(false, 'thommy');
272+
},
273+
saveAccessToken: function (token, clientId, expires, user, cb) {
274+
token.should.equal('thommy');
275+
cb();
276+
}
277+
},
278+
grants: ['password']
279+
});
280+
281+
request(app)
282+
.post('/oauth/token')
283+
.set('Content-Type', 'application/x-www-form-urlencoded')
284+
.send(validBody)
285+
.expect(200, /thommy/, done);
286+
287+
});
288+
255289
it('should reissue if model returns object', function (done) {
256290
var app = bootstrap({
257291
model: {

0 commit comments

Comments
 (0)