Skip to content

Instantly share code, notes, and snippets.

@rrharvey
rrharvey / CustomSwagger.js
Last active May 5, 2019 09:39
Add bearer token to Swagger UI using Swashbuckle
(function () {
$(function () {
$('#input_apiKey').attr('placeholder', 'JSON Web Token');
$('#input_apiKey').off();
$('#input_apiKey').on('change', function () {
var key = this.value;
console.info('Set bearer token to: ' + key);
if (key && key.trim() !== '') {
swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "Bearer " + key, "header"));
}