[英]React-Keycloak keeps refreshing
I am trying to use keycloak to secure a React application.我正在尝试使用 keycloak 来保护 React 应用程序。 I am using two packages: React-keycloak and keycloak-js.我正在使用两个包:React-keycloak 和 keycloak-js。
This is my keycloak provider这是我的密钥斗篷提供商
<ReactKeycloakProvider
authClient={keycloak}
onEvent={eventLogger}
onTokens={tokenLogger}
>
<Foo></Foo>
</ReactKeycloakProvider>
and this my keycloak object:这是我的 keycloak object:
const keycloak = new Keycloak({
url: "http://XXX.XXX.XXX.XXX:8080",
realm: "testrealm",
clientId: "testclient",
});
If I have no login cookie, i will be directed to the Keycloak login page.如果我没有登录 cookie,我将被定向到 Keycloak 登录页面。 I can then login and return to my application.然后我可以登录并返回到我的应用程序。 Now the page is constantly refreshed again and again as it tries to call urls like this:现在页面不断刷新,因为它试图调用这样的 url:
http://localhost:3000/#state=6b9c8273-3e7a-46d8-81e6-89d83a539d81&session_state=cb1b6069-b99a-4346-b0bf-6ea37e80900c&code=2b1ce5bb-ec49-4c1e-942e-9b70c74c36ee.cb1b6069-b99a-4346-b0bf-6ea37e80900c.d8e66d53-2283-4ead-b4f4-c11ddd5aa2a6
I have tried different init options including:我尝试了不同的初始化选项,包括:
initOptions={{ onLoad: "login-required"}}
initOptions={{ checkLoginIframe: false }}
but nothing seems to work.但似乎没有任何效果。
No examples I find seem to do anything more than this so I'm not sure if it's a bug, if I'm missing some configuration, or whatever else.我发现没有比这更有效的例子了,所以我不确定这是不是一个错误,我是否缺少一些配置,或者其他什么。
I'm currently using versions: @react-keycloak/web@3.4.0 keycloak-js@19.0.1我目前使用的版本:@react-keycloak/web@3.4.0 keycloak-js@19.0.1
but have used both newer and older version, with no success.但同时使用了新旧版本,但没有成功。
a similar issue: Page keeps refreshing and changing the query parameter 'state' and 'session' in URL when implementing React with keycloak一个类似的问题: 使用keycloak实现React时,页面不断刷新并更改URL中的查询参数'state'和'session'
UPDATE: https://github.com/react-keycloak/react-keycloak/issues/182更新: https://github.com/react-keycloak/react-keycloak/issues/182
I am using React 18.0 where StrictMode causes useEffect to be called twice.我正在使用 React 18.0,其中 StrictMode 导致 useEffect 被调用两次。 This seems to be a breaking change for the ReactKeycloakProvider+keycloak.js.这似乎是 ReactKeycloakProvider+keycloak.js 的重大变化。 The workaround is to move StrictMode inside the ReactKeycloakProvider instead of around the whole application!解决方法是将 StrictMode 移动到 ReactKeycloakProvider 内部,而不是围绕整个应用程序移动!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.