Swagger UI身份验证

时间:2015-08-04 21:51:39

标签: authentication swagger swagger-ui swagger-2.0

我的swagger UI没有将身份验证密钥发送到API。 我认为我已经设置了我的招摇ui但是当我检查标题时他们没有被发送。我有日志告诉我,身份验证密钥已被读入但从未在这些请求标头中发送。

我注意到clientAuthorizations字段未更新并保持为空。

这是相关代码

function addApiKeyAuthorization(windowName){
      log("got key from " + windowName);

      var key = get('accessToken');
      if(key && key.trim() != "") {
          var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "header");
          window.windowName.api.clientAuthorizations.add("api_key", apiKeyAuth);
          log("added key " + key + "from " + windowName);
      }
    }

谢谢!

1 个答案:

答案 0 :(得分:0)

问题出现在我的onComplete函数中,用SwaggerUI替换windowName并且它有效。我猜SwaggerUi引用当前对象而windowName不是

        onComplete: function(swaggerApi, windowName){ 
          addApiKeyAuthorization(windowName);
        },