anyproxy How to add the function of auth

ssgvzors  于 2个月前  发布在  其他
关注(0)|答案(6)|浏览(52)

应该如何加入用户验证功能?

2ledvvac

2ledvvac1#

Hi @Vbubblery
请问这里面的用户验证是不是指header中的authorization?
如果是header中的信息,目前直接放入header中就可以使用,如果是想在rule中拦截并加入验证信息,应该可以自己对rule进行二次开发,所以可否描述一下用户验证的使用场景?

6yjfywim

6yjfywim2#

这个需求可能是需要“对使用AnyProxy的用户做权限控制”。我觉得这个优先级不高。

djp7away

djp7away3#

@ottomao 我也有这个需求,原因是代理开在服务器上面,如果没有 basic auth,这个代理就很容易被别人扫到。

7gs2gvoe

7gs2gvoe4#

@ottomao 兄弟,可以讲讲实现的思路吗?我自己实现试试。

b4lqfgs4

b4lqfgs45#

Hi @Vbubblery
请问这里面的用户验证是不是指header中的authorization?
如果是header中的信息,目前直接放入header中就可以使用,如果是想在rule中拦截并加入验证信息,应该可以自己对rule进行二次开发,所以可否描述一下用户验证的使用场景?

实现basic author重写了beforeSendRequest 方法:
*beforeSendRequest (requestDetail) {
console.log(requestDetail._req.headers);
if (!requestDetail || !requestDetail._req.headers || !requestDetail._req.headers["Proxy-Authorization"]) {
return {
response: {
statusCode: 407,
header: {
'Proxy-Authenticate': 'Basic'
}
}
};
}
}
该方法http请求可以验证身份,但是HTTPS请求出错了

其中beforeDealHttpsRequest方法如下:
*beforeDealHttpsRequest(requestDetail) {
console.log(requestDetail._req.headers);

return true;
    },
slmsl1lt

slmsl1lt6#

Hi,
this is my code for Basic Auth, I am getting an error message "Send final response failed:Can not read property 'transfer-encoding' of undefined"

can anyone help me with the authentication!!!! pls

  • beforeSendRequest(requestDetail) {
const Base64 = require('js-base64').Base64;
  if (!requestDetail || !requestDetail._req.headers || !requestDetail._req.headers["Proxy-Authorization"]) {
      
      return {
          response: {
              statusCode: 407,
              header: { 'Proxy-Authenticate': 'Basic' }
          }
      };
  } else {
      let auth = requestDetail._req.headers["Proxy-Authorization"];
      auth = auth.split(" ");
      auth = Base64.decode(auth[1]);
      auth = auth.split(":");
      let username = auth[0];
      let password = auth[1];
      if (username === "dawood" && password === "google123") {
          return {
              response: {
                  statusCode: 200,

              }
          };
      }}

相关问题