Skip to main content

Third Party Login

With third party login, you can use the admin credentials to obtain a session id for a particular domain or user and use that id to login into that domain or user of the PBX from another webpage (URL) other than the PBX. That is very useful when you want to access a domain or user of the PBX through links from another site without having to enter the login credentials. The session id's can be obtained by the server from the PBX, and passed on to the front end of the server for authentication by the PBX.

Steps to setup a third party login.

  •     POST /rest/system/session HTTP/1.1
    Authorization: Basic base64encode(admin:password)
    Content-Type: application/json

    {
    name: "3rd",
    admin: true,
    domain: "domain.com"
    }

    OR

    {
    name: "3rd",
    domain: "domain.com"
    }

    OR

    {
    name: "3rd",
    username: "40",
    domain: "domain.com"
    }
  • This returns the session token to be used.

  • In the first example, where admin is true, the session id of the admin is returned.

  • In the second example, where there is no admin (or admin is false) and no username, the session id of the domain (e.g. domain.com) is returned.

  • In the third example, where username is 40, the session id of the extension (40) in domain (domain.com) is returned.

  • In the server, using curl, you will get a temporary session token for the domain or user (using the admin credentials as shown above) and pass it to your client in the browser.

  • Use that temporary token within 10 seconds as session id for PBX authentication as follows:

  • POST /rest/system/session HTTP/1.1
    Content-Type: application/json

    {
    name: "session",
    value: < session id passed from the server goes here >
    }
  • On successful response, you can enter the PBX with the URL:

https://YOUR_PBX_URL/thirdparty.htm
  • You should be able to get to the domain or user (for which the original temporary session id was obtained).

  • This is sample PHP code for implementing a AJAX handler on the server side that does the work:

// Make sure that this request is authenticated
// TBD by final implementation

// Set the trust parameters:
$url = 'http://pbx.xyz.com/rest/system/session';
$username = 'abc';
$password = 'def';

// Decode the input:
$body = json_decode(file_get_contents('php://input'));
$domain = $body->{'domain'};
$account = $body->{'account'};

// Send the request:
$body_string = json_encode(array('name' => '3rd', 'domain' => $domain, 'username' => $account));
$header = "Content-Type: application/json\r\nAuthorization: Basic " . base64_encode($username . ":" . $password) . "\r\nContent-Length: " . strlen($body_string) . "\r\n";
$result = file_get_contents($url, null,
stream_context_create(array('http' => array(
'method' => 'POST',
'header' => $header,
'content' => $body_string))));
print($result);
  • Below is a sample HTML form that uses the above script:

  • Make sure to name the above file which will be called in the below Script (For e.g 'thirdpartylogin.php' in this example).

<title>Vodia PBX 3rd party login</title><script>
<!--//--><![CDATA[// ><!--

function load() {
var form = document.getElementById('form');
var account = document.getElementById('account');
var domain = document.getElementById('domain');
function submit(e) {
e.preventDefault();
var xhr = new XMLHttpRequest();
xhr.open('POST', '/thirdpartylogin.php', true);
xhr.setRequestHeader("Content-Type", 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var session = JSON.parse(xhr.responseText);
document.location = 'https://pbx.xyz.com/welcome.htm?session=' + session;
}
};
var data = {
account: account.value,
domain: domain.value
};
xhr.send(JSON.stringify(data));
}
form.addEventListener('submit', submit);
}
window.addEventListener('load', load, false);

//--><!]]>
</script>

Account

Domain

The third party login directly into the domain or user portal should now be possible.