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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With