Skip to content

Commit

Permalink
nixos/oauth2_proxy_nginx: fix proxy_set_header
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Apr 29, 2024
1 parent 27f59a8 commit b28952c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions nixos/modules/services/security/oauth2_proxy_nginx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ in
} ++ (map (vhost: {
virtualHosts.${vhost} = {
locations = {
"/".extraConfig = ''
# pass information via X-User and X-Email headers to backend, requires running with --set-xauthrequest flag
proxy_set_header X-User $user;
proxy_set_header X-Email $email;
# if you enabled --cookie-refresh, this is needed for it to work with auth_request
add_header Set-Cookie $auth_cookie;
'';

"/oauth2/auth" = {
proxyPass = cfg.proxy;
extraConfig = ''
Expand All @@ -63,6 +72,7 @@ in
proxy_pass_request_body off;
'';
};

"@redirectToAuth2ProxyLogin" = {
return = "307 https://${cfg.domain}/oauth2/start?rd=$scheme://$host$request_uri";
extraConfig = ''
Expand All @@ -75,16 +85,10 @@ in
auth_request /oauth2/auth;
error_page 401 = @redirectToAuth2ProxyLogin;
# pass information via X-User and X-Email headers to backend,
# requires running with --set-xauthrequest flag
# set variables being used in locations."/".extraConfig
auth_request_set $user $upstream_http_x_auth_request_user;
auth_request_set $email $upstream_http_x_auth_request_email;
proxy_set_header X-User $user;
proxy_set_header X-Email $email;
# if you enabled --cookie-refresh, this is needed for it to work with auth_request
auth_request_set $auth_cookie $upstream_http_set_cookie;
add_header Set-Cookie $auth_cookie;
'';
};
}) cfg.virtualHosts)));
Expand Down

0 comments on commit b28952c

Please sign in to comment.