Skip to content

Commit

Permalink
Merge pull request #48 from davidbrewer/fix-authorization-headers-branch
Browse files Browse the repository at this point in the history
Fix authorization headers feature
  • Loading branch information
dblock committed Mar 8, 2016
2 parents 59372ab + 924038c commit b8b5981
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.2.1 (Next)

* Your contribution here.
* Fixed header-based authorization - [@davidbrewer](https://github.com/davidbrewer).
* Support Swagger-UI validatorUrl option - [@davidbrewer](https://github.com/davidbrewer).

### 0.2.0 (February 23, 2016)
Expand Down
13 changes: 7 additions & 6 deletions app/views/grape_swagger_rails/application/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
addApiKeyAuthorization();
},
onFailure: function(data) {
if('console' in window) {
Expand All @@ -40,20 +41,20 @@
apisSorter: "alpha"
});

$('#input_apiKey').change(function() {
function addApiKeyAuthorization() {
var key = $('#input_apiKey')[0].value;

if(key && key.trim() != "") {
if (key && key.trim() != "") {
if (options.api_auth == 'basic') {
key = "Basic " + Base64.encode(key);
} else if (options.api_auth == 'bearer') {
key = "Bearer " + key
}
window.swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization(options.api_key_name, key, options.api_key_type));
} else {
window.swaggerUi.api.clientAuthorizations.add("key", null);
}
});
}
}

$('#input_apiKey').change(addApiKeyAuthorization);

window.swaggerUi.load();

Expand Down

0 comments on commit b8b5981

Please sign in to comment.