【发布时间】:2020-11-21 04:11:43
【问题描述】:
我正在使用 Postgresql DB 在 SpringBoot 中开始配置 OAuth2。在邮递员中请求令牌后,我收到错误:
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
有效载荷:
curl --location --request POST 'localhost:9000/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic Y2xpZW50SWQ6c2VjcmV0' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=user' \
--data-urlencode 'password=pass'
资源服务器配置:
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter
{
private static final String ROOT_PATTERN = "/**";
@Override
public void configure(HttpSecurity http) throws Exception
{
http.authorizeRequests()
.antMatchers(HttpMethod.GET, ROOT_PATTERN).access("#oauth2.hasScope('read')")
.antMatchers(HttpMethod.POST, ROOT_PATTERN).access("#oauth2.hasScope('write')")
.antMatchers(HttpMethod.PATCH, ROOT_PATTERN).access("#oauth2.hasScope('write')")
.antMatchers(HttpMethod.PUT, ROOT_PATTERN).access("#oauth2.hasScope('write')")
.antMatchers(HttpMethod.DELETE,
ROOT_PATTERN).access("#oauth2.hasScope('write')");
}
}
我检查了请求数据,一切都是正确的。我找不到问题是如何发生的。
【问题讨论】:
标签: spring-boot spring-security spring-oauth2