Skip to content

Commit

Permalink
Merge pull request #155 from siacomuzzi/arity_5
Browse files Browse the repository at this point in the history
add arity for passing authorization request to token issuing callback
  • Loading branch information
jaredhanson committed Jan 27, 2016
2 parents 921ee48 + fa334d6 commit a7efd68
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/grant/token.js
Expand Up @@ -174,7 +174,9 @@ module.exports = function token(options, issue) {

try {
var arity = issue.length;
if (arity == 4) {
if (arity == 5) {
issue(txn.client, txn.user, txn.res, txn.req, issued);
} else if (arity == 4) {
issue(txn.client, txn.user, txn.res, issued);
} else { // arity == 3
issue(txn.client, txn.user, issued);
Expand Down
37 changes: 37 additions & 0 deletions test/grant/token.test.js
Expand Up @@ -615,6 +615,43 @@ describe('grant.token', function() {
});
});
});

describe('decision handling with user response and client request', function() {
function issue(client, user, ares, areq, done) {
if (client.id == 'c123' && user.id == 'u123' && ares.scope == 'foo' && areq.state == 'f1o1o1') {
return done(null, 'xyz');
}
return done(new Error('something is wrong'));
}

describe('transaction with response scope', function() {
var response;

before(function(done) {
chai.oauth2orize.grant(token(issue))
.txn(function(txn) {
txn.client = { id: 'c123', name: 'Example' };
txn.redirectURI = 'http://example.com/auth/callback';
txn.req = {
redirectURI: 'http://example.com/auth/callback',
state: 'f1o1o1'
};
txn.user = { id: 'u123', name: 'Bob' };
txn.res = { allow: true, scope: 'foo' };
})
.end(function(res) {
response = res;
done();
})
.decide();
});

it('should respond', function() {
expect(response.statusCode).to.equal(302);
expect(response.getHeader('Location')).to.equal('http://example.com/auth/callback#access_token=xyz&token_type=Bearer&state=f1o1o1');
});
});
});

describe('decision handling with response mode', function() {
function issue(client, user, done) {
Expand Down

0 comments on commit a7efd68

Please sign in to comment.