因此,我在使 Keycloak-Connect 示例正常工作时遇到了一些问题。
基本上,我在虚拟机上的快速路线上使用 Keycloak 进行了简单的检查
(10.10.10.54:8081)如下。
app.get('/api*', keycloak.protect(), (req, res) => res.status(200).send({
message: 'Hit API Backend!',
}));
我的 Keycloak 服务器位于单独的虚拟机上(对于本例 http://keycloak.myexternaldomain.ca/auth/ )
我一直在调用电话来测试这一点。
RESULT=`curl --data "grant_type=password&client_secret=mysecret&client_id=account&username=myusername&password=mypassword" http://keycloak.myexternaldomain.ca/auth/realms/TEST/protocol/openid-connect/token`
这每次都会返回正确的访问 token ,
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
将 token 解析为变量。
curl http://10.10.10.54:8081/api -H "Authorization: bearer $TOKEN"
仍然不断返回拒绝访问,我在类似的示例中尝试了此操作 Keycloak-Quickstart Node Service看看是否存在更详细的错误。我收到的回复是
Validate grant failed
Grant validation failed. Reason: invalid token (wrong ISS)
不过,如果我稍等一下,它会给我一个“过期 token ”错误,所以我觉得我走在正确的轨道上。
很明显,我发出 token 的地方与预期的地方不匹配?我可以通过 cURLing 来调用从 keycloak 服务器本身获取用户凭据
curl --data "grant_type=password&token=$TOKEN&client_secret=secret&client_id=account&username=myaccount&password=mypassword" http://keycloak.myexternaldomain.ca/auth/realms/TEST/protocol/openid-connect/token/introspect
我是否误解了我应该如何使用 Keycloak,或者这是一个设置问题?
提前致谢
最佳答案
我的问题出在我的 keycloak.json 中......我有一个与我正在验证的领域不同的领域。
如果您遇到此问题,我建议修改 keycloak-auth-utils为您提供更详细的授权管理器错误日志记录。
具体改变
else if (token.content.iss !== this.realmUrl) {
reject(new Error('invalid token (wrong ISS)'));
}
到
else if (token.content.iss !== this.realmUrl) {
reject(new Error('invalid token (wrong ISS) Expecting: '+this.realmUrl+' Got: '+token.content.iss);
}
帮助我自己找到了这个问题。
关于node.js - Keycloak - 授权验证失败。原因: invalid token (wrong ISS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46097124/