Skip to content

Commit c8c5664

Browse files
committed
Add API Key auth in onComplete callback of SwaggerUI#load call
1 parent 854ef16 commit c8c5664

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

dist/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
});
4343
*/
4444
}
45+
4546
$('pre code').each(function(i, e) {
4647
hljs.highlightBlock(e)
4748
});
49+
4850
},
4951
onFailure: function(data) {
5052
log("Unable to Load SwaggerUI");
@@ -53,7 +55,7 @@
5355
sorter : "alpha"
5456
});
5557

56-
function addApiKeyAuthorization() {
58+
function addApiKeyAuthorization(){
5759
var key = encodeURIComponent($('#input_apiKey')[0].value);
5860
log("key: " + key);
5961
if(key && key.trim() != "") {

dist/lib/swagger-oauth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ window.onOAuthComplete = function onOAuthComplete(token) {
277277
}
278278
}
279279
});
280-
window.authorizations.add(oauth2KeyName, new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
280+
window.swaggerUi.api.clientAuthorizations.add(oauth2KeyName, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
281281
}
282282
}
283283
}

src/main/html/index.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
});
4343
*/
4444
}
45+
4546
$('pre code').each(function(i, e) {
4647
hljs.highlightBlock(e)
4748
});
49+
4850
},
4951
onFailure: function(data) {
5052
log("Unable to Load SwaggerUI");
@@ -53,7 +55,7 @@
5355
sorter : "alpha"
5456
});
5557

56-
function addApiKeyAuthorization() {
58+
function addApiKeyAuthorization(){
5759
var key = encodeURIComponent($('#input_apiKey')[0].value);
5860
log("key: " + key);
5961
if(key && key.trim() != "") {
@@ -69,15 +71,11 @@
6971
/*
7072
var apiKey = "myApiKeyXXXX123456789";
7173
$('#input_apiKey').val(apiKey);
74+
addApiKeyAuthorization();
7275
*/
7376

7477
window.swaggerUi.load();
7578

76-
// Add authorization if auth input is not empty
77-
if ($('#input_apiKey').val().length) {
78-
addApiKeyAuthorization();
79-
}
80-
8179
function log() {
8280
if ('console' in window) {
8381
console.log.apply(console, arguments);

0 commit comments

Comments
 (0)