1

Is there out of box support to use OAuth2 based Bearer token with Apache HttpClient? I know we can just pass it in headers, but my worry is to handle token such that it is re fetched before it expires.

MyStackRunnethOver
  • 4,872
  • 2
  • 28
  • 42
Jogger
  • 397
  • 5
  • 15

1 Answers1

1

Not sure with Apache HttpClient, but if you're using SpringBoot there is OAuth2RestTemplate which automates everything with bearer tokens

stream28
  • 141
  • 6
  • Thanks @stream28 for suggesting that. Actually I am in doubt whether to use it after reading it's doc that RestTemplate will be deprecated in future. This is the Note from RestTemplate doc: " The RestTemplate will be deprecated in a future version and will not have major new features added going forward. See the WebClient section of the Spring Framework reference documentation for more details and example code. " – Jogger Feb 28 '20 at 05:51
  • Update: Now I am successfully using Spring WebClient (as it is the recommended approach) to post requests with OOTB OAuth2 support. There is one Stackoverflow post suggesting the same https://stackoverflow.com/a/59247804/2806640 – Jogger Mar 01 '20 at 20:09