Bruno Lopes
Bruno Lopes

Reputation: 41

Authorization bearer token with NEST elasticsearch and C#

I've got a problem while trying to connect to an elasticsearch API. The API expect an bearer token, but the NEST lybrary only provides a basic authentication and I've got to pass a custom header as well. So, did anybody have to face this problem?? How to pass custom headers?!

Thanks

enter image description here

Upvotes: 1

Views: 2731

Answers (3)

Bruno Lopes
Bruno Lopes

Reputation: 41

Actually I was getting a mistaken concept. Actually I'm interacting with an API wich encapsolate the elasticsearch and just use the elasticsearch query sintax, so I didn't need to use NEST, the elasticsear package, to connect with it. And I just got to interact it with a simple http call.

Anyway, thanks Russ

Upvotes: 0

Russ Cam
Russ Cam

Reputation: 125528

You can add headers that should be added to all requests on ConnectionSettings

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool)
    .GlobalHeaders(new NameValueCollection 
    { 
        { "Authorization", "Bearer fnoi3nfion3fn00jr0j1r0" } 
    });

var client = new ElasticClient(connectionSettings);

Upvotes: 6

Ehsan Zargar Ershadi
Ehsan Zargar Ershadi

Reputation: 24843

you can add any header to your request:

req.Headers.Add("CustomeKey", CustomeData);

Upvotes: -1

Related Questions