|
| 1 | +## Version 2025/08/23 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/oauth2-proxy-location.conf.sample |
| 2 | +# Make sure that your oauth2-proxy container is in the same user defined bridge network and is named oauth2-proxy |
| 3 | + |
| 4 | +auth_request /oauth2/auth; |
| 5 | +error_page 401 =302 /oauth2/sign_in; |
| 6 | + |
| 7 | +# pass information via X-User and X-Email headers to backend, |
| 8 | +# requires running with --set-xauthrequest flag |
| 9 | +auth_request_set $user $upstream_http_x_auth_request_user; |
| 10 | +auth_request_set $email $upstream_http_x_auth_request_email; |
| 11 | +auth_request_set $groups $upstream_http_x_auth_request_groups; |
| 12 | +proxy_set_header X-User $user; |
| 13 | +proxy_set_header X-Email $email; |
| 14 | +proxy_set_header X-Groups $groups; |
| 15 | + |
| 16 | +# if you enabled --pass-access-token, this will pass the token to the backend |
| 17 | +auth_request_set $token $upstream_http_x_auth_request_access_token; |
| 18 | +proxy_set_header X-Access-Token $token; |
| 19 | + |
| 20 | +# if you enabled --cookie-refresh, this is needed for it to work with auth_request |
| 21 | +auth_request_set $auth_cookie $upstream_http_set_cookie; |
| 22 | +add_header Set-Cookie $auth_cookie; |
| 23 | + |
| 24 | +# When using the --set-authorization-header flag, some provider's cookies can exceed the 4kb |
| 25 | +# limit and so the OAuth2 Proxy splits these into multiple parts. |
| 26 | +# Nginx normally only copies the first `Set-Cookie` header from the auth_request to the response, |
| 27 | +# so if your cookies are larger than 4kb, you will need to extract additional cookies manually. |
| 28 | +auth_request_set $auth_cookie_name_upstream_1 $upstream_cookie_auth_cookie_name_1; |
| 29 | + |
| 30 | +# Extract the Cookie attributes from the first Set-Cookie header and append them |
| 31 | +# to the second part ($upstream_cookie_* variables only contain the raw cookie content) |
| 32 | +if ($auth_cookie ~* "(; .*)") { |
| 33 | + set $auth_cookie_name_0 $auth_cookie; |
| 34 | + set $auth_cookie_name_1 "auth_cookie_name_1=$auth_cookie_name_upstream_1$1"; |
| 35 | +} |
| 36 | + |
| 37 | +# Send both Set-Cookie headers now if there was a second part |
| 38 | +if ($auth_cookie_name_upstream_1) { |
| 39 | + add_header Set-Cookie $auth_cookie_name_0; |
| 40 | + add_header Set-Cookie $auth_cookie_name_1; |
| 41 | +} |
0 commit comments