title: Keycloak integration in Swagger
body: <p>I have a Keycloak protected backend that I would like to access via swagger-ui. Keycloak provides the oauth2 implicit and access code flow, but I was not able to make it work. Currently, Keycloak's documentation is lacking regarding which url should be used for <strong>authorizationUrl</strong> and <strong>tokenUrl</strong> within <strong>swagger.json</strong>.</p>
  
  <p>Each realm within Keycloak offers a huge list of configuration urls by accessing <a href="http://keycloak.local/auth/realms/REALM/.well-known/openid-configuration" rel="noreferrer">http://keycloak.local/auth/realms/REALM/.well-known/openid-configuration</a></p>
  
  <p>Furthermore I've tried to directly integrate the keycloak js-client within swagger-ui index.html by adding the following lines:</p>
  
  <pre><code>&lt;script src="keycloak/keycloak.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    var keycloak = Keycloak('keycloak.json');
      keycloak.init({ onLoad: 'login-required' })
        .success(function (authenticated) {
          console.log('Login Successful');
          window.authorizations.add("oauth2", new ApiKeyAuthorization("Authorization", "Bearer " + keycloak.token, "header"));
        }).error(function () {
          console.error('Login Failed');
          window.location.reload();
        }
      );
   &lt;/script&gt;
  </code></pre>
  
  <p>I also tried something like this after 'Login Successful'</p>
  
  <pre><code>swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "Bearer " + keycloak.token, "header"));
  </code></pre>
  
  <p>But it also doesn't work.</p>
  
  <p>Any suggestions how I can integrate keycloak auth within swagger?</p>