Automated 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:

  1. //app.js on client
  2. //Request key from server
  3. VoxImplant.getInstance().requestOneTimeLoginKey("myuser@myapp.myaccount.voximplant.com");
  4.  
  5. function onAuthResult(e) {
  6. log("AuthResult: "+e.result);
  7. if (e.result) {
  8. //Login successful
  9. } else {
  10. if (e.code == 302){
  11. //IMPORTANT: You should always calculate the token on your backend!
  12. $.post('/calckey/',{"key":e.key},function(token){
  13. VoxImplant.getInstance().loginWithOneTimeKey("myuser@myapp.myaccount.voximplant.com", token);
  14. },'text');
  15. }
  16. }
  17. }
  18. //Listen server response
  19. VoxImplant.getInstance().addEventListener(VoxImplant.Events.AuthResult, onAuthResult);

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:

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

Java(Spring):

  1. @RestController
  2. @EnableAutoConfiguration
  3. public class StartPoint {
  4. private static final String login = "";
  5. private static final String pass = "";
  6. private static final String HASH;
  7. static {
  8. HASH = DigestUtils.md5DigestAsHex((login + ":voximplant.com:" + pass).getBytes());
  9. }
  10. @RequestMapping("/hash/{login}")
  11. public String getHash(@PathVariable String login) {
  12. String key = login + "|" + HASH;
  13. return DigestUtils.md5DigestAsHex(key.getBytes());
  14. }
  15. public static void main(String[] args) {
  16. SpringApplication.run(StartPoint.class, args);
  17. }
  18. }