> For the complete documentation index, see [llms.txt](https://docs.amitysolutions.com/ekoai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.amitysolutions.com/ekoai/api-reference/botv2/bot-authorization.md).

# Bot Authorization

**After created a bot profile, you’ll also need to provide a random string generated from Admin Panel to use for OAuth service. After the authentication succeeds an access token will be provided.**

On node.JS, the authentication algorithm looks like this

```js-templates
const ClientOAuth2 = require('client-oauth2');

const ekoAuth = new ClientOAuth2({
  clientId: process.env.EKO_OAUTH_CLIENT_ID,
  clientSecret: process.env.EKO_OAUTH_CLIENT_SECRET,
  accessTokenUri: `${process.env.EKO_HTTP_URI}/oauth/token`, //Eko HTTP server uri
  scopes: ['bot'],
});

const authenticate = async () => {
  const { data } = await ekoAuth.credentials.getToken();
  app.set('token', data); //returned access token
};
```

## OAuth Parameter

| Name           | Type   | Description                   |
| -------------- | ------ | ----------------------------- |
| clientId       | String | Random string specific to bot |
| clientSecret   | String | Random string specific to bot |
| accessTokenUri | String | Eko http server uri           |

{% hint style="info" %}
The *access token* will be generated when the bot is successfully authorized.
{% endhint %}

**Response**

```
{
    "access_token": "eyJ0eXA...",
    "token_type": "Bearer",
    "expires_in": 1209599,
    "scope": "bot profile"
}
```

#### cURL

```
curl --location '<EKO_HTTP_URI>/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic <Base64(EKO_OAUTH_CLIENT_ID:EKO_OAUTH_CLIENT_SECRET)>' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=bot profile'
```

## Add the access token to your request

```
headers: {
    Authorization: `Bearer ${ekoAPIKey}`,
},
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.amitysolutions.com/ekoai/api-reference/botv2/bot-authorization.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
