title: Adding Basic Authorization for Swagger-UI
body: <p>I have currently deployed a swagger project but I am having trouble adding some basic authorization to it. Currenty when you click on the "Try it out!" button you are required to log in to an account to access the results. I have an account that I want to automatically be used everytime someone tries to access the api. Bellow is my index.html for the project:</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Swagger UI&lt;/title&gt;
    &lt;link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/&gt;
    &lt;link href='css/screen.css' media='print' rel='stylesheet' type='text/css'/&gt;
    &lt;script src='lib/jquery-1.8.3.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/jquery.slideto.min.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/jquery.wiggle.min.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/jquery.ba-bbq.min.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/underscore-min.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/backbone-min.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/swagger.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/swagger-ui.js' type='text/javascript'&gt;&lt;/script&gt;
    &lt;script src='lib/highlight.7.3.pack.js' type='text/javascript'&gt;&lt;/script&gt;
  
    &lt;script type="text/javascript"&gt;
      $(function () {
          window.swaggerUi = new SwaggerUi({
                  discoveryUrl:"https://localhost:8080/AssistAPI/api-docs.json",
                  apiKey:"",
                  dom_id:"swagger-ui-container",
                  supportHeaderParams: true,
                  supportedSubmitMethods: ['get', 'post', 'put'],
                  onComplete: function(swaggerApi, swaggerUi){
                      if(console) {
                          console.log("Loaded SwaggerUI")
                          console.log(swaggerApi);
                          console.log(swaggerUi);
                      }
                    $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
                  },
                  onFailure: function(data) {
                      if(console) {
                          console.log("Unable to Load SwaggerUI");
                          console.log(data);
                      }
                  },
                  docExpansion: "none"
              });
              window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "XXXX"header"));
              //window.authorizations.add("key", new ApiKeyAuthorization("username", "rmanda", "header"));
              window.swaggerUi.load();
          });
    &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body class="swagger-section"&gt;
  &lt;div id='header'&gt;
    &lt;div class="swagger-ui-wrap"&gt;
      &lt;a id="logo" href="http://swagger.io"&gt;swagger&lt;/a&gt;
      &lt;form id='api_selector'&gt;
        &lt;div class='input'&gt;&lt;input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/&gt;&lt;/div&gt;
        &lt;div class='input'&gt;&lt;input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/&gt;&lt;/div&gt;
        &lt;div class='input'&gt;&lt;a id="explore" href="#"&gt;Explore&lt;/a&gt;&lt;/div&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="message-bar" class="swagger-ui-wrap"&gt;&amp;nbsp;&lt;/div&gt;
  &lt;div id="swagger-ui-container" class="swagger-ui-wrap"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am trying to determine where the information is supposed to go to allow Basic Authorization. I know it involved the following lines of code, but can someone please explain to me in a little more detail where things go exactly. I have come to the realization that the documentation for swagger on GitHub is not very clear or helpful</p>
  
  <pre><code>window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "XXXX"header"));
  window.authorizations.add("key", new ApiKeyAuthorization("username", "password", "header"));
  </code></pre>