Spring Security 5 Replacement for OAuth2RestTemplate : <p>In <code>spring-security-oauth2:2.4.0.RELEASE</code> classes such as <code>OAuth2RestTemplate</code>, <code>OAuth2ProtectedResourceDetails</code> and <code>ClientCredentialsAccessTokenProvider</code> have all been marked as deprecated.</p>

<p>From the javadoc on these classes it points to a <a href="https://github.com/spring-projects/spring-security/wiki/OAuth-2.0-Migration-Guide" rel="noreferrer">spring security migration guide</a> that insinuates that people should migrate to the core spring-security 5 project. However I'm having trouble finding how I would implement my use case in this project.</p>

<p>All of the documentation and examples talk about integrating with a 3rd part OAuth provider if you want incoming requests to your application to be authenticated and you want to use the 3rd party OAuth provider to verify the identity. </p>

<p>In my use case all I want to do is make a request with a <code>RestTemplate</code> to an external service that is protected by OAuth. Currently I create an <code>OAuth2ProtectedResourceDetails</code> with my client id and secret which I pass into an <code>OAuth2RestTemplate</code>. I also have a custom <code>ClientCredentialsAccessTokenProvider</code> added to the <code>OAuth2ResTemplate</code> that just adds some extra headers to the token request that are required by the OAuth provider I'm using.</p>

<p>In the spring-security 5 documentation I've found a section that mentions <a href="https://docs.spring.io/spring-security/site/docs/current/reference/html5/#customizing-the-access-token-request-3" rel="noreferrer">customising the token request</a>, but again that looks to be in the context of authenticating an incoming request with a 3rd party OAuth provider. It is not clear how you would use this in combination with something like a <code>ClientHttpRequestInterceptor</code> to ensure that each outgoing request to an external service first gets a token and then gets that added to the request. </p>

<p>Also in the migration guide linked above there is reference to a <code>OAuth2AuthorizedClientService</code> which it says is useful for using in interceptors, but again this looks like it relies on things like the <code>ClientRegistrationRepository</code> which seems to be where it maintains registrations for third party providers if you want to use that provide to ensure an incoming request is authenticated.</p>

<p>Is there any way I can make use of the new functionality in spring-security 5 for registering OAuth providers in order to get a token to add to outgoing requests from my application?</p>
