Trying to create a cookie inside the auth_request call and pass it downstream for immediate use. The best I can manage so far is setting the cookie in the browser after the call is complete with:
auth_request /blah/blah;
auth_request_set $saved_set_cookie $upstream_http_set_cookie;
add_header Set-Cookie $saved_set_cookie;
That cookie will not be available downstream until the next request. I can always get the new cookie by doing the following, but it's not ideal to have it in a new header name:
auth_request_set $saved_cookie_try_2 $upstream_cookie_COOKIE_NAME;
proxy_set_header X-Fake-Cookie $saved_cookie_try_2;
This allows the cookie value to be immediately available as a custom header, but isn't as convenient as just having the cookie.
Any suggestions?
Update 1:
I was able to add to the existing cookies or replace them entirely with:
proxy_set_header Cookie "$http_cookie; $saved_set_cookie";
or
proxy_set_header Cookie "$saved_set_cookie";
I was not able to figure out a way to set or replace only a single cookie.
Update 2:
I can probably use NGiNX map function for this task:
map $http_cookie $auth_header {
default "";
"~*yourCookieName=(?<variable>[^;]+)" "the value you wanna set
$variable";
}
From here: https://stackoverflow.com/a/45208334/1502561
来源:https://stackoverflow.com/questions/48177119/nginx-auth-request-set-cookie-for-use-downstream