Skip to content

Commit 305632e

Browse files
committed
updated auth to support existing authorization keys
1 parent e9a860b commit 305632e

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

lib/swagger.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger.js
2-
// version 2.0.30
2+
// version 2.0.31
33

44
var __bind = function(fn, me){
55
return function(){
@@ -1124,6 +1124,8 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
11241124
else
11251125
requestContentType = "application/x-www-form-urlencoded";
11261126
}
1127+
else if (this.type == "DELETE")
1128+
body = "{}";
11271129
else if (this.type != "DELETE")
11281130
requestContentType = null;
11291131
}
@@ -1462,16 +1464,33 @@ SwaggerAuthorizations.prototype.remove = function(name) {
14621464
};
14631465

14641466
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
1465-
status = null;
1467+
var status = null;
14661468
var key;
1467-
for (key in this.authz) {
1468-
value = this.authz[key];
1469-
result = value.apply(obj, authorizations);
1470-
if (result === false)
1471-
status = false;
1472-
if (result === true)
1473-
status = true;
1469+
1470+
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
1471+
// apply all keys since no authorizations hash is defined
1472+
log("adding all keys");
1473+
for (key in this.authz) {
1474+
value = this.authz[key];
1475+
result = value.apply(obj, authorizations);
1476+
if (result === true)
1477+
status = true;
1478+
}
14741479
}
1480+
else {
1481+
for(name in authorizations) {
1482+
for (key in this.authz) {
1483+
if(key == name) {
1484+
log("adding key " + key);
1485+
value = this.authz[key];
1486+
result = value.apply(obj, authorizations);
1487+
if (result === true)
1488+
status = true;
1489+
}
1490+
}
1491+
}
1492+
}
1493+
14751494
return status;
14761495
};
14771496

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99
],
1010
"description": "swagger.js is a javascript client for use with swaggering APIs.",
11-
"version": "2.0.30",
11+
"version": "2.0.31",
1212
"homepage": "http://swagger.wordnik.com",
1313
"repository": {
1414
"type": "git",

0 commit comments

Comments
 (0)