-
-
Save rj93/388f45317c6513b83b12fb708042b992 to your computer and use it in GitHub Desktop.
Reddit WebClient Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class RedditConfig { | |
private static final String REDDIT_OAUTH2_REGISTRATION_ID = "reddit"; | |
private static final String REDDIT_BASE_URL = "https://oauth.reddit.com"; | |
@Bean(name = "redditWebClient") | |
public WebClient redditWebClient(ReactiveOAuth2AuthorizedClientManager reactiveOAuth2AuthorizedClientManager) { | |
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth2 = | |
new ServerOAuth2AuthorizedClientExchangeFilterFunction(reactiveOAuth2AuthorizedClientManager); | |
oauth2.setDefaultClientRegistrationId(REDDIT_OAUTH2_REGISTRATION_ID); | |
return WebClient.builder() | |
.baseUrl(REDDIT_BASE_URL) | |
.filter(oauth2) | |
.build(); | |
} | |
@Bean | |
public ReactiveOAuth2AuthorizedClientManager authorizedClientManager( | |
ReactiveClientRegistrationRepository clientRegistrationRepository, | |
ReactiveOAuth2AuthorizedClientService authorizedClientService) { | |
ReactiveOAuth2AuthorizedClientProvider authorizedClientProvider = | |
ReactiveOAuth2AuthorizedClientProviderBuilder.builder() | |
.clientCredentials() | |
.build(); | |
AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager authorizedClientManager = | |
new AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager( | |
clientRegistrationRepository, | |
authorizedClientService); | |
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider); | |
return authorizedClientManager; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment