Skip to content

Commit

Permalink
Expose user and client to generateToken.
Browse files Browse the repository at this point in the history
Closes oauthjs#120
Closes oauthjs#124
Closes oauthjs#132
  • Loading branch information
thomseddon authored and nunofgs committed Feb 10, 2015
1 parent 79d1f81 commit 81bdf29
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var fns = [
checkClient,
checkGrantTypeAllowed,
checkGrantType,
exposeParams,
generateAccessToken,
saveAccessToken,
generateRefreshToken,
Expand Down Expand Up @@ -342,6 +343,23 @@ function checkGrantTypeAllowed (done) {
});
}

/**
* Expose user and client params
*
* @param {Function} done
* @this OAuth
*/
function exposeParams (done) {
this.req.oauth = this.req.oauth || {};
this.req.oauth.client = {
id: this.client.clientId,
secret: this.client.clientSecret
};
this.req.user = this.user;

done();
}

/**
* Generate an access token
*
Expand Down
34 changes: 34 additions & 0 deletions test/grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,40 @@ describe('Grant', function() {

});

it('should include client and user in request', function (done) {
var app = bootstrap({
model: {
getClient: function (id, secret, callback) {
callback(false, true);
},
grantTypeAllowed: function (clientId, grantType, callback) {
callback(false, true);
},
getUser: function (uname, pword, callback) {
callback(false, { id: 1 });
},
generateToken: function (type, req, callback) {
req.oauth.client.id.should.equal('thom');
req.oauth.client.secret.should.equal('nightworld');
req.user.id.should.equal(1);
callback(false, 'thommy');
},
saveAccessToken: function (token, clientId, expires, user, cb) {
token.should.equal('thommy');
cb();
}
},
grants: ['password']
});

request(app)
.post('/oauth/token')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send(validBody)
.expect(200, /thommy/, done);

});

it('should reissue if model returns object', function (done) {
var app = bootstrap({
model: {
Expand Down

0 comments on commit 81bdf29

Please sign in to comment.