Title: Unexpected behavior of Spring Security OAuth2 client
Tags: java;spring;spring-security-oauth2
Question: I need to access an OAuth2 protected service from my java microservice. I'm trying to use the spring-security-oauth2 client. But when importing it in maven my rest API starts returning a ```403 unauthorized```. Here is the module I'm importing

```<dependency&gt;
   <groupId&gt;org.springframework.security.oauth</groupId&gt;
   <artifactId&gt;spring-security-oauth2</artifactId&gt;
   <version&gt;2.3.5.RELEASE</version&gt;
</dependency&gt;
```

I assume that there is some default config I am missing to find, is there any way of overriding it and only extract the oauth2RestTemplate?

To clarify: I'm not trying to secure my endpoints and do not need any of that, only the client that allows me to call an OAuth2 service without having to deal with the tokens and it's expiration/renewal.

Comment: Stacktrace would be useful.

Comment: I'am not getting any error, just unexpected behaviour. My endpoints become secured endpoints by just importing the library, thus returning 403 errors instead of the proper payloads.

Comment: If it is possible for you, I would suggest using the `spring-security-oauth2-client` module (top level package `org.springframework.security.oauth2.client`) and following the docs here https://docs.spring.io/spring-security/site/docs/5.1.6.RELEASE/reference/htmlsingle/#oauth2client . The



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:09/17/19', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<java><spring><spring-security-oauth2>', 'Title': 'Unexpected behavior of Spring Security OAuth2 client', 'ViewCount': 34, 'id': 57974530, 'user_AboutMe': '<p>Jr Developer.</p>\n', 'user_AccountId': 9448736.0, 'user_DisplayName': 'xgrimau', 'user_Reputation': 636.0, 'user_Views': 14.0, 'user_id': 7026461.0}}