【问题标题】:How to secure generated API documentation using swagger swashbuckle如何使用 swagger swashbuckle 保护生成的 API 文档
【发布时间】:2017-01-05 13:04:14
【问题描述】:

我已经使用 swagger swashbukle 实现了 API 文档。现在我想在我的网站上发布生成的文档作为帮助文件。如何保护此链接并发布?

【问题讨论】:

    标签: c# asp.net-web-api swagger swashbuckle


    【解决方案1】:

    到目前为止,我认为没有办法保护 swagger swashbuckle 端点。您可以从他们的 github 问题here

    中获得提示和更多信息

    【讨论】:

    【解决方案2】:

    只有在您的解决方案中实施了身份验证时,此解决方案才有效。

    1. 在解决方案中创建新文件夹 swagger
    2. 添加新的 Web.config 文件。
    3. 在里面写下如下代码:

      <configuration> 
          <system.web> 
              <authorization> 
                  <deny users="?" /> 
              </authorization> 
          </system.web> 
          <system.webServer> 
              <modules runAllManagedModulesForAllRequests="true" /> 
          </system.webServer> 
      </configuration>
      

    【讨论】:

      【解决方案3】:

      我想出了办法。使用最新的 swashbuckle 版本并在注入的 index.html 中添加以下 div 标签

      &lt;div id='auth_container'&gt;&lt;/div&gt;

      这将在 swagger UI 中显示一个 Authorize 按钮,该按钮可用于身份验证,一旦通过身份验证,对于 API 的所有请求,JWT 令牌将从 swagger UI 传递

      此外,请按照以下链接保护对 swagger 文档的所有调用 - https://github.com/domaindrivendev/Swashbuckle/issues/601

      【讨论】:

        猜你喜欢
        • 2021-04-13
        • 1970-01-01
        • 2020-10-30
        • 2016-05-01
        • 2016-07-11
        • 1970-01-01
        • 2016-10-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多