【问题标题】:springfox swagger api: Can't get OAuth 2.0 workingspringfox swagger api:无法使 OAuth 2.0 工作
【发布时间】:2019-11-29 15:03:25
【问题描述】:

我在 Spring Boot REST API 中使用 Spring security OAuth 2.0 授权。它在 Postman 测试中按预期工作,但我没有成功使其从 Swagger “试用”中工作。我在这里使用这篇文章:How to configure oAuth2 with password flow with Swagger ui in spring boot rest application。这应该有效,但在我的情况下无效。我只需要对以下方法进行一些说明:

    private SecurityContext securityContext() {
    return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.ant("/user/**"))
            .build();
}

/user/** URL 代表什么?这是否意味着定义的安全上下文应该应用于与模式匹配的所有 URL?还是说要调用这个URL来获取用户的详细信息?

我的代码与帖子中的代码完全相同,但是,在我用用户凭据和范围等填写对话框后。我得到“Auth ErrorTypeError: Failed to fetch”,无论我做什么我都做不到获取任何有用的日志消息。

这可能与 CORS 有关,因为在这种情况下不会调用我在进行 Postman 测试时调用的 HTTP 过滤器。

有什么建议吗?

非常感谢。

亲切的问候,

尼古拉斯

【问题讨论】:

    标签: spring-boot swagger


    【解决方案1】:

    我确认文章中提到的代码按预期工作。我在使用错误的 URL 等进行测试时弄错了。对不起,smalltalk。

    亲切的问候,

    尼古拉斯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      相关资源
      最近更新 更多