【发布时间】:2020-11-16 02:24:52
【问题描述】:
我正在尝试使用 Spring cloud OAuth2 实现书中 OAuth-2.0-Cookbook 中的示例。
我设法实现了他的功能,但不幸的是我遇到了一个问题:为了成功调用,我必须提供基本的身份验证凭据(Authorization: Basic YWRtaW46cXdlcnR5):
@PostMapping("/oauth/revoke")
public ResponseEntity<String> revoke(@RequestParam Map<String, String> params) {
RevocationService revocationService = revocationServiceFactory
.create(params.get("token_type_hint"));
revocationService.revoke(params.get("token"));
return ResponseEntity.ok().build();
}
Github source
我喜欢在发出 POST 请求以撤销令牌时进行某种身份验证的想法,但我认为 Angular SPA 应用程序不应该一直保存用户名和密码才能成功调用 @ 987654327@.
一般来说,谷歌上的解决方案只有一个只接受令牌的端点。对于那种情况,我不知道哪种解决方案是合适的。
如何将基本身份验证功能删除到 Spring Cloud OAuth2 中?我使用这个安全配置:
http
.csrf()
.disable()
.authorizeRequests()
.anyRequest().authenticated()
.and()
// Configure token authentication permissions
.requestMatchers().antMatchers(HttpMethod.POST,"/oauth/token")
.and()
// Configure token revoke permissions
.requestMatchers().antMatchers(HttpMethod.POST,"/oauth/revoke")
.and()
.httpBasic()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
Github source:
【问题讨论】:
标签: spring spring-security oauth-2.0 spring-cloud spring-security-oauth2