What's going on in Spring Boot OAuth2 `AbstractTokenGranter.validateGrantType()` method?

断了今生、忘了曾经 提交于 2019-12-13 14:27:49

问题


I'm securing Spring Cloud/Spring Boot microservices with OAuth2 and all seems nicely wired up in the Authorization Server. But when I send a POST request via postman to /oauth/token to obtain an access token with grant_type = client_credentials I get the following response:

{
    "error": "invalid_client",
    "error_description": "Unauthorized grant type: client_credentials"
}

However in the oauth_client_details database table where OAuth Clients are registered, I have the following setup for the current Client making this request;

authorized_grant_types = `password, authorization_code, client_credentials, refresh_token`

So I took the liberty to debug Spring Boot's entire oauth flow and found something very funny happening in the AbstractTokenGranter.validateGrantType(String grantType, ClientDetails clientDetails) method. See the illustration below;

So I'd like to understand what may likely be going on here, cos it's practically unfathomable to me.


回答1:


Looks like you're using RDBMS. When you insert client record in oauth_client_details table, make sure there are no spaces in value for authorized_grant_typescolumn.

Value should be like this (no space after comma):

'password,client_credentials,refresh_token'


来源:https://stackoverflow.com/questions/51930058/whats-going-on-in-spring-boot-oauth2-abstracttokengranter-validategranttype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!