16

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 ...
}
outdev
  • 5,249
  • 3
  • 21
  • 38

1 Answers1

38

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.

Maxim Dounin
  • 6,365
  • 1
  • 26
  • 27
  • 1
    With NGINX JavaScript module's help, it might be done. Check this out: https://github.com/nginxinc/NGINX-Demos/tree/master/oauth2-token-introspection-oss – bitmountain Nov 24 '20 at 06:47
  • @bitmountain How does the example you posted here help with returning the authentication response? – Honza Zidek Feb 07 '22 at 17:03