Adding Token header in micronaut client request

1.7k Views Asked by At

In micronaut, I have a use case where i need to add the oauth2 access token as a custom header (not Header Name='Authorization) to every request.

Currently, i am fetching token and adding Authorization header to every request as specified by https://micronaut-projects.github.io/micronaut-security/latest/guide/#clientecredentialshttpclient. But i also have to add another header whose value is token to every outgoing request. So, I am using an HttpClientFilter to intercept the request, then read the Authorization Header, then add this custom header whose value is token. But this is causing concurrency issues. Sometimes ClientCredentialsHttpClientFilter is called after HttpClientFilter in which case i get null as token.

So, is there a way to ensure ClientCredentialsHttpClientFilter is called before HttpClientFilter?

EDIT:

All this works fine when I run through IDE. But does not run when I use native-image.

1

There are 1 best solutions below

1
On

The filter implements the Ordered interface.

Just override the getOrder() method and set the value according to your required order.