In my server application, I want to consume some third party API using a MicroProfile REST client. To do so, I need to send an Authorization
Header with a bearer token.
I don't want to always get a token before I make any call so I need a mechanism to only retrieve a new token if there is no token yet or if the token expired. The token could then be stored and used in each call until it expires. The next call to the API which would cause a HTTP 401 Unauthorized shall then cause a new token to be obtained.
Unfortunately so far I wasn't able to find any resources on how to consume OAuth secured APIs using the MicroProfile REST client. I hope anybody can give me any tips. I'm using Kotlin and Quarkus but Java related documentation would be fine as well. Anything helps.
Here is my rather simple client:
@RegisterRestClient
@Produces(MediaType.APPLICATION_JSON)
interface SomeThirdPartyApiClient {
@POST
@Path("/some/random/url")
fun someRandomUrl(body: SomeJsonRequestObject, @HeaderParam("Authorization") bearer: String): SomeJsonResponseObject
}