TokenChannel.io Official Javascript/Typescript library
This is the official Javascript/Typescript Library for TokenChannel.io.
Library Usage
Remember that in order to start using TokenChannel.io API, you will need to register an account at https://tokenchannel.io and get an API KEY.
Installation
npm install tokenchannel
Usage Example
Challenge Creation:
const apiKey = 'TCk-EjyljGEI032PiREvOJiN9g9RjPYUDWZWxhXE';
const client = new Tokenchannel(apiKey);
try {
const channel = Channel.SMS;
const identifier = '+14155552671';
const {requestId} = await client.challenge(channel, identifier);
console.log("RequestId: ", requestId);
} catch (error) {
if (error instanceof TargetOptOutError) {
} else if(error instanceof InvalidIdentifierError) {
} else if(error instanceof OutOfBalanceError) {
} else {
}
}
Challenge Authentication
let authCode = '123456';
try {
const {channel, identifier} = await client.authenticate(requestId, authCode);
console.log(`Challenge successfully passed: ${identifier} in ${channel}`);
} catch (error) {
if (error instanceof InvalidCodeError || error instanceof BadRequestError) {
console.log("Invalid code");
} else if (error instanceof ChallengeExpiredError || error instanceof ChallengeClosedError
|| error instanceof ChallengeNotFoundError || error instanceof MaxAttemptsExceededError) {
console.log("Create a new challenge");
} else {
console.log("Error: ", error.message);
}
}
Execute Example
node dist/example/example.js challenge PUSHOVER <userId>