spring - 创建客户端 Spring Security OAuth2 应用程序
问题描述
我的项目中有以下架构:
JOB_SCHEDULE ---> API A ---> API B
我的 JOB_SCHEDULE 调用 API A 没有任何身份验证,这对我们来说没问题。但是 API A 需要调用 API B,而这最后有一个 client_credentials 认证。
我们有一个 IdentityServer 来生成这个令牌,所以在API A中我配置了以下内容:
security.oauth2.client.client-id=clientid
security.oauth2.client.client-secret=secret
security.oauth2.client.access-token-uri=http://localhost:8080/oauth/token
security.oauth2.client.user-authorization-uri=http://localhost:8080/oauth/authorize
security.oauth2.client.grant-type=client_credentials
security.oauth2.client.authentication-scheme=form
在我的 pom.xml 中:
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
我在API A中有一个调用 API B 的端点,请参阅:
private final OAuth2RestTemplate restTemplate;
@GetMapping("/sayhello")
public ResponseEntity<String> redirectToResourceServer() {
String strReturn = restTemplate.getForObject("http://localhost:9090/noscope", String.class);
return ResponseEntity.ok(strReturn);
}
但是每次我打电话时http://localhost/api/v1/hello/sayhello
,我都会被重定向到登录页面,但这是 client_credentials 我不应该被重定向。
解决方案
推荐阅读
- swift - 计算两个坐标之间的距离并将其显示在 UITableViewCell 的标签内
- java - 何时使用接口变量与实现变量
- elasticsearch - 在 Kibana 仪表板中使用 SQL
- python - 为什么我要为 Python 中数据框的每个索引获取列标题?
- c++ - 冒泡排序降序
- javascript - laravel 在提交表单时没有获取文件
- laravel - 重定向到 Laravel 路由 VueJS
- accessibility - 在网站上的两个选项之间进行选择,我应该使用按钮还是单选按钮?
- python - 是否存在与 torch.nn.Sequential 等效的“Split”?
- vue.js - 在 Nuxt 中使用 Filepond 上传的图像在哪里?