Keycloak - Getting 401 in Ajax calls after token expired

半世苍凉 提交于 2019-12-24 09:57:38

问题


I'm using keycloak 3.4.3 Server and 3.4.3 springboot adapter. The login is done with the Java Adapter using the following json configurations:

{
  "realm": "real name",
  "auth-server-url": "http://172.21.34.65/auth",
  "ssl-required": "external",
  "resource": "appName",
  "public-client": true,
  "use-resource-role-mappings": true
}

The token is refreshed with non ajax calls but when the request contains the header X-Requested-With: XMLHttpRequest the token is not refreshed. Is there a problem with my config or is this the normal behavior and I need to use the JS adapter to refresh the token before the ajax calls?


回答1:


For me an ugly solution was to embed an invisible self-reloading iframe that causes the token refresh. But that is the source of another problem: sometimes the redirect after logging into keycloak leads to the iframe url rather than the desired one. I haven't found a satisfying solution yet.



来源:https://stackoverflow.com/questions/50352049/keycloak-getting-401-in-ajax-calls-after-token-expired

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!