spring - Spring security OAuth2 令牌自省
问题描述
我尝试通过自省使用 Spring 安全性来验证 OAuth2 令牌。实际上,当我调用控制器时,我的应用程序不会尝试访问 OAuth 服务器进行自省并返回 403。
我的自信:
spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=https://example.net/introspection
spring.security.oauth2.resourceserver.opaquetoken.client-id=clientId
spring.security.oauth2.resourceserver.opaquetoken.client-secret=clientSecret
网络安全:
@EnableWebSecurity
public class WebServerConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.oauth2ResourceServer().opaqueToken();
}
}
我的控制器:
@RestController
public class Controller {
@PostMapping(value = "/foo", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void uploadMedia(BearerTokenAuthentication bearerTokenAuthentication,
@RequestHeader(value = "Authorization") String bearerToken){
System.out.println(bearerTokenAuthentication.getToken().getTokenValue());
}
}
如何通过自省使用弹簧安全来验证 OAuth 令牌?
马修
解决方案
尝试添加以下依赖项
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.8.RELEASE</version>
</dependency>
在应用程序属性中,您可以指定
security.oauth2.resource.token-info-uri=http://localhost:8080/oauth/check_token.
现在,核心类 - RemoteTokenServices.loadAuthentication 将用于调用授权服务器。你可以把它放在调试中。
security.oauth2.client.client-id=client1
security.oauth2.client.client-secret=secret1
推荐阅读
- python - 从嵌套字典中提取值
- javascript - 为什么 URL.createObjectURL 开始将我的文件名作为 GUID?
- gradle - 无法让 Gradle 签名插件与子项目一起使用
- node.js - Mongoees 查询以查找具有 id 数组的对象,而不管其 id 的顺序如何 - Nodejs
- twilio - Twilio - 对 2 个端点/webhook 的入站 SMS webhook 请求?
- c - Matlab VLFeat - 错误:在 'void' 之前需要 '='、','、';'、'asm' 或 '__attribute__'
- javascript - 如果未使用 jQuery hide() 显示 AngularJS 表单项,是否对其进行验证?
- reactjs - 在 useEffect() 中返回一个对象并在 React 外部访问它(在分配状态之后)
- python-3.x - Outlook 2FA 的 SMTP 中继配置以从 python 脚本发送邮件
- python - 如何加入 Pandas 数据帧,但只对左数据帧中的每一行使用右数据帧中的行一次?