我试图找出是否有可能从原始URL转发查询参数到auth_request
处理程序/服务?
用户应该能够添加API令牌作为查询参数,如下所示: https://example.com/api/user?token=237263864823674238476
: https://example.com/api/user?token=237263864823674238476
token https://example.com/api/user?token=237263864823674238476
而不是通过header
或cookie
。 我可以在validation服务中以某种方式访问token
参数吗? 或者用NGINX在自定义标题中写入token
查询参数?
试过这个到目前为止:
location = /api/user { auth_request /auth; proxy_set_header X-auth-token-from-query $arg_token; proxy_pass http://<url>; }
/auth
endpoint没有得到X-auth-token-from-query
头,但是在返回200
,upstream-proxy得到头。
你很可能也想把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>; }
奖金:我也通过了这个方法! :田田:
以下为我工作
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 ""; }