nginx auth_request:访问原始查询参数

pky*_*eck 6 authentication nginx

我想弄清楚是否可以将查询参数从原始URL转发到auth_request处理程序/服务?

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

而不是通过headercookie.我可以token在auth服务中以某种方式访问参数吗?或者token使用NGINX在自定义标题中写入query-parameter?
到目前为止试过这个:

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

  proxy_pass http://<url>;
}
Run Code Online (Sandbox Code Playgroud)

/auth端点没有获取X-auth-token-from-query头但在返回后200上游代理确实得到了头.

Aro*_*ost 7

您很可能也希望将url(uri)传递给auth-request端点.你可以一次性做到这一点:

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>;
}
Run Code Online (Sandbox Code Playgroud)

额外奖励:我也通过了这个方法!:田田:


use*_*986 6

以下对我有用

        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 "";
        }
Run Code Online (Sandbox Code Playgroud)