【问题标题】:spring-boot-starter-oauth2-resource-server vs spring-cloud-starter-oauth2 which to use?spring-boot-starter-oauth2-resource-server vs spring-cloud-starter-oauth2 使用哪个?
【发布时间】:2021-05-07 20:51:17
【问题描述】:

我刚开始使用 OAuth2 学习 Spring Security,我想为我的微服务 Restful Api 创建授权服务器和资源服务器。但是我很困惑从哪个依赖开始,因为我找到了其中的一些。我使用 spring boot 2.4.1 版本。这里我在下面列出:

这个是我在 spring 初始化页面找到的,当我尝试添加 OAuth2 库时,这个是最新版本吗?

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-oauth2-resource-server -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>

在这个下面我在一些教程中找到了它,我认为这个已经被弃用了,对吧?

<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-oauth2 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-oauth2</artifactId>
    <version>2.2.4.RELEASE</version>
</dependency>

最后一个,是下面这个吗,因为我看不到更新版本了,这个也被弃用了吗?

<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 -->
<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.5.0.RELEASE</version>
</dependency>

我应该使用哪一个?

【问题讨论】:

    标签: java spring spring-boot oauth-2.0 dependencies


    【解决方案1】:

    Spring Boot 2.4.x uses Spring Security 5.4.x,遗憾地删除了对授权服务器的支持。

    有一个新项目,spring-authorization-sever,旨在在未来将其带回,但目前它只有 0.0.3 版。

    如果您的项目需要它,我建议您改用 spring boot 2.3.x。

    【讨论】:

    【解决方案2】:

    正如@dislexit 所评论的,授权服务器已从 Spring Security 中删除,并且有另一个项目将支持它,答案是 Spring Security 5+ 将支持 oauth2 的资源和客户端功能,因此您可以使用它而不是两者你提到了。

    点击此链接查看差异https://github.com/spring-projects/spring-security/wiki/OAuth-2.0-Features-Matrix

    【讨论】:

      猜你喜欢
      • 2019-04-29
      • 2023-04-04
      • 2017-08-28
      • 2014-04-07
      • 1970-01-01
      • 2021-10-24
      • 2019-12-26
      • 2023-01-12
      • 2016-01-29
      相关资源
      最近更新 更多