Nginx auth_request: access to the original request parameter

I am trying to figure out if it is possible to forward the request parameter from the original URL to the handler / service auth_request?

Users should be able to add an API token as a request parameter, for example: https://example.com/api/user?token=237263864823674238476

And not through headeror cookie. Can I access a parameter tokenin an auth service in any way ? Or write a query parameter tokenin a custom header using NGINX?
Tried this so far:

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

  proxy_pass http://<url>;
}

/authThe endpoint does not receive the header X-auth-token-from-query, but after returning the 200upstream proxy receives the header.

+4
source share
2 answers

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

: !: :

+5

        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 "";
        }
+1

All Articles