I am using auth module for nginx. (http://nginx.org/en/docs/http/ngx_http_auth_request_module.html) Is it possible somehow to store the response from the /auth, so I can send it as a request body to another endpoint.
location /private/ {
auth_request /auth;
proxy_pass ...
proxy_set_body 'Here I want to put /auth response. How?';
}
location = /auth {
proxy_pass ...
}
Nginx returns custom error page instead of external http auth service response body when auth service return 401 status code with json response body. Is it possible to return auth service response body in the case of auth errors except 2xx status codes? Nginx response when got 401 error:
Fom Nginx auth_request documentation: If the subrequest returns a 2xx response code, the access is allowed. If it returns 401 or 403, the access is denied with the corresponding error code. Any other response code returned by the subrequest is considered an error.
Nginx and the nginx plus will authenticate each request of our website with an external server and service. For performing an authentication nginx will make an http sub-request for a service that was external. If the subsequent code will return a 2xx response code then access will be allowed.
We get the auth request url directive setting from the configuration. If it is empty (set to off in the directive) then we return NGX_DECLINED which means the request should be routed to the next handler in the chain.
Short answer:
No, you can't.
Long answer:
You can't get body of a response returned to auth_request
. You can get a header returned in the response though, using the auth_request_set directive:
location / {
auth_request /auth;
auth_request_set $auth_foo $upstream_http_foo;
proxy_pass ...
proxy_set_body $auth_foo;
}
The above configuration will set the $auth_foo
variable to the value of Foo
header of an auth subrequest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With