Application API Documentation

POST /auth/bot

Parameters (name : type)

payload : string

Notes: You must AES Encrypt a JSON Object containing the fields token, deviceID, and timestamp. The key used to encrypt this payload will be the ENCRYPTION_KEY for your Kleidi Server.

Example
{
    deviceID: "some unique string value identifitying a device",
    key: "XXXXX-XXXXX-XXXXX-XXXXX",
    timestamp: 1577426056
}
POST /auth/bot/validate

Parameters (name : type)

payload : string

Notes: You must AES Encrypt a JSON Object containing the fields token, deviceID, and timestamp. The key used to encrypt this payload will be the ENCRYPTION_KEY for your Kleidi Server.

Example
{
    token: "asdfadsf",
    deviceID: "some unique string value identifitying a device",
    timestamp: 1577426056
}
POST /auth/bot/unlink

Parameters (name : type)

token : string

Notes: Authorization Key provided to the client (user).

POST /auth/bot/ban

Parameters (name : type)

key : string

Notes: Key of the user you desire to ban.

encrpytion_key : string

Notes: AES 256 Key for the server (ENCRYPTION_KEY).

Implementation (Node.JS)

import request from 'request';
import { machineIdSync } from 'node-machine-id';
import CryptoJS, { AES } from 'crypto-js';

const encryptData = (key, data) => {
    if (data == null || data === '') return null;
    return AES.encrypt(data, key).toString();
};

const decryptData = (key, data) => {
    if (data == null || data === '') return null;
    const decrypted = AES.decrypt(data, key);
    const text = decrypted.toString(CryptoJS.enc.Utf8);
    return text;
};

const ENCRYPTION_KEY = 'YOUR ENCRYPTION KEY GOES HERE';

const deviceID = machineIdSync();
const key = 'XXXXX-XXXXX-XXXXX-XXXXX';
let token = null;

const authReq = {
    deviceID: deviceID,
    key: key, /* Users assigned key */
    timestamp: Math.floor((new Date()).getTime() / 1000)
}

request({
    url: `https://domain.com/auth/bot`,
    method: 'post',
    json: true,
    form: {
        payload: encryptData(ENCRYPTION_KEY, JSON.stringify(authReq))
    }
}, (err, res, body) => {
    if (err) {
        return console.log('Request Error (Auth): ' + err);
    } else {
        if (res.statusCode == 200) {
            let responseDecrypted = null;
            try {
                responseDecrypted = JSON.parse(decryptData(ENCRYPTION_KEY, body));
                token = responseDecrypted.token;
                console.log(`Successful Response (Auth): ${JSON.stringify(responseDecrypted)}`);
                execValidateReq()
            } catch (e) {
                console.dir(e);
            }
        } else {
            console.error('Unsuccessful Request (Auth): ' + JSON.stringify(body));
        }
    }
});

let execValidateReq = () => {
    let validateReq = {
        token: token,
        deviceID: deviceID,
        timestamp: Math.floor((new Date()).getTime() / 1000)
    }
    
    request({
        url: `https://domain.com/auth/bot/validate`,
        method: 'post',
        json: true,
        form: {
            payload: encryptData(ENCRYPTION_KEY, JSON.stringify(validateReq))
        }
    }, (err, res, body) => {
        if (err) {
            return console.log('Request Error (Validate): ' + err);
        } else {
            if (res.statusCode == 200) {
                console.log(`Successful Response (Validate): ${JSON.stringify(body)}`);
                execUnlinkReq()
            } else {
                console.error('Unsuccessful Request (Validate): ' + JSON.stringify(body));
            }
        }
    });
}

let execUnlinkReq = () => {
    
    request({
        url: `https://domain.com/auth/bot/unlink`,
        method: 'post',
        json: true,
        form: {
            token: token
        }
    }, (err, res, body) => {
        if (err) {
            return console.log('Request Error (Unlink): ' + err);
        } else {
            if (res.statusCode == 200) {
                console.log(`Successful Response (Unlink): ${JSON.stringify(body)}`);
            } else {
                console.error('Unsuccessful Request (Unlink): ' + JSON.stringify(body));
            }
        }
    });
}

If you have any questions please feel free to email us or reach out on twitter