Here is an SSO example for the index.php and multipass.php files you will need for the SSO to work. Also we offer the editor in multiple languages, see below the available languages and how to start the editor in a certain language.
Please note that YOUR_CLIENT_ID, YOUR_SECRET and YOUR_WL_DASHBOARD_DOMAIN need to be replaced with the values of your dashboard domain, your client ID and your secret that you will get from us once you join our reseller program.
index.php
<?php
use App\Multipass;
require ('Multipass.php');
const PUBLIC_PARTNER_ID = YOUR_CLIENT_ID;
const SECRET_KEY = YOUR_SECRET;
// Your customer email from the session
function getCustomerEmail()
{
return 'client@example.cloud';
}
function getToken()
{
date_default_timezone_set("UTC");
return (new Multipass(SECRET_KEY))->encode([
'created_at' => (new \DateTime())->format(\DateTime::ISO8601),
'email' => getCustomerEmail(),
project_uid: {Project.uid}
]);
}
$redirect_url = 'https://YOUR_WL_DASHBOARD_DOMAIN/multipass/' . PUBLIC_PARTNER_ID . '?token=' . getToken();
header("Location: $redirect_url");
exit;
Multipass.php
<?php
namespace App;
class Multipass {
private $signature_key;
private $encryption_key;
private $init_vector;
public function __construct($secret_key)
{
$key_material = hash("SHA256", $secret_key, true);
$this->encryption_key = substr($key_material, 0, 16);
$this->signature_key = substr($key_material, 16, 16);
$iv_material = hash("SHA256", $this->encryption_key, true);
$this->init_vector = substr($iv_material, 0, 16);
}
/**
* Converts and signs a PHP object or array into a JWT string.
*
* @param object|array $payload PHP object or array
*
* @return string A signed JWT
*
* @uses jsonEncode
* @uses urlsafeB64Encode
*/
public function encode($payload)
{
$segments = array();
$segments[] = $this->urlsafeB64Encode($this->encrypt(json_encode($payload), $this->encryption_key, $this->init_vector));
$signing_input = implode('.', $segments);
$signature = $this->sign($signing_input, $this->signature_key);
$segments[] = $this->urlsafeB64Encode($signature);
return implode('.', $segments);
}
/**
* Sign a string with a given key and algorithm.
*
* @param string $msg The message to sign
* @param string|resource $key The secret key
*
* @return string An encrypted message
*
*/
private function sign($msg, $key)
{
return hash_hmac('SHA256', $msg, $key, true);
}
/**
* Encode a string with URL-safe Base64.
*
* @param string $input The string you want encoded
*
* @return string The base64 encode of what you passed in
*/
private function urlsafeB64Encode($input)
{
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
/**
* Encrypt a string with AES-128-CBC
*
* @param string $json_payload The data
* @param string $encryption_key The secret encryption key
* @param string $init_vector A non-NULL Initialization Vector
*
* @return string An encrypted data
*/
private function encrypt($json_payload, $encryption_key, $init_vector)
{
return openssl_encrypt($json_payload, 'AES-128-CBC' , $encryption_key, OPENSSL_RAW_DATA, $init_vector);
}
}
To start the editor in a specific language your $redirect URL will look like this:
https://[your-white-label-dashboard-domain]/multipass/{partnerId}?token={token}&_lang=en
Here are all the available languages:
[ 'name' => 'English', 'code' => 'en' ], [ 'name' => 'Deutsch', 'code' => 'de' ], [ 'name' => 'Français', 'code' => 'fr' ], [ 'name' => 'Italiano', 'code' => 'it' ], [ 'name' => 'Español', 'code' => 'es' ], [ 'name' => 'Nederlands', 'code' => 'nl' ], [ 'name' => 'Português', 'code' => 'pt' ], [ 'name' => 'Danish', 'code' => 'da' ], [ 'name' => 'Русский', 'code' => 'ru' ], [ 'name' => 'عربي', 'code' => 'ar' ], [ 'name' => '日本語', 'code' => 'ja' ], [ 'name' => 'Polski', 'code' => 'pl' ], [ 'name' => 'Română', 'code' => 'ro' ], [ 'name' => 'Turkish', 'code' => 'tr' ], [ 'name' => 'Українська', 'code' => 'uk' ], [ 'name' => 'Svenska', 'code' => 'sv' ], [ 'name' => 'Norsk', 'code' => 'no' ],