File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
examples/token-auth-keycloak Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,23 @@ I will highlight required configuration for Basic Access Authentication Protocol
32
32
proxy_set_header X-Forwarded-Proto $scheme;
33
33
proxy_set_header Host $host;
34
34
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
+
35
46
# By default, keycloak returns 400 instead of 401, we need to change that
36
47
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;
37
52
add_header WWW-Authenticate 'Basic realm="Keycloak login"' always;
38
53
return 401;
39
54
}
Original file line number Diff line number Diff line change 7
7
set $registry "http://registry:5000" ;
8
8
set $ui "http://ui" ;
9
9
10
-
11
10
#charset koi8-r;
12
11
#access_log /var/log/nginx/host.access.log main;
13
12
@@ -44,14 +43,30 @@ server {
44
43
proxy_set_header X-Forwarded-Proto $scheme ;
45
44
proxy_set_header Host $host ;
46
45
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
+
47
57
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;
48
62
add_header WWW-Authenticate 'Basic realm="Keycloak login"' always;
49
63
return 401 ;
50
64
}
51
65
proxy_pass $keycloak ;
52
66
}
53
67
54
68
location /ui {
69
+ rewrite ^/ui/( .*) /$1 break ;
55
70
proxy_pass $ui ;
56
71
}
57
72
You can’t perform that action at this time.
0 commit comments