This is the main configuration class in the client application, which is annotated with @EnableOAuth2Client, as shown in the following code snippet:
@Configuration
@EnableOAuth2Client
public class OAuthClientConfig {
@Autowired
private OAuth2ClientContext oauth2ClientContext;
@Autowired
@Qualifier("movieAppClientDetails")
private OAuth2ProtectedResourceDetails movieAppClientDetails;
@ConfigurationProperties(prefix = "security.oauth2.client.movie-app-client")
@Bean
public OAuth2ProtectedResourceDetails movieAppClientDetails() {
return new AuthorizationCodeResourceDetails();
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public OAuth2RestTemplate movieAppRestTemplate() {
return new OAuth2RestTemplate(movieAppClientDetails, oauth2ClientContext);
}
}
The important aspect to look at in this class is that we initialize the OAuth2 REST template by providing the client details, which are configured in the application.yml file.