12

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?

Priyanka Mane
  • 517
  • 2
  • 9
  • 23

3 Answers3

2

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

Swagata Prateek
  • 1,076
  • 7
  • 15
  • 1
    Thanks for the issue link. Below given solution works for me. https://github.com/domaindrivendev/Swashbuckle/issues/384#issuecomment-111609097 – Priyanka Mane Aug 30 '16 at 06:40
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>
    
Chrono
  • 1,433
  • 1
  • 16
  • 33
Priyanka Mane
  • 517
  • 2
  • 9
  • 23
0

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

haldo
  • 14,512
  • 5
  • 46
  • 52
Silly John
  • 1,584
  • 2
  • 16
  • 34