anyproxy icon indicating copy to clipboard operation
anyproxy copied to clipboard

How to add the function of auth

Open Vbubblery opened this issue 9 years ago • 6 comments

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

Vbubblery avatar Jun 06 '16 02:06 Vbubblery

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

codingfishman avatar Sep 01 '16 11:09 codingfishman

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

ottomao avatar Sep 01 '16 14:09 ottomao

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

lijinma avatar Feb 25 '17 12:02 lijinma

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

lijinma avatar Feb 26 '17 12:02 lijinma

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请求出错了

qq 20181016185422

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

        return true;
    },

LiuWeiMr avatar Oct 16 '18 10:10 LiuWeiMr

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,
    
                  }
              };
          }}
    

dawoodaijaz97 avatar May 29 '20 15:05 dawoodaijaz97