-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Per-Request Headers #631
Comments
You can add both a credential provider and a http request interceptor to the rest client: RestClient.builder(HttpHost.create("url"))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(elasticCredentialsProvider)
.addInterceptorFirst((HttpRequestInterceptor) (request, context) -> {
request.addHeader("Authorization", value);
})
)
.build(); Did you mean something else? |
My specific use case was the need to basically send a request "on behalf" of another user, not just using something like |
I have implemented Proxy authentication inside the interceptor before, that should work for you as well. It runs before every call to the Elastic cluster, so you can set custom headers and/or parameters for each call individually. |
We ended up going a different direction, so this wasn't specifically needed in the end. However, to the solution he provided; I think this would work for setting the JWT like I had mentioned. In our case I probably could have used Springs I understand Elasticsearch doesn't make much use of headers with its API so the example I gave may seem a bit weird, however there are cases where setting headers are required if let's say there is a proxy in-between you and Elasticsearch. |
Description
Currently I do not see a way to provide per-request headers anywhere in the API. This would be needed for things like JWT authorization documented here https://www.elastic.co/guide/en/elasticsearch/reference/current/jwt-auth-realm.html#hmac-oidc-example-request-headers
The only current solution it seems would be to re-build the entire client with every request which seems extremely wasteful.
The text was updated successfully, but these errors were encountered: