Skip to content

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

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
};
Name Type Description
clientId String Random string specific to bot
clientSecret String Random string specific to bot
accessTokenUri String Eko http server uri

Response

{
"access_token": "eyJ0eXA...",
"token_type": "Bearer",
"expires_in": 1209599,
"scope": "bot profile"
}
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'
headers: {
Authorization: `Bearer ${ekoAPIKey}`,
},