Last active
August 29, 2015 14:22
-
-
Save ponelat/7ee105d25a1cd7f02fc6 to your computer and use it in GitHub Desktop.
Setup Auth in Swagger-UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
window.swaggerUi = new SwaggerUi({ | |
url: url, | |
dom_id: "swagger-ui-container", | |
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'], | |
onComplete: function(swaggerApi, swaggerUi){ | |
if(typeof initOAuth == "function") { | |
initOAuth({ | |
clientId: "your-client-id", | |
realm: "your-realms", | |
appName: "your-app-name" | |
}); | |
} | |
$('pre code').each(function(i, e) { | |
hljs.highlightBlock(e) | |
}); | |
addApiKeyAuthorization(); // --------------------------------------------< make sure this is here | |
}, | |
// ........... | |
function addApiKeyAuthorization(){ | |
// You can use the 'key', which comes from the input box in the -UI... only if you want. | |
var key = encodeURIComponent($('#input_apiKey')[0].value); | |
if(key && key.trim() != "") { | |
// Lets add some Auth! | |
window.swaggerUi.api.clientAuthorizations.add("api_key", new SwaggerClient.ApiKeyAuthorization('some_header_key', 'value', 'header');); | |
window.swaggerUi.api.clientAuthorizations.add("another_auth", new SwaggerClient.ApiKeyAuthorization('some_query_key', 'value', 'query');); | |
window.swaggerUi.api.clientAuthorizations.add("and_another_auth", new SwaggerClient.PasswordAuthorization('', 'username', 'password');); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment