Keycloak – 授权validation失败。 原因:无效标记(错误的ISS)
所以我有一些问题让我的Keycloak连接示例工作。
基本上我有一个快速路由在我的虚拟机上与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/ )
我一直在做这个testing的电话是。
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=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
将令牌parsing为一个variables。
curl http://10.10.10.54:8081/api -H "Authorization: bearer $TOKEN"
这仍然不断返回访问拒绝,我尝试了一个类似的例子与Keycloak快速启动节点服务 ,看看是否有一个更详细的错误。 我收到回来的是
Validate grant failed Grant validation failed. Reason: invalid token (wrong ISS)
虽然如果我等了一会儿,它会给我一个过期的令牌错误,所以我觉得我在正确的轨道上。
所以很明显,我从哪里发布令牌不符合它所期望的地方有什么问题? 我可以拨打电话,通过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 …我有一个不同的领域,而我正在authentication的领域。
如果你有这个问题,我build议修改keycloak-auth-utils ,让你在grant-manager上logging更详细的错误。
具体改变
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); }
帮助我自己追踪这个问题。