Skip to content

Commit 924038c

Browse files
author
David Brewer
committed
Fixed header-based authorization.
Previous to this update, when I tried to do API-key authorization using headers rather than the query string, Swagger-UI would not send my authorization headers. This update basically makes the authorization options get set AFTER Swagger-UI has finished initializing, which seems to make the system much happier. Changes based on a conversation on a mostly-unrelated pull request, ruby-grape#25
1 parent 347e563 commit 924038c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 0.2.1 (Next)
22

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

67
### 0.2.0 (February 23, 2016)

app/views/grape_swagger_rails/application/index.html.erb

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
console.log(swaggerUi);
2929
}
3030
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
31+
addApiKeyAuthorization();
3132
},
3233
onFailure: function(data) {
3334
if('console' in window) {
@@ -40,20 +41,20 @@
4041
apisSorter: "alpha"
4142
});
4243

43-
$('#input_apiKey').change(function() {
44+
function addApiKeyAuthorization() {
4445
var key = $('#input_apiKey')[0].value;
4546

46-
if(key && key.trim() != "") {
47+
if (key && key.trim() != "") {
4748
if (options.api_auth == 'basic') {
4849
key = "Basic " + Base64.encode(key);
4950
} else if (options.api_auth == 'bearer') {
5051
key = "Bearer " + key
5152
}
5253
window.swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization(options.api_key_name, key, options.api_key_type));
53-
} else {
54-
window.swaggerUi.api.clientAuthorizations.add("key", null);
55-
}
56-
});
54+
}
55+
}
56+
57+
$('#input_apiKey').change(addApiKeyAuthorization);
5758

5859
window.swaggerUi.load();
5960

0 commit comments

Comments
 (0)