Skip to content

Commit 254a8e3

Browse files
committed
Merge pull request oauthjs#93 from alonl/master
Added 'state' to authorization response as required by RFC 6749
2 parents a80c7cc + 3c5a4c7 commit 254a8e3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/authCodeGrant.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ function saveAuthCode (done) {
188188
* @this OAuth
189189
*/
190190
function redirect (done) {
191-
this.res.redirect(this.client.redirectUri + '?code=' + this.authCode);
191+
this.res.redirect(this.client.redirectUri + '?code=' + this.authCode +
192+
(this.req.query.state ? '&state=' + this.req.query.state : ''));
192193

193194
if (this.config.continueAfterResponse)
194195
return done();

test/authCodeGrant.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,37 @@ describe('AuthCodeGrant', function() {
290290
});
291291
});
292292

293+
it('should accept valid request and return code and state using GET', function (done) {
294+
var code;
295+
296+
var app = bootstrap({
297+
getClient: function (clientId, clientSecret, callback) {
298+
callback(false, {
299+
clientId: 'thom',
300+
redirectUri: 'http://nightworld.com'
301+
});
302+
},
303+
saveAuthCode: function (authCode, clientId, expires, user, callback) {
304+
should.exist(authCode);
305+
code = authCode;
306+
callback();
307+
}
308+
}, [false, true]);
309+
310+
request(app)
311+
.get('/authorise')
312+
.query({
313+
response_type: 'code',
314+
client_id: 'thom',
315+
redirect_uri: 'http://nightworld.com',
316+
state: 'some_state'
317+
})
318+
.expect(302, function (err, res) {
319+
res.header.location.should.equal('http://nightworld.com?code=' + code + '&state=some_state');
320+
done();
321+
});
322+
});
323+
293324
it('should continue after success response if continueAfterResponse = true', function (done) {
294325
var app = bootstrap({
295326
getClient: function (clientId, clientSecret, callback) {

0 commit comments

Comments
 (0)