authentication - 如何让 Swagger UI 让我提供身份验证 header ?

标签 authentication clojure swagger-ui luminus reitit

我使用 Luminus 以及 reitit 和 swagger-ui 来生成一个页面,让我可以试用我的 Luminus API。我只需输入我的 API 请求正文并提交即可测试我的 API。
A snapshot of my swagger UI
现在我已经使用 buddy 添加了身份验证,并且我的 API 需要在请求的 header 中传递一个 token ,否则它会拒绝该请求作为被禁止的请求。
我正在尝试让“授权” header 字段神奇地出现在我的 UI 中,以便我可以输入 JWT token 字符串并测试我的 API。对于使用 reitit 创建 API 的任何人来说,这一定是一个非常普遍的要求,但我不知道如何去做。
我四处寻找,发现this reitit issues page ,其中包括文本...

Header params are declared as lower-case strings {:headers {"authorization" string?}} which would match exactly what Ring provides us. (Could still HTTP-Header-Case them for documentation.)



...并建议以下设置...
:get {:summary "list offers"
      :parameters 
        {:headers 
          {"authorization" string?}}
         ... etc

这样做并没有让我有任何方式进行身份验证。所以,我找到了 this discussion并通过在上述 route 的 :summary 和 :parameters 之后添加以下内容来编辑我的路线...
             :middleware [authenticated?]
             :swagger {:security [:apiKey]}

添加后,我得到了这个......
enter image description here

...看起来我在正确的轨道上,但我仍然无法在身份验证 header 中输入我的 token 。

正如我所说,一切都与 curl 一起工作......只是那个招摇没有显示任何添加身份验证 header 的方法。有人知道如何让 Swagger UI 在这种情况下发挥作用吗?

如果 reitit 不支持这一点,那么人们如何将 Swagger UI 用于经过身份验证的请求?

任何帮助,将不胜感激!

最佳答案

好的。解决了。

在我的 API 路由的根部(封装了我可能最终使用此身份验证的所有路由),我添加了 :securityDefinitions。

  ["/api"
   {:swagger {:id ::api
              :securityDefinitions {:apiAuth
                                             {:type "apiKey"
                                              :name "Authorization"
                                              :in "header"
                                              }}}


具体路线内:
             :middleware [authenticated?]
             :swagger {:security [{:apiAuth []}]}

关于authentication - 如何让 Swagger UI 让我提供身份验证 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61469164/

相关文章:

ios - 在 parse.com 的 ios 中使用 google plus 登录

java - YouTube API Auth 类中的 Nullpointer 异常 - 使用 Java 上传视频

recursion - 有没有办法显式地编写一个 elixir 函数来优化尾调用?

clojure - 如何在 ClojureScript 中使用 clojure.tools.macro/name-with-attributes?

mule - 在 Mule 中使用 Swagger 记录 RESTful 服务

java - 在Google App Engine Java中使用OAuth2对不同服务提供商的用户进行身份验证

python - Colaboratory - 记住 Google Drive Auth(Python)

python - csv 数据可以变得懒惰吗?

.net - 如何使用 Swashbuckle 在生成的 Swagger 文件中生成全局参数?

rest - 将 Swagger UI 嵌入 Blazor 服务器端应用程序