Keycloak JavaScript适配器`keycloak.init`加载404 iframe [英] Keycloak javascript adapter `keycloak.init` load 404 iframe

查看:249
本文介绍了Keycloak JavaScript适配器`keycloak.init`加载404 iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript适配器keycloak-js为我的客户端应用程序集成Keycloak.

I am trying to integrate Keycloak for my client side application using javascript adapter keycloak-js.

但是,我似乎无法使其正常工作.这是我的代码

However, I can't seem to make it work. This is my code

const keycloak = new Keycloak({
    realm: 'my-realm',
    url: 'http://localhost:8080/auth/',
    clientId: 'my-client',
});

try {
    const authenticated = await keycloak.init();
    console.log(authenticated);
} catch (e) {
    console.log(e);
}

它不返回任何内容,甚至不返回错误或回调中的任何内容.我只有 GET http://localhost:8080/auth/realms/my-realm/protocol/openid-connect/3p-cookies/step1.html 404 (Not Found) 不确定我做错了什么?我按照文档进行操作,但是找不到有关此行为的任何信息 如果我在浏览器中输入上面的网址,我会看到

It doesn't return anything, not even error or anything from the callback. I only have GET http://localhost:8080/auth/realms/my-realm/protocol/openid-connect/3p-cookies/step1.html 404 (Not Found) Not sure what did I do wrong? I follow the documentation but I can't find anything about this behaviour If I type the url above in browser, I see this

我能做些什么吗?

编辑:通过将keycloak服务器与keycloak-js版本进行匹配,我设法使用此代码使其工作. 将服务器和keycloak-js版本升级到11.0.2确实对我有用,并将这两个版本都降级到10.0.2

I managed to make it work using this code by matching keycloak server with keycloak-js version. Upgrading server and keycloak-js version to 11.0.2 does work for me as well as downgrading both version to 10.0.2

这是我正在使用的客户端配置

This is the client configuration that I'm using

在上面的代码示例中,我可以在开发工具中看到console.log(isAuthorised);返回false,如果执行const isAuthorised = await keycloak.init({ onLoad: 'login-required' });,它将重定向我到登录页面,并在成功登录后重定向到该页面.希望这会有所帮助.

In the code example above, I can see console.log(isAuthorised); return false in dev tools, and if I do const isAuthorised = await keycloak.init({ onLoad: 'login-required' });, It will redirect me to login page and redirect me back to this page after successful login. Hope this helps.

推荐答案

这可能是keycloak-js与您的密钥库服务器之间的版本不匹配.我正在使用最新的keycloak-js版本11.0.010.0.1的密钥库服务器版本,这会导致此确切错误.将客户端上的keycloak-js降级为10.0.2对我来说是成功的窍门. (尚未尝试升级密钥斗篷服务器,但很可能也可以升级)

It's probably a version mismatch between keycloak-js and your keycloak server. I was using the newest keycloak-js version 11.0.0 with a keycloak server version of 10.0.1, which lead to this exact error. Downgrading keycloak-js on the client side to 10.0.2 did the trick for me. (Haven't tried to upgrade the keycloak server yet, but most likely works as well)

这篇关于Keycloak JavaScript适配器`keycloak.init`加载404 iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