Java 什么';Spring Boot OAuth2`AbstractTokenGranter.validateGrantType()`方法中发生了什么?
我正在用OAuth2保护SpringCloud/SpringBoot微服务,所有这些似乎都很好地连接在授权服务器上。但是,当我通过邮递员向Java 什么';Spring Boot OAuth2`AbstractTokenGranter.validateGrantType()`方法中发生了什么?,java,spring-boot,spring-security,oauth-2.0,spring-security-oauth2,Java,Spring Boot,Spring Security,Oauth 2.0,Spring Security Oauth2,我正在用OAuth2保护SpringCloud/SpringBoot微服务,所有这些似乎都很好地连接在授权服务器上。但是,当我通过邮递员向/oauth/token发送POST请求,以获得具有grant\u type=client\u凭据的访问令牌时,我得到以下响应: { "error": "invalid_client", "error_description": "Unauthorized grant type: client_credentials" } 但是,在注册oau
/oauth/token
发送POST请求,以获得具有grant\u type=client\u凭据的访问令牌时,我得到以下响应:
{
"error": "invalid_client",
"error_description": "Unauthorized grant type: client_credentials"
}
但是,在注册oauth客户机的oauth_client_details
数据库表中,我对发出此请求的当前客户机进行了以下设置:
authorized_grant_types = `password, authorization_code, client_credentials, refresh_token`
所以我冒昧地调试了Spring Boot的整个oauth流,发现AbstractTokenGranter.validateGrantType(String grantType,ClientDetails ClientDetails)
方法中发生了一些非常有趣的事情。见下图
所以我想了解这里可能发生的事情,因为这对我来说几乎是深不可测的。看起来您正在使用RDBMS。在oauth\u client\u details
表中插入客户记录时,请确保authorized\u grant\u types
列的值中没有空格
值应如下所示(逗号后无空格):
这似乎是相关的:神圣的烟!。。。这让我被困了整整1.5天。。。想想看,这只是因为逗号分隔列表中的空格???。。。啊哈!!!。。。现在我意识到,当我查看调试器时,空格实际上就在那里,我一辈子都没有注意到。谢谢@Vijay,你太棒了!我感觉到你了,我也曾经花了几乎一整天的时间来弄明白这一点。我很高兴能帮上忙。
'password,client_credentials,refresh_token'