keycloak redirects url to http instead of https


Rahul

I have a keycloak setup behind an SSL terminating nginx proxy. When I try to access an application secured with keycloak, keycloak generates a url like this:

https://keycloak.mydomain.com/auth/realms/AdfsDemo/protocol/openid-connect/auth?client_id=adfs&redirect_uri=http%3A%2F%2Fmyapp.mydomain.com%2Fsignin-oidc&response_type=code&scope=openid%20profile&response_mode=form_post&nonce=636603226928179925.MmUzYWEzMGYtNTAxOS00MTBkLTk4MWItMDU3MGY1NjAxOGViNzlhYmZiMDQtNTQyOC00Y2YzLTk2MjMtZjNjMWFjNTI1YzM3&state=CfDJ8NQosUp9FsZBgifUu0XsVAEasSeKTitMPUM5yatTiQGf_Kz_X9CpQNPIHOkGr1hsgdErjhbw4ULINvCJgnFdWYctcIuhoyhOTt2Km3xy0qFh4o9gNFkPQlbEqc771MmVC2FUqUtvDqf8zChsyDDfGkxZ6Kc1y36I_3lFfzfubBAyXK0cEb_3AdZBMyDRp2WMykrarD8Z-0iGBk_q5Z8akYYHyCc7q-FSKxP1DW59nHpF8fM6P-S8SdVxvTW2dtEyV9UL6rlqD8dabNNJxhoaXEeBzwRh84it2vVlaaYpQ7d1ErZ51hpuzhG2gYSxnowMdQa8gfd8X1hs5HsgJXL-gCmBgTlxWNQfAy5DRpcX8Wi0&x-client-SKU=ID_NET&x-client-ver=2.1.4.0

I can access keycloak on https just fine. However, when I try to access an application secured with keycloak, you will notice that the redirect_uri generated by keycloak is http instead of https.

Here is my nginx configuration

server {       
listen 443  ssl;
server_name  myapp.mydomain.com;
ssl_certificate /etc/nginx/external/wildcard_mydomain_com.pem;
ssl_certificate_key /etc/nginx/external/private.rsa;

location / {                 
   proxy_set_header Host myapp.mydomain.com;         
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-Proto $scheme;       
   proxy_set_header X-Forwarded-Port 443;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                               
   proxy_pass http://172.30.5.28:8001;
 }
}

#Keycloak Service
server {
listen 443  ssl;
server_name  keycloak.mydomain.com;  
ssl_certificate /etc/nginx/external/wildcard_mydomain_com.pem;
ssl_certificate_key /etc/nginx/external/private.rsa;
location = / {
     return 301 https://keycloak.mydomain.com/auth; 
}  
location /auth {
   proxy_pass http://172.30.5.28:8080;        
   proxy_set_header Host keycloak.mydomain.com;  
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-Proto https;
   proxy_set_header X-Forwarded-Port 443;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;           
 }
}

Any help is greatly appreciated.

Thanks, Rahul

Rahul

I was able to resolve this issue. We have dotnet core application and keycloak behing ssl terminated SSL proxy. The Nginx setup as above is correct, the problem is that the application is not forwarding the headers to keyclaok correctly. The following link helped : https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1

Related


Keycloak redirects localhost, not remote URL

ourobor93: I connect my Keycloak server and web app to Keycloak to log into the app. If I run locally it redirects perfectly, but if I deploy the server and the web app on the same server, when the web app redirects to keycloak, it redirects to localhost inste

PlayFramework returns absolute URL in http instead of httpS?

Cyril N. I only use https in NGinx Play! A project is implemented in the Framework. Everything works fine, SSL is recognized and I can use my app anywhere other than Play! Returns an absolute URL, which is in http, not https. This is problematic and I don't kn

HTTP URL redirects to HTTPS when selenium test runs

Ruby Tester When I load the website via URL, for example http://yoururl.com, it redirects tohttps://yoururl.com I mean, passing the URL with HTTP automatically redirects like https://yoururl.comin the browser URL. @driver.get("http://yoururl.com") Browser use

PlayFramework returns absolute URL in http instead of httpS?

Cyril N. I only use https in NGinx Play! A project is implemented in the Framework. Everything works fine, SSL is recognized and I can use my app anywhere other than Play! Returns an absolute URL, which is in http, not https. This is problematic and I don't kn

keycloak redirects url to http instead of https

Rahul I have a keycloak setup behind an SSL terminating nginx proxy. When I try to access an application secured with keycloak, keycloak generates a url like this: https://keycloak.mydomain.com/auth/realms/AdfsDemo/protocol/openid-connect/auth?client_id=adfs&r

htaccess redirects to http instead of https

Danny I have redirect rules set up in htaccess - but instead of redirecting the URL to the correct scheme (https), it redirects to http first. E.g: RewriteRule ^prefixurl/(aaa|bbb|ccc)/suffixurl$ prefixurl/ddd/suffixurl [R=301,QSA,L] What would I get the resu

Keycloak redirects localhost, not remote URL

