3

I need to add a separate login page before Swagger UI for authentication from another server. From this request I will get a key which I have to add in the header of every req from swagger UI.

I'm using a node server and swagger-tool with swagger 2.0.

Cœur
  • 37,241
  • 25
  • 195
  • 267
aaqib90
  • 510
  • 1
  • 5
  • 16

1 Answers1

1

If you're using nginx you could add basic HTTP Authentication. Then anytime anyone goes to your docs url or sub-domain they'll get a pop-up user/password dialog before being able to access swagger-ui.

Full instructions for creating your user/password combinations (assuming Ubuntu):

sudo apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd exampleuser

The tool will prompt you for a password.

Then update your nginx file to have something like this for the docs route:

location /docs {
   auth_basic "Restricted Content";
   auth_basic_user_file /etc/nginx/.htpasswd;
   proxy_pass http://0.0.0.0:3000;
 }

Then reload nginx:

sudo /etc/init.d/nginx reload
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225