【发布时间】:2021-03-11 14:22:55
【问题描述】:
我已经实现了一个带有微服务架构的简单系统,在我的系统中,大约有 5 个微服务实例,它们用作资源服务器。资源服务器和授权服务器之间的通信采用非对称方式,遵循 OAuth 密码流程。
当用户通过门户模块注册或登录系统调用服务时,我必须返回一个包含电子邮件和access_token的响应,并且响应应该保存在本地存储中。
当我调用http://localhost:9098/oauth/token 端点时,出现以下错误。
org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException: Unable to obtain a new access token for resource 'null'. The provider manager is not configured to support it.
application.yml
security:
oauth2:
client:
grant-type: password
client-id: web
client-secret: 14292
access-token-uri: http://127.0.0.1:9098/oauth/token
配置类
@Configuration
public class WebPortalConfig {
@Bean
@ConfigurationProperties("security.oauth2.client")
public ClientCredentialsResourceDetails oAuthDetails()
{
return new ClientCredentialsResourceDetails();
}
@Bean
public RestTemplate restTemplate()
{
return new OAuth2RestTemplate(oAuthDetails());
}
}
OAuthDetails 类
@Getter
@Setter
public class OAuthDetails {
private String access_token;
private String token_type;
private String refresh_token;
private int expires_in;
}
服务类
private OAuthDetails getOAuthDetails()
{
String url="http://127.0.0.1:9098/oauth/token?grant_type=password&username=nafazbenzema@gmail.com&password=benz";
return restTemplate.getForObject(url, OAuthDetails.class);
}
附言-
-
如何克服这个错误?
-
这种方法是否正确,如果您有更好的方法,请提出答案
【问题讨论】:
标签: java spring-boot spring-security oauth-2.0 microservices