问题
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.
- Create new folder swagger in solution
- Add new Web.config file.
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