Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx: Is it possible to get response retuned from auth_request

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 ...
}
like image 465
outdev Avatar asked Jul 15 '15 13:07

outdev


People also ask

Can Nginx return custom error page when Auth service return 401 error?

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:

How do I know if Nginx Auth_request is allowed or denied?

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.

How to use NGINX and Nginx Plus for authentication?

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.

How to return NGX_declined from an empty Auth request?

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.


1 Answers

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.

like image 53
Maxim Dounin Avatar answered Sep 21 '22 22:09

Maxim Dounin