# 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           |

:::note
The *access token* will be generated when the bot is successfully authorized.
:::

**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}`,
},
```
