【问题标题】:Spring Boot resource server validates token with HTTP POST instead of HTTP GETSpring Boot 资源服务器使用 HTTP POST 而不是 HTTP GET 验证令牌
【发布时间】:2019-09-05 22:14:03
【问题描述】:

我的服务器具有依赖项和配置,正如它提到的 Minimal OAuth2 Boot Configuration:

  • spring-security-oauth2
  • spring-security-oauth2-autoconfigure

安全配置用@EnableResourceServer注解。

属性包含:

spring:
  security:
    oauth2:
      resource:
        token-info-uri: https://token-validation-url/example

当我执行请求 curl -H "Authorization: xyz" http://localhost:8080/my-endpoint 时,我得到 401,但我没有看到用于令牌验证的 HTTP 调用会被执行。

如果我从属性中删除 spring 前缀,我仍然会得到 401,但它会尝试 HTTP POST 到 https://token-validation-url/example:

security:
  oauth2:
    resource:
      token-info-uri: https://token-validation-url/example

如果我使用相同的令牌并手动尝试HTTP GET https://token-validation-url/example?otoken=xyz,它会返回它是有效的。

如何指定otoken查询参数? 为什么服务器尝试使用 HTTP POST 而不是 HTTP GET 验证令牌?

【问题讨论】:

  • 我不知道这个确切的例子,但是当我使用 spring security 时,我需要一个在 header 中以 Bearer 开头的有效令牌,如下所述:stackoverflow.com/questions/33265812/…
  • 我用 Bearer 传递它,只是在示例中错过了。我不认为这会导致问题。

标签: java spring spring-boot oauth


【解决方案1】:

注意到HTTP POST https://token-validation-url/example?otoken=xyz 的验证与所使用的 GET 相同:

security:
  oauth2:
    resource:
      token-info-uri: https://token-validation-url/example

只需要设置令牌名称:

@SpringBootApplication
public class ExampleApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ExampleApplication.class, args);
        RemoteTokenServices remoteTokenServices = context.getBean(RemoteTokenServices.class);
        remoteTokenServices.setTokenName("otoken");
    }
}

其他方式配置RemoteTokenServices:Configuring resource server with RemoteTokenServices in Spring Security Oauth2

【讨论】:

    猜你喜欢
    • 2021-06-04
    • 1970-01-01
    • 2018-10-13
    • 2020-11-03
    • 2019-05-27
    • 2019-10-03
    • 1970-01-01
    • 2013-07-12
    • 2021-12-26
    相关资源
    最近更新 更多