How to secure generated API documentation using swagger swashbuckle

眉间皱痕 提交于 2019-12-01 00:27:08

问题


I have implemented API documentation using swagger swashbukle. Now I want to publish generated documentation as a help file in my website. How to secure this link and publish?


回答1:


I don't think there's a way to secure the swagger swashbuckle endpoint up until now. You can have tips and more into this from their github issue here




回答2:


This solution will only work if you have implemented authentication in your solution.

  1. Create new folder swagger in solution
  2. Add new Web.config file.
  3. write following code in it:

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



回答3:


I figured out the way to do this. Use the latest swashbuckle version and add the below div tag in the injected index.html

<div id='auth_container'></div>

This will show an Authorize button in the swagger UI which can be used for authentication and once Authenticated, for all the requests to the API, the JWT token will be passed from the swagger UI

Also, follow the below link to protect all the calls for the swagger docs - https://github.com/domaindrivendev/Swashbuckle/issues/601



来源:https://stackoverflow.com/questions/39207264/how-to-secure-generated-api-documentation-using-swagger-swashbuckle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!