SIGN UP

Automated Voximplant SDK login

Automated Voximplant SDK login

There are some cases when you need to login users into web phone automatically, but don't want plain text password (that is accepted by VoxImplant.getInstance().login()) to be available in JavaScript code.

We have a solution for this problem. Let's assume that you need to login user named myuser to application myapp in your Voximplant account named myaccount, and that user has password mypass.

  1. Add handler for AuthResult event.
  2. Request one-time authentication login key using requestOneTimeLoginKey function.
  3. Calculate token with on your backend
    MD5(`${login_key}|${MD5(`${myuser}:voximplant.com:${mypass}`)`)

    PLEASE NOTICE that myuser doesn’t include @appname.accname.voximplant.com 

  4. Send this token using loginWithOneTimeKey function
  5. Finally you should receive AuthResult with result == true if correct password was specified.

Example:

//app.js on client
// Please, change this data before go.
const appUser = 'APPLICATIONUSER';
const appUserPassword = 'SECUREPASSWORD';
const appName = 'VOXAPPLICATION';
const account = 'ACCOUNT';
const URI = `${appUser}@${appName}.${account}.voximplant.com`;
//Request key from server
VoxImplant.getInstance().requestOneTimeLoginKey(URI);
//Listen server response
VoxImplant.getInstance().addEventListener(VoxImplant.Events.AuthResult, e => {
  log(`AuthResult: ${e.result}`);
  if (e.result) {
    //Login successful
  } else {
    if (e.code == 302) {
      //IMPORTANT: You should always calculate the token on your backend!
      $.post('/calckey/', {
        key: e.key
      }, token => {
        VoxImplant.getInstance().loginWithOneTimeKey(URI, token);
      }, 'text');
    }
  }
});

 

Example backend function PHP:

echo md5($_REQUEST['key'].'|'.md5($myuser.':voximplant.com:'.$mypass));

 

Ruby:

require 'digest/md5' concat Digest::MD5.hexdigest(request.POST['key']+'|'+Digest::MD5.hexdigest(myuser+":voximplant.com:"+mypass))

 

Node.js:

var md5 = crypto.createHash('md5');
response.writeHead(200, {"Content-Type": "text/plain"});
response.end(md5(`${request.body.key}|${md5(`${myuser}:voximplant.com:${mypass}`)`);

 

Java(Spring):

@RestController
@EnableAutoConfiguration
public class StartPoint {
  private static final String login = "";
  private static final String pass = "";
  private static final String HASH;
  static {
    HASH = DigestUtils.md5DigestAsHex((login + ":voximplant.com:" + pass).getBytes());
  }
  @RequestMapping("/hash/{login}")
  public String getHash(@PathVariable String login) {
    String key = login + "|" + HASH;
    return DigestUtils.md5DigestAsHex(key.getBytes());
  }
  public static void main(String[] args) {
    SpringApplication.run(StartPoint.class, args);
  }
}
Tags:ios sdkweb sdkandroid sdk
B6A24216-9891-45D1-9D1D-E7359CEB8282 Created with sketchtool.

Answers(0)

Add your comment

Please complete this field.

Recommended

Get your free developer account or talk with our sales team to learn more about Voximplant solutions
SIGN UP