<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: 'helvetica Neue', helvetica;">Hi,&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">I’m integrating a web application using angularjs 1.4.6 and keycloak 1.5.0.&nbsp;&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">The application and keycloak app-servers are on different ports.&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">The application works ok when the session is not expired.&nbsp;&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">After session expiration keycloak.updateToken() fails with&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">400 Bad Request. Chrome shows the following in the console:&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">XMLHttpRequest cannot load&nbsp;</span><a href="http://localhost:8080/auth/realms/demo/protocol/openid-connect/token" style="font-family: 'helvetica Neue', helvetica;">http://localhost:8080/auth/realms/demo/protocol/openid-connect/token</a><span style="font-family: 'helvetica Neue', helvetica;">. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '</span><a href="http://localhost:9080'" style="font-family: 'helvetica Neue', helvetica;">http://localhost:9080'</a><span style="font-family: 'helvetica Neue', helvetica;">&nbsp;is therefore not allowed access. The response had HTTP status code 400.&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">The behavior is same with Safari and Firefox.&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">If I get it right, this 400 response from keycloak shouldn’t be&nbsp;&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">interpreted as CORS failure by browsers?&nbsp;&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">This is keycloak response when session is alive:&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--&gt; HTTP/1.1 200 OK&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;X-Powered-By: Undertow/1&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Server: WildFly/9&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Access-Control-Expose-Headers: Access-Control-Allow-Methods&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Date:&nbsp;</span><a href="http://airmail.calendar/2015-09-29%2010:54:52%20GMT+6" style="font-family: 'helvetica Neue', helvetica;">Tue, 29 Sep 2015 04:54:52 GMT</a><span style="font-family: 'helvetica Neue', helvetica;">&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Connection: keep-alive&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Access-Control-Allow-Origin:&nbsp;</span><a href="http://localhost:9080/" style="font-family: 'helvetica Neue', helvetica;">http://localhost:9080</a><span style="font-family: 'helvetica Neue', helvetica;">&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Access-Control-Allow-Credentials: true&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Transfer-Encoding: chunked&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Content-Type: application/json&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">And this one with session expired:&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --&gt; HTTP/1.1 400 Bad Request&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Connection: keep-alive&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; X-Powered-By: Undertow/1&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Server: WildFly/9&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Transfer-Encoding: chunked&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Content-Type: application/json&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Date:&nbsp;</span><a href="http://airmail.calendar/2015-09-29%2010:55:03%20GMT+6" style="font-family: 'helvetica Neue', helvetica;">Tue, 29 Sep 2015 04:55:03 GMT</a><span style="font-family: 'helvetica Neue', helvetica;">&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">So my concerns are:&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">1. Why CORS headers depend on session validity? This caused much confusion for me,&nbsp;&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">because I thought there is a problem&nbsp;with CORS, until I understood this was session problem.&nbsp;&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">2. I think it would also be great to have some more context&nbsp;on error responses&nbsp;&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"><span style="font-family: 'helvetica Neue', helvetica;">(like returning some json with error description), because HTTP responses are too generic.&nbsp;</span><br style="font-family: 'helvetica Neue', helvetica;"></div><br><div id="bloop_sign_1443600488081101824" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">--&nbsp;<br>Tair Sabirgaliev</div><div style="font-family:helvetica,arial;font-size:13px">Bee Software, LLP</div></div></body></html>