简体   繁体   中英

How to secure generated API documentation using swagger swashbuckle

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?

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

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> 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM