# Basic Authentication with cppRest-SDK(casablanca)

**URL:** <https://discuss.elastic.co/t/basic-authentication-with-cpprest-sdk-casablanca/220745>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [February 25, 2020, 1:13am UTC](https://discuss.elastic.co/t/basic-authentication-with-cpprest-sdk-casablanca/220745 "2020-02-25T01:13:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IC1101Galaxy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ic1101galaxy/32/61455_2.png) [@IC1101Galaxy](https://discuss.elastic.co/u/IC1101Galaxy)\
**Post date:** [February 25, 2020, 1:13am UTC](https://discuss.elastic.co/t/basic-authentication-with-cpprest-sdk-casablanca/220745/1 "2020-02-25T01:13:20Z")

</div>

I'd like to set a Basic Authentication with cppRest-sdk AKA casablanca for the security configuration to elastic-search cluster.

I've tried to do with header configuration such as following and it worked fine.

```
	http_client client(U("http://serverip:9200/"));
	http_request req(methods::GET);
	req.headers().add(L"Authorization", L"Basic ZWxhc3RpYzpwYXNzd29yZA==");

```

But I want to use cppRest-sdk's credentials configuration class such as these codes.

```
	http_client_config client_config;
	web::credentials cred(U("elastic"), U("password")); 
	client_config.set_credentials(cred);
	http_client client(U("http://serverip:9200/"), client_config);

```

I've debugged as much as I could but elastic-search cluster repeatly returns 401 error such as below.

> Resuest result :401{"error":{"header":{"WWW-Authenticate":"Basic realm="security" charset="UTF-8""},"reason":"missing authentication credentials for REST request [/]","root\_cause":[{"header":{"WWW-Authenticate":"Basic realm="security" charset="UTF-8""},"reason":"missing authentication credentials for REST request [/]","type":"security\_exception"}],"type":"security\_exception"},"status":401}

I've been searching for a quite long time but I couldn't find adequate answer because of lack of information of cppRest-SDK.  
Any advice would greatly appreciated.  
Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 24, 2020, 1:13am UTC](https://discuss.elastic.co/t/basic-authentication-with-cpprest-sdk-casablanca/220745/2 "2020-03-24T01:13:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
