【问题标题】:Revoke Oauth2 token without using Basic Auth在不使用基本身份验证的情况下撤销 Oauth2 令牌
【发布时间】: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


【解决方案1】:

您可以像这样禁用撤销端点的身份验证

http
...
.authorizeRequests()
.antMatchers("/oauth/revoke").permitAll()
...

【讨论】:

  • 我试过这个:pastebin.com/z3691x1Ebut我得到`工厂方法'springSecurityFilterChain'抛出异常;嵌套异常是 java.lang.IllegalStateException: Can't configure antMatchers after anyRequest`
猜你喜欢
  • 2023-03-12
  • 2014-12-01
  • 2020-03-03
  • 1970-01-01
  • 1970-01-01
  • 2017-08-15
  • 2016-11-02
  • 1970-01-01
  • 2018-02-23
相关资源
最近更新 更多