@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Import(value=OAuth2ClientConfiguration.class) public @interface EnableOAuth2Client
DelegatingFilterProxy
that delegates to a bean named
"oauth2ClientContextFilter". Once that filter is in place your client app can use another bean provided by this
annotation (an AccessTokenRequest
) to create an OAuth2RestTemplate
, e.g.
@Configuration @EnableOAuth2Client public class RemoteResourceConfiguration { @Bean public OAuth2RestOperations restTemplate(OAuth2ClientContext oauth2ClientContext) { return new OAuth2RestTemplate(remote(), oauth2ClientContext); } }Client apps that use client credentials grants do not need the AccessTokenRequest or the scoped RestOperations (the state is global for the app), but they should still use the filter to trigger the OAuth2RestOperations to obtain a token when necessary. Apps that use password grants need to set the authentication properties in the OAuth2ProtectedResourceDetails before using the RestOperations, and this means the resource details themselves also have to be per session (assuming there are multiple users in the system).
Copyright © 2019. All rights reserved.