我需要在Swagger UI之前添加一个单独的登录页,以便从另一台服务器进行身份验证。从这个请求中,我将获得一个键,我必须将其添加到来自swagger UI的每个请求的头中。
我在swagger 2.0中使用节点服务器和swagger-tool。
发布于 2016-10-31 05:44:56
如果你使用的是nginx,你可以添加基本的HTTP认证。然后,任何人只要进入你的文档、网址或子域,他们就会在访问swagger-ui之前得到一个弹出的用户名/密码对话框。
用于创建用户/密码组合的Full instructions (假设使用Ubuntu):
sudo apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd exampleuser
该工具将提示您输入密码。
然后更新您的nginx文件,以获得类似于docs路径的内容:
location /docs {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://0.0.0.0:3000;
}
然后重新加载nginx:
sudo /etc/init.d/nginx reload
https://stackoverflow.com/questions/34648234
复制相似问题