Swagger UI + Auth0 Bearer

When you would like to integrate Swagger UI with a token based authentication (like Auth0), this is the way you need to update Swagger index.html :


      function addApiKeyAuthorization(){
        var key = encodeURIComponent($('#input_apiKey')[0].value);
        if(key && key.trim() != "") {
            var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("Authorization", "Bearer " + key, "header");
            window.swaggerUi.api.clientAuthorizations.add("key", apiKeyAuth);
            log("added key " + key);
        }
      }

Instead of adding api_key as part of the query, this code is adding your token in an "Authorization" header and with "Bearer " as prefix.

enjoy

Aucun commentaire:

Enregistrer un commentaire