Authentication nginx auth_请求:访问原始查询参数

Authentication nginx auth_请求:访问原始查询参数,authentication,nginx,Authentication,Nginx,我试图弄清楚是否有可能将查询参数从原始URL转发到auth\u请求handler/service 用户应该能够添加API令牌作为查询参数,如下所示: https://example.com/api/user?token=237263864823674238476 而不是通过标题或cookie。我是否可以在身份验证服务中以某种方式访问令牌参数?或者使用NGINX在自定义标头中写入令牌查询参数? 到目前为止,我一直在尝试: location = /api/user { auth_request

我试图弄清楚是否有可能将查询参数从原始URL转发到
auth\u请求
handler/service

用户应该能够添加API令牌作为查询参数,如下所示:
https://example.com/api/user?token=237263864823674238476

而不是通过
标题
cookie
。我是否可以在身份验证服务中以某种方式访问
令牌
参数?或者使用NGINX在自定义标头中写入
令牌
查询参数?
到目前为止,我一直在尝试:

location = /api/user {
  auth_request /auth;
  proxy_set_header X-auth-token-from-query $arg_token;

  proxy_pass http://<url>;
}
location=/api/user{
授权请求/授权;
代理设置标题X-auth-token-from-query$arg\u token;
代理传递http://;
}

/auth
端点没有获取
X-auth-token-from-query
头,但是在返回
200
之后,上游代理确实获取了头。

您很可能还希望将url(uri)传递给auth请求端点。您可以一次性完成此操作:

location = /api/auth {
  proxy_set_header X-Original-URI $request_uri;
  proxy_set_header X-Original-METHOD $request_method;
  proxy_pass_request_body off;
  proxy_set_header Content-Length "";

  proxy_pass http://<url>;
}
location=/api/auth{
代理集头X-Original-URI$request\u URI;
代理\u集\u头X-原始方法$request\u方法;
代理通过请求关闭;
代理集标题内容长度“”;
代理传递http://;
}

奖励:我也通过了这个方法塔达:

以下几点对我很有用

        location = /auth {
          internal;
          set $query '';
          if ($request_uri ~* "[^\?]+\?(.*)$") {
              set $query $1;
          }
          proxy_pass                http://myauthpoint?$query;
          proxy_pass_request_body   off;
          proxy_set_header          Content-Length "";
        }

这是最好的,因为查询参数传递得很好。我必须做一个小的编辑,以便传递完整的原始路径…:;