Skip to content

Commit 99fab0b

Browse files
committed
Spec error on missing redirect_uri
1 parent 6ed9e6a commit 99fab0b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/oauth-shim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module.exports.interpret = function( req, res, next ){
111111
//
112112
// OAUTH1
113113
//
114-
else if( ( p.redirect_uri && p.oauth && parseInt(p.oauth.version,10) === 1 ) || p.token_url || p.oauth_token ){
114+
else if( p.redirect_uri && ( ( p.oauth && parseInt(p.oauth.version,10) === 1 ) || p.token_url || p.oauth_token ) ) {
115115

116116
p.location = url.parse("http"+(req.connection.encrypted?"s":'')+'://'+req.headers.host+req.url);
117117

test/oauth-shim.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ oauthshim.init({
4242
app.all('/proxy', oauthshim );
4343

4444

45+
4546
////////////////////////////////
4647
// SETUP REMOTE SERVER
4748
// This reproduces a third party OAuth and API Server
@@ -82,6 +83,13 @@ remoteServer.use('/oauth/grant', function(req,res){
8283
});
8384

8485

86+
var error_unrecognised = {
87+
error : {
88+
code : 'invalid_request',
89+
message : 'The request is unrecognised'
90+
}
91+
};
92+
8593
describe('OAuth2 exchanging code for token,', function(){
8694

8795
var query = {};
@@ -318,7 +326,7 @@ describe('OAuth authenticate', function(){
318326
for(var x in o){
319327
hash.push(x + '=' + o[x]);
320328
}
321-
return new RegExp( query.redirect_uri.replace(/\//g,'\\/') + '#' + hash.join('&') );
329+
return new RegExp( (query.redirect_uri || '').replace(/\//g,'\\/') + '#' + hash.join('&') );
322330
}
323331

324332

@@ -411,6 +419,18 @@ describe('OAuth authenticate', function(){
411419
});
412420
});
413421

422+
it("should return error 'invalid_request' if redirect_uri is missing", function(done){
423+
424+
delete query.redirect_uri;
425+
426+
request(app)
427+
.get('/proxy?'+querystring.stringify( query ))
428+
.expect(200, JSON.stringify(error_unrecognised, null, 2))
429+
.end(function(err, res){
430+
if (err) throw err;
431+
done();
432+
});
433+
});
414434

415435
it("should error with required_credentials if the client_id was not provided", function(done){
416436

0 commit comments

Comments
 (0)