TokenChannel.io

TokenChannel.io

  • Pricing
  • API
  • FAQ
  • Signup | Login

›Libraries

API Documentation

  • What is TokenChannel?
  • API Overview
  • API Endpoints
  • Libraries

    • Intro
    • Node
    • Java

Java Libraries

Get your api key from the dashboard and write Java code to make HTTP requests to the TokenChannel API.

Java 8 Sync Client

Add Java 8 TokenChannel library as a dependency to your project.

<dependency>
  <groupId>io.tokenchannel</groupId>
  <artifactId>tokenchannel-java</artifactId>
  <version>0.14.0.RELEASE</version>
</dependency>

Build a TokenChannel client instance given a TokenChannelProperties instance and a Gson instance:

TokenChannel client = new TokenChannel(tokenChannelProperties, gson);

Challenge creation

ChannelType channel = ChannelType.EMAIL; // Channel.SMS or Channel.VOICE or Channel.WHATSAPP
String identifier = 'info@tokenchannel.io'; // '+14155552671'
ChallengeResponse challengeRequest = 
    tokenChannel.challenge(channel, identifier,
        ChallengeOptions.builder()
            .language("de")
            .charset(CodeCharSet.DEC)
            .expirationInMinutes(5)
            .codeLength(6)
            .test(true) // enables test
            .build());

Authenticate token

AuthenticateResponse authResponse = tokenChannel.authenticate(requestId, validationCode);

Retrieve validation code for Test Challenge

TestResponse testResponse = tokenChannel.getValidationCodeByTestChallengeId(requestId);

Get supported countries

List<String> countries = tokenChannel.getSupportedCountries();

Get supported languages

List<String> languages = tokenChannel.getSupportedLanguages();

Get SMS prices

List<SMSPriceItem> smsPrices = tokenChannel.getSMSPrices();

Get Voice call prices

List<VoicePriceItem> voiceCallPrices = tokenChannel.getVoicePrices();

Get Whatsapp prices

List<WhatsappPriceItem> smsPrices = tokenChannel.getWhatsappPrices();

Java 11 Async Client

Add Java 11 TokenChannel library as a dependency to your project.

<dependency>
  <groupId>io.tokenchannel</groupId>
  <artifactId>tokenchannel-java11</artifactId>
  <version>0.14.0.RELEASE</version>
</dependency>

Build a TokenChannel client instance given a TokenChannelProperties instance and a Gson instance:

TokenChannel client = new TokenChannel(tokenChannelProperties, gson);

Challenge creation

ChannelType channel = ChannelType.EMAIL; // Channel.SMS or Channel.VOICE
String identifier = 'info@tokenchannel.io'; // '+14155552671'
CompletableFuture<ChallengeResponse> challengeRequest = 
    tokenChannel.challenge(channel, identifier,
        ChallengeOptions.builder()
            .language("de")
            .charset(CodeCharSet.DEC)
            .expirationInMinutes(5)
            .codeLength(6)
            .test(true) // enables test
            .build());

Authenticate token

CompletableFuture<AuthenticateResponse> authResponse = tokenChannel.authenticate(requestId, validationCode);

Retrieve validation code for Test Challenge

CompletableFuture<TestResponse> testResponse = tokenChannel.getValidationCodeByTestChallengeId(requestId);

Get supported countries

CompletableFuture<List<String>> countries = tokenChannel.getSupportedCountries();

Get supported languages

CompletableFuture<List<String>> languages = tokenChannel.getSupportedLanguages();

Get SMS prices

CompletableFuture<List<SMSPriceItem>> smsPrices = tokenChannel.getSMSPrices();

Get Voice call prices

CompletableFuture<List<VoicePriceItem>> voiceCallPrices = tokenChannel.getVoicePrices();

Get Whatsapp prices

CompletableFuture<List<WhatsappPriceItem>> smsPrices = tokenChannel.getWhatsappPrices();

Using TokenChannel in Spring Boot

TokenChannel Spring Boot Starter dependency

Add one of our TokenChannel Spring Boot starter dependencies into your Spring Boot project. Two options available: sync java 8 client and async java 11 client.

Java 8 Spring BOOT starter installation

<dependency>
  <groupId>io.tokenchannel</groupId>
  <artifactId>tokenchannel-java-starter</artifactId>
  <version>0.14.0.RELEASE</version>
</dependency>

Java 11 Spring BOOT starter installation

<dependency>
  <groupId>io.tokenchannel</groupId>
  <artifactId>tokenchannel-java11-starter</artifactId>
  <version>0.14.0.RELEASE</version>
</dependency>

Set up TokenChannel client

Set your api key in application.properties file and optionally enable test mode:

tokenchannel.apiKey='TCk-onutLwE3Os9tuJVCDw7UGm3A98rHva6Rz3gQ'
tokenchannel.test=true 

Now you will have a TokenChannel instance ready to be injected in your code.

Challenge

ChannelType channel = ChannelType.EMAIL; // Channel.SMS or Channel.VOICE
String identifier = 'info@tokenchannel.io'; // '+14155552671'
ChallengeResponse response = tokenChannel.challenge(channel, identifier,
                ChallengeOptions.builder()
                .language("de")
                .charset(CodeCharSet.DEC)
                .codeLength(6)
                .build());

Authenticate

boolean keepGoing = true;
do {

    System.out.print("Confirm your validation code: ");
    String validationCode = System.console().readLine();
    try {
        tokenChannel.authenticate(response.getRequestId(), validationCode);
        log.info("Challenge succeed!");
        keepGoing = false;
    } catch (InvalidCodeException e) {
        log.info("Invalid code. Try again.");
    } catch (MaxAttemptsExceededException e) {
        log.info("Two many attempts. BYE!");
        keepGoing = false;
    } catch (ChallengeClosedException | ChallengeExpiredException | ChallengeNotFound e) {
        log.info("You should create a new challenge!");
        keepGoing = false;
    }
} while (keepGoing);

Retrieve validation code for a Test Challenge

TestResponse testResponse = tokenchannel.getValidationCodeByTestChallengeId(requestId);

Retrieve supported countries and languages

log.info("TokenChannel Supported Countries: {}", tokenChannel.getSupportedCountries().toString());
log.info("TokenChannel Supported Languages: {}", tokenChannel.getSupportedLanguages().toString());
← Node
  • Java 8 Sync Client
    • Challenge creation
    • Authenticate token
    • Retrieve validation code for Test Challenge
    • Get supported countries
    • Get supported languages
    • Get SMS prices
    • Get Voice call prices
    • Get Whatsapp prices
  • Java 11 Async Client
    • Challenge creation
    • Authenticate token
    • Retrieve validation code for Test Challenge
    • Get supported countries
    • Get supported languages
    • Get SMS prices
    • Get Voice call prices
    • Get Whatsapp prices
  • Using TokenChannel in Spring Boot
    • TokenChannel Spring Boot Starter dependency
    • Set up TokenChannel client
TokenChannel.io
General
PricingAPI DocsFAQAbout
Legal
Privacy policyCookie policyTerms of serviceData Processing Agreement
More
API Status
Medium channelMedium
Youtube channel
Star on GitHub
Follow @TokenChannel_io
Copyright © 2020 Neivi Innovación Tecnológica, S.L.