Nginx – Pass a cookie back to a user before proxy_pass

nginx

I've been setting up an nginx reverse proxy to handle requests based on logging in against a LDAP database. The basic guide is here https://github.com/nginxinc/nginx-ldap-auth . The problem I have is that I want to set an expiry time on the cookie (easy to do), and that every time any resource is accessed, the expiry time gets bumped ten minutes into the future. I don't have access to the code beyond the proxy, so I can't get that to update the cookie, but I do have some python code which receives the auth_request. What I would ideally like is for the cookie to be returned to the user, and then redirected to the proxy_pass.

Here is a fragment of my nginx.conf

server {
    listen 80;
    location / {
         auth_request /auth_proxy; #the python authentication routine checks the cookie at this address.
         error_page 401 403 =200 /login #Python login page
         proxy_pass http://ADifferentServerWhenLoggedIn.org.
    }
} 

Thanks

Best Answer

What you could do is following the example provided in the docs for auth_request and provide a location corresponding to the authentication path.

You could then use add_header to insert HTTP headers such as Set-Cookie.