Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tokenchannel

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tokenchannel

README.md

  • 0.10.0
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by600%
Maintainers
1
Weekly downloads
 
Created
Source

TokenChannel TokenChannel.io Official Javascript/Typescript library

license npm type definitions npm version

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); // new Tokenchannel(apiKey, true) whether test mode is enabled for every challenge
try {
    const channel = Channel.SMS;
    const identifier = '+14155552671'; // E164

    const {requestId} = await client.challenge(channel, identifier);
    console.log("RequestId: ", requestId);
} catch (error) {
  if (error instanceof TargetOptOutError) {
        // handleCustomerOptOut()
  } else if(error instanceof  InvalidIdentifierError) {
        // handleInvalidIdentifier()  
  } else if(error instanceof  OutOfBalanceError) {
        // handleOutOfBalanceError()
  } else {
        // handleError() 
  }
}
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 {
        // Handle Unexpected
        console.log("Error: ", error.message);
    }
}
Execute Example
node dist/example/example.js challenge PUSHOVER <userId>

Keywords

FAQs

Package last updated on 08 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc