# Acquiring a Token using Advanced REST client

**URL:** https://discuss.elastic.co/t/acquiring-a-token-using-advanced-rest-client/163939
**Category:** Elasticsearch
**Created:** [January 11, 2019, 5:06pm UTC](https://discuss.elastic.co/t/acquiring-a-token-using-advanced-rest-client/163939 "2019-01-11T17:06:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)
#### Post date: [January 11, 2019, 5:06pm UTC](https://discuss.elastic.co/t/acquiring-a-token-using-advanced-rest-client/163939/1 "2019-01-11T17:06:19Z")

</div>

When using Advanced REST client to acquire a token, should I set authentication to basic, just to obtain the token, then my next request should be OAUTH2?

or do I start with OAUTH2 with the GRANT TYPE set to "password" or "client credentials"?

I am a bit confused.

---

<div class="post-metadata">

### Author: ![baz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/baz/32/5183_2.png) [@baz](https://discuss.elastic.co/u/baz)
#### Post date: [January 18, 2019, 3:18pm UTC](https://discuss.elastic.co/t/acquiring-a-token-using-advanced-rest-client/163939/2 "2019-01-18T15:18:13Z")

</div>

under the hood the `RestClient` just uses the [apache HttpAsyncClient](https://github.com/apache/httpasyncclient/blob/4.1.x/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java) for authentication. It would be best to look for answers on how to configure the credentials by looking at the `HttpAsyncClient` code. [Here](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html) is an example of how to do basic auth, but it will likely be different for configuring OAUTH.

---

<div class="post-metadata">

### Author: ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)
#### Post date: [January 18, 2019, 7:46pm UTC](https://discuss.elastic.co/t/acquiring-a-token-using-advanced-rest-client/163939/3 "2019-01-18T19:46:51Z")

</div>

Issue is resolved.

All the confusion started with me needing to upgrade my elastic instance.

---

<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: [February 15, 2019, 7:47pm UTC](https://discuss.elastic.co/t/acquiring-a-token-using-advanced-rest-client/163939/4 "2019-02-15T19:47:15Z")

</div>

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