Skip to content

Commit ba322e0

Browse files
committed
docs(token-auth-keycloak): update nginx configuration (#303)
1 parent a77103a commit ba322e0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

examples/token-auth-keycloak/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,23 @@ I will highlight required configuration for Basic Access Authentication Protocol
3232
proxy_set_header X-Forwarded-Proto $scheme;
3333
proxy_set_header Host $host;
3434
proxy_set_header X-Forwarded-Host $host;
35+
36+
if ($request_method = "OPTIONS") {
37+
add_header Access-Control-Allow-Origin $http_origin always;
38+
add_header Access-Control-Allow-Methods "OPTIONS, GET" always;
39+
add_header Access-Control-Allow-Headers "Content-Type, Accept, Authorization" always;
40+
add_header Access-Control-Allow-Credentials true always;
41+
add_header Content-Type "text/plain charset=UTF-8";
42+
add_header Content-Length 0;
43+
return 204;
44+
}
45+
3546
# By default, keycloak returns 400 instead of 401, we need to change that
3647
if ($http_authorization = "") {
48+
add_header Access-Control-Allow-Origin $http_origin always;
49+
add_header Access-Control-Allow-Methods "OPTIONS, GET" always;
50+
add_header Access-Control-Allow-Headers "Content-Type, Accept, Authorization" always;
51+
add_header Access-Control-Allow-Credentials true always;
3752
add_header WWW-Authenticate 'Basic realm="Keycloak login"' always;
3853
return 401;
3954
}

examples/token-auth-keycloak/conf/proxy/nginx.conf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ server {
77
set $registry "http://registry:5000";
88
set $ui "http://ui";
99

10-
1110
#charset koi8-r;
1211
#access_log /var/log/nginx/host.access.log main;
1312

@@ -44,14 +43,30 @@ server {
4443
proxy_set_header X-Forwarded-Proto $scheme;
4544
proxy_set_header Host $host;
4645
proxy_set_header X-Forwarded-Host $host;
46+
47+
if ($request_method = "OPTIONS") {
48+
add_header Access-Control-Allow-Origin $http_origin always;
49+
add_header Access-Control-Allow-Methods "OPTIONS, GET" always;
50+
add_header Access-Control-Allow-Headers "Content-Type, Accept, Authorization" always;
51+
add_header Access-Control-Allow-Credentials true always;
52+
add_header Content-Type "text/plain charset=UTF-8";
53+
add_header Content-Length 0;
54+
return 204;
55+
}
56+
4757
if ($http_authorization = "") {
58+
add_header Access-Control-Allow-Origin $http_origin always;
59+
add_header Access-Control-Allow-Methods "OPTIONS, GET" always;
60+
add_header Access-Control-Allow-Headers "Content-Type, Accept, Authorization" always;
61+
add_header Access-Control-Allow-Credentials true always;
4862
add_header WWW-Authenticate 'Basic realm="Keycloak login"' always;
4963
return 401;
5064
}
5165
proxy_pass $keycloak;
5266
}
5367

5468
location /ui {
69+
rewrite ^/ui/(.*) /$1 break;
5570
proxy_pass $ui;
5671
}
5772

0 commit comments

Comments
 (0)