Token based authentication(oauth2) using RestHighLevelClient

stack-security
(Dhruvajyoti Chatterjee) #1

I have ES 7.0.0 with x-pack and an application using java RestHighLevelClient to connect to it. I am looking for way to setup token based authentication(oauth2) with this client but not able to find any API to set the token in the request after getting it. Can you please give an example (sample code) on how this can be achieved using RestHighLevelClient API.

(Ioannis Kakavas) #2

Hi there,

You can use RequestOptions to set any headers in the request (see here for an example that actually sets the Authorization header with Bearer <token_value> which is exactly what you want )