Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a login page before Swagger ui?

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.

like image 783
aaqib90 Avatar asked Aug 31 '25 03:08

aaqib90


1 Answers

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
like image 168
Philip Kirkbride Avatar answered Sep 05 '25 08:09

Philip Kirkbride



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!