ourobor93: I connect my Keycloak server and web app to Keycloak to log into the app. If I run locally it redirects perfectly, but if I deploy the server and the web app on the same server, when the web app redirects to keycloak, it redirects to localhost inste

Keycloak redirects localhost, not remote URL

ourobor93: I connect my Keycloak server and web app to Keycloak to log into the app. If I run locally it redirects perfectly, but if I deploy the server and the web app on the same server, when the web app redirects to keycloak, it redirects to localhost inste

Keycloak redirects localhost, not remote URL

ourobor93: I connect my Keycloak server and web app to Keycloak to log into the app. If I run locally it redirects perfectly, but if I deploy the server and the web app on the same server, when the web app redirects to keycloak, it redirects to localhost inste

nginx reverse proxy redirects to http instead of https

flavonoids Make the following settings: NGINX (port 443) > Jetty (port 9090) > Spring Controller To simplify the problem, I use the following files: /main.html contains the iframe that calls the spring controller /test spring controller /test doreturn "redirec

PlayFramework returns absolute URL in http instead of httpS?

Cyril N. I only use https in NGinx Play! A project is implemented in the Framework. Everything works fine, SSL is recognized and I can use my app anywhere other than Play! Returns an absolute URL, which is in http, not https. This is problematic and I don't kn

HTTP URL redirects to HTTPS when selenium test runs

Ruby Tester When I load the website via URL, for example http://yoururl.com, it redirects tohttps://yoururl.com I mean, passing the URL with HTTP automatically redirects like https://yoururl.comin the browser URL. @driver.get("http://yoururl.com") Browser use

htaccess redirects to http instead of https

Danny I have redirect rules set up in htaccess - but instead of redirecting the URL to the correct scheme (https), it redirects to http first. E.g: RewriteRule ^prefixurl/(aaa|bbb|ccc)/suffixurl$ prefixurl/ddd/suffixurl [R=301,QSA,L] What would I get the resu

nginx reverse proxy redirects to http instead of https

flavonoids Make the following settings: NGINX (port 443) > Jetty (port 9090) > Spring Controller To simplify the problem, I use the following files: /main.html contains the iframe that calls the spring controller /test spring controller /test doreturn "redirec

Apache mod_rewrite redirects to http with 302 instead of https

Nikonj Sharma In apache 2.2 I am using mod_rewrite and I have a rewrite rule - RewriteCond %{REQUEST_URI} ^/?mysite/? RewriteRule (.*)mysite/(.*) $1$2 [R=301,L] This rewrites this url - https://www.domain.com/mysite/about/ arrive https://www.domain.com/about

PlayFramework returns absolute URL in http instead of httpS?

Cyril N. I only use https in NGinx Play! A project is implemented in the Framework. Everything works fine, SSL is recognized and I can use my app anywhere other than Play! Returns an absolute URL, which is in http, not https. This is problematic and I don't kn

htaccess redirects to http instead of https

Danny I have redirect rules set up in htaccess - but instead of redirecting the URL to the correct scheme (https), it redirects to http first. E.g: RewriteRule ^prefixurl/(aaa|bbb|ccc)/suffixurl$ prefixurl/ddd/suffixurl [R=301,QSA,L] What would I get the resu

Keycloak redirects localhost, not remote URL

ourobor93: I connect my Keycloak server and web app to Keycloak to log into the app. If I run locally it redirects perfectly, but if I deploy the server and the web app on the same server, when the web app redirects to keycloak, it redirects to localhost inste

Keycloak redirects localhost, not remote URL

ourobor93: I connect my Keycloak server and web app to Keycloak to log into the app. If I run locally it redirects perfectly, but if I deploy the server and the web app on the same server, when the web app redirects to keycloak, it redirects to localhost inste

nginx reverse proxy redirects to http instead of https

flavonoids Make the following settings: NGINX (port 443) > Jetty (port 9090) > Spring Controller To simplify the problem, I use the following files: /main.html contains the iframe that calls the spring controller /test spring controller /test doreturn "redirec

HTTP URL redirects to HTTPS when selenium test runs

Ruby Tester When I load the website via URL, for example http://yoururl.com, it redirects tohttps://yoururl.com I mean, passing the URL with HTTP automatically redirects like https://yoururl.comin the browser URL. @driver.get("http://yoururl.com") Browser use

htaccess redirects to http instead of https

Danny I have redirect rules set up in htaccess - but instead of redirecting the URL to the correct scheme (https), it redirects to http first. E.g: RewriteRule ^prefixurl/(aaa|bbb|ccc)/suffixurl$ prefixurl/ddd/suffixurl [R=301,QSA,L] What would I get the resu

nginx reverse proxy redirects to http instead of https

flavonoids Make the following settings: NGINX (port 443) > Jetty (port 9090) > Spring Controller To simplify the problem, I use the following files: /main.html contains the iframe that calls the spring controller /test spring controller /test doreturn "redirec

nginx reverse proxy redirects to http instead of https

flavonoids Make the following settings: NGINX (port 443) > Jetty (port 9090) > Spring Controller To simplify the problem, I use the following files: /main.html contains the iframe that calls the spring controller /test spring controller /test doreturn "redirec