我正试图从NodeJS代码中登录到Keycloak,并且很难找到有用的示例。
关于适配器的文档是不完整的,并且没有描述最重要的事情,您如何实际登录。
我从键盘斗篷文档的基本信息和来自键盘斗篷-nodejs-连接的测试中修改了我的示例
"keycloak-connect": "15.0.2",
"express-session": "1.17.2",
const Keycloak = require('keycloak-connect');
const session = require('express-session');
const keycloakConfig = {
serverUrl: "http://keycloak.intern/auth",
realm: "client-realm",
clientId: "test-client",
bearerOnly: true
}
const memoryStore = new session.MemoryStore();
const keycloak = new Keycloak({store: memoryStore}, keycloakConfig)
async function loginUser(username, password) {
return await keycloak.grantManager.obtainDirectly(username, password).then(grant => {
return grant
})
}
const main = async () => {
let grant = await loginUser('testuser@localhost.com', "test_password")
}
main().then(()=>{
process.exit(0)
}, (err)=>{
console.error(err)
process.exit(1)
})然而,我犯了一个错误:
错误:400:错误请求
在服务器端,我看到日志:
2021-11-19T10:16:49,312+01:00 org.keycloak.events type=LOGIN_ERROR,realmId=客户端-领域,clientId=test-client,userId=null,ipAddress=192.168.111.2222,error=not_allowed,auth_method=oauth_credentials,grant_type=password,client_auth_method=客户端-机密
因此,keycloak是被调用的,然而,用户名在某种程度上是不正确的。
该方法的签名是OK的,它得到用户名,以及它期望的方式。
我在这里错过了什么?
发布于 2021-11-19 09:52:18
错误not_allowed表示不允许直接授予。在Direct Access Grants Enabled密钥披风客户端配置中启用test-client。
https://stackoverflow.com/questions/70032465
复制相似问题