I used below code to set the authorization when my service connects to some other service via feign Client.
@Bean
public RequestInterceptor requestInterceptor() {
return new OAuth2AccessTokenInterceptor(APP_INNER_ACCESS_CREDENTIAL, oAuth2AuthorizedClientManager);}
It works fine and generates and sends the token when we hit the API from bowser/swagger etc. But when I trigger the API as a cron job as it is not a HTTPRequest, this call fails with below ERROR
ERROR DETAILS
java.lang.IllegalArgumentException: servletRequest cannot be null at .springframework.util.Assert.notNull(Assert.java:172) ~[spring-core-6.1.4.jar:6.1.4] at .springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager.authorize(DefaultOAuth2AuthorizedClientManager.java:144)
Any alternate way to solve this?