使用refresh_token WSO2 IS 5.2.0时,“提供的授权授权无效”

时间:2016-11-15 22:05:18

标签: wso2 wso2is wso2carbon

我最近将我的环境从WSO2 IS 5.0.0更新为WSO2 IS 5.2.0。我的环境包含部署在EC2 AWS实例上的一台计算机。我正在使用MySQL(不是默认的H2数据库)。部署IS的计算机是Windows Server 2012 R2 我使用密码授予类型来获取特定用户的访问令牌,并存储刷新令牌,以便我能够在需要时发出另一个访问令牌。我正在执行以下请求以获取访问令牌:
POST
https://(IS-URL)/oauth2/token?scope=openif&grant_type=password&username=test@abv.bg@localhost.io&password=Asd123@@
配置适当的Authorization Basic标头
之后我使用刷新令牌来发布新的访问令牌。例如:
POST
https://(IS-URL)/oauth2/token?scope=openid&grant_type=refresh_token&refresh_token=
配置适当的Authorization Basic标头
我以2-5秒的间隔多次从Postman执行最新的POST调用后,在前5-7次调用之后,我开始收到以下错误响应:

{  
 "error": "invalid_grant",  
 "error_description": "Provided Authorization Grant is invalid"  
}  

我希望收到新的访问令牌,而我收到上面提到的错误。然后我通过更新以下行来修改log4j.properties:

log4j.logger.org.wso2.carbon.identity=DEBUG
log4j.logger.org.wso2.carbon.identity.application=DEBUG
log4j.logger.org.wso2.carbon.identity.mgt=DEBUG
log4j.logger.org.wso2.carbon.identity.oauth2=DEBUG
log4j.logger.org.wso2.carbon.identity.provisioning=DEBUG
log4j.logger.org.wso2.carbon.identity.user.account.association=DEBUG
log4j.logger.org.wso2.carbon.identity.user.profile.mgt=DEBUG

然后我启动了IS并再次尝试了上面提到的场景,这就是我在日志文件中收到的内容:

[2016-11-15 21:29:18,873] DEBUG     {org.wso2.carbon.identity.oauth2.OAuth2Service} -  Access Token request received for Client ID GCFfyPSGkykWG4zQTKoDp8NEvjIa, User ID null, Scope :   [openid] and Grant Type : refresh_token
[2016-11-15 21:29:18,873] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.clientauth.AbstractClientAuthHandler} -  Can authenticate with client ID and Secret. Client ID: GCFfyPSGkykWG4zQTKoDp8NEvjIa
[2016-11-15 21:29:18,873] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.clientauth.AbstractClientAuthHandler} -  Grant type : refresh_token Strict client validation set to : null
[2016-11-15 21:29:18,873] DEBUG {org.wso2.carbon.identity.oauth2.util.OAuth2Util} -  Client credentials were available in the cache for client id : GCFfyPSGkykWG4zQTKoDp8NEvjIa
[2016-11-15 21:29:18,873] DEBUG {org.wso2.carbon.identity.oauth2.util.OAuth2Util} -  Successfully authenticated the client with client id : GCFfyPSGkykWG4zQTKoDp8NEvjIa
[2016-11-15 21:29:18,873] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.grant.RefreshGrantHandler} -  Access Token is not in 'ACTIVE' or 'EXPIRED' state for Client with Client Id : GCFfyPSGkykWG4zQTKoDp8NEvjIa
[2016-11-15 21:29:18,873] DEBUG {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer} -  Invalid Grant provided by the client Id: GCFfyPSGkykWG4zQTKoDp8NEvjIa
[2016-11-15 21:29:18,873] DEBUG {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer} -  OAuth-Error-Code=invalid_grant client-id=GCFfyPSGkykWG4zQTKoDp8NEvjIa grant-type=refresh_token scope=openid

有关详细信息,请查看整个日志文件:
https://www.dropbox.com/s/ygfc9hrrgxjkzkh/console.log?dl=0
有人经历过类似的问题吗?这可能是IS中的错误还是由于某种错误配置造成的? 我看了Refresh token returns invalid grant type,但未能找到问题的直接答案 只是想提一下,我尝试每秒发出一个请求并尝试这个间隔5分钟并且无法重现该问题。当请求频率足够高时,似乎会发生这种情况 提前谢谢。

1 个答案:

答案 0 :(得分:2)

根据this code和您的日志,访问令牌既不在' ACTIVE'也没有' EXPIRED'州。您可以在IDN_OAUTH2_ACCESS_TOKEN表中查找该特定令牌。这会给你一个关于出了什么问题的暗示。

<强>更新 我分析了你的数据集。问题是,由于您已多次发送相同的令牌请求,因此此表中有许多条目包含TOKEN_STATE=INACTIVE。此外,您在TIME_CREATED列中有2个具有相同时间戳(即2016-11-17 11:40:02)的条目,这恰好是最新的。因此,当IS尝试选择最新的令牌(理想情况下应该是ACTIVE令牌)时,db server会返回2个令牌。但IS必须选择一个。它可以是其中任何一个,因为时间戳是相同的。所以当它选择INACTIVE时,你应该看到上面的错误。

理想情况下,IS应该正确处理这个问题。但作为一种解决方案,如果您不经常发送相同的请求,您应该能够摆脱错误。只需发送请求并等待响应。如果需要花费大量时间,那么分析和解决这个问题就不同了。