Home > Software engineering >  What is the difference between spring-boot-starter-oauth2-client, spring-cloud-starter-oauth2 and sp
What is the difference between spring-boot-starter-oauth2-client, spring-cloud-starter-oauth2 and sp

Time:02-14

I am developing a client application for client_credentials grant type flow in OAUTH2.

I am not able to decide on which dependency to use in my project for this purpose among the following.

  1. spring-boot-starter-oauth2-client
  2. spring-cloud-starter-oauth2
  3. spring-security-oauth2

I referred this documentation from spring-projects in which under client-support section it had a table describing the available options. But I am not able to understand which column is referring to which of the above dependencies.

I want to configure a WebClient or RestTemplate which retrieves the OAUTH2 token from the auth-server automatically before accessing a resource-server.

Please guide me in choosing the right artifact for my project.

CodePudding user response:

If you are using Spring Boot you should choose org.springframework.boot:spring-boot-starter-oauth2-client.
This includes Spring Security's OAuth 2.0 Client support and provides Spring Boot auto-configuration to set up OAuth2/Open ID Connect clients.
You can read about how to configure client in the Spring Boot reference documentation.
You can also find additional details in the Spring Security reference documentation.

If you are not using Spring Boot then you should choose org.springframework.security:spring-security-oauth2-client. This also provides Spring Security's latest OAuth 2.0 Client support, but does not include the Spring Boot auto-configuration.
The corresponding documentation is also the Spring Security reference documentation.

The third dependency you mentioned org.springframework.security.oauth:spring-security-oauth2 should not be used because it is part of the legacy Spring Security OAuth project, which is now deprecated.
The functionality that this library provided has now been moved into Spring Security.
That is what the Migration Guide describes, the migration from the legacy project to the latest Spring Security support.

You should not use the org.springframework.cloud:spring-cloud-starter-oauth2 at this time, because it relies on the legacy OAuth support.
This is likely to change in the future, as the Spring Cloud team updates to the latest Spring Security support.

  • Related