Skip to content

Commit 266b006

Browse files
committed
add oauth2-proxy
1 parent 7d8332e commit 266b006

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Version 2025/08/23 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/oauth2-proxy-server.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+
location /oauth2/ {
5+
include /config/nginx/resolver.conf;
6+
set $upstream_oauth2_proxy oauth2-proxy;
7+
proxy_pass http://$upstream_oauth2_proxy:4180;
8+
9+
proxy_set_header Host $host;
10+
proxy_set_header X-Real-IP $remote_addr;
11+
proxy_set_header X-Auth-Request-Redirect $request_uri;
12+
# or, if you are handling multiple domains:
13+
# proxy_set_header X-Auth-Request-Redirect $scheme://$host$request_uri;
14+
}
15+
16+
location = /oauth2/auth {
17+
internal;
18+
19+
include /config/nginx/resolver.conf;
20+
set $upstream_oauth2_proxy oauth2-proxy;
21+
proxy_pass http://$upstream_oauth2_proxy:4180;
22+
23+
proxy_set_header Host $host;
24+
proxy_set_header X-Real-IP $remote_addr;
25+
proxy_set_header X-Forwarded-Uri $request_uri;
26+
# nginx auth_request includes headers but not body
27+
proxy_set_header Content-Length "";
28+
proxy_pass_request_body off;
29+
}

root/etc/s6-overlay/s6-rc.d/init-swag-config/run

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ if [[ ! -f /config/nginx/tinyauth-server.conf ]]; then
3030
cp /defaults/nginx/tinyauth-server.conf.sample /config/nginx/tinyauth-server.conf
3131
fi
3232

33+
# copy oauth2-proxy config files if they don't exist
34+
if [[ ! -f /config/nginx/oauth2-proxy-location.conf ]]; then
35+
cp /defaults/nginx/oauth2-proxy-location.conf.sample /config/nginx/oauth2-proxy-location.conf
36+
fi
37+
if [[ ! -f /config/nginx/oauth2-proxy-server.conf ]]; then
38+
cp /defaults/nginx/oauth2-proxy-server.conf.sample /config/nginx/oauth2-proxy-server.conf
39+
fi
40+
3341
# copy old ldap config file to new location
3442
if [[ -f /config/nginx/ldap.conf ]] && [[ ! -f /config/nginx/ldap-server.conf ]]; then
3543
cp /config/nginx/ldap.conf /config/nginx/ldap-server.conf

0 commit comments

Comments
 (0)