Merge pull request #1170 from swagger-api/apikeyfix
Add API Key auth in onComplete callback of SwaggerUI#load call
This commit is contained in:
6
dist/index.html
vendored
6
dist/index.html
vendored
@@ -42,9 +42,12 @@
|
|||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
$('pre code').each(function(i, e) {
|
$('pre code').each(function(i, e) {
|
||||||
hljs.highlightBlock(e)
|
hljs.highlightBlock(e)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addApiKeyAuthorization();
|
||||||
},
|
},
|
||||||
onFailure: function(data) {
|
onFailure: function(data) {
|
||||||
log("Unable to Load SwaggerUI");
|
log("Unable to Load SwaggerUI");
|
||||||
@@ -53,9 +56,8 @@
|
|||||||
sorter : "alpha"
|
sorter : "alpha"
|
||||||
});
|
});
|
||||||
|
|
||||||
function addApiKeyAuthorization() {
|
function addApiKeyAuthorization(){
|
||||||
var key = encodeURIComponent($('#input_apiKey')[0].value);
|
var key = encodeURIComponent($('#input_apiKey')[0].value);
|
||||||
log("key: " + key);
|
|
||||||
if(key && key.trim() != "") {
|
if(key && key.trim() != "") {
|
||||||
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
|
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
|
||||||
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
|
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
|
||||||
|
|||||||
@@ -42,9 +42,12 @@
|
|||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
$('pre code').each(function(i, e) {
|
$('pre code').each(function(i, e) {
|
||||||
hljs.highlightBlock(e)
|
hljs.highlightBlock(e)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addApiKeyAuthorization();
|
||||||
},
|
},
|
||||||
onFailure: function(data) {
|
onFailure: function(data) {
|
||||||
log("Unable to Load SwaggerUI");
|
log("Unable to Load SwaggerUI");
|
||||||
@@ -53,9 +56,8 @@
|
|||||||
sorter : "alpha"
|
sorter : "alpha"
|
||||||
});
|
});
|
||||||
|
|
||||||
function addApiKeyAuthorization() {
|
function addApiKeyAuthorization(){
|
||||||
var key = encodeURIComponent($('#input_apiKey')[0].value);
|
var key = encodeURIComponent($('#input_apiKey')[0].value);
|
||||||
log("key: " + key);
|
|
||||||
if(key && key.trim() != "") {
|
if(key && key.trim() != "") {
|
||||||
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
|
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
|
||||||
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
|
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
|
||||||
@@ -69,15 +71,11 @@
|
|||||||
/*
|
/*
|
||||||
var apiKey = "myApiKeyXXXX123456789";
|
var apiKey = "myApiKeyXXXX123456789";
|
||||||
$('#input_apiKey').val(apiKey);
|
$('#input_apiKey').val(apiKey);
|
||||||
|
addApiKeyAuthorization();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
window.swaggerUi.load();
|
window.swaggerUi.load();
|
||||||
|
|
||||||
// Add authorization if auth input is not empty
|
|
||||||
if ($('#input_apiKey').val().length) {
|
|
||||||
addApiKeyAuthorization();
|
|
||||||
}
|
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
if ('console' in window) {
|
if ('console' in window) {
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
|
|||||||
Reference in New Issue
Block a user