Colu platform, PHP SDK
Install Composer in your project:
$curl -s http://getcomposer.org/installer | phpCreate a composer.json file in your project root:
{
"require": {
"Colu/Colu": "1.0.4"
}
}
Install via Composer
$php composer.phar installIf you create an instance of the Colu class with only the company name, the privateKey will be generated randomly on your machine.
Your privateKey is what defines your company.
require_once ('vendor/autoload.php');
use Colu\ColuSDK\Colu;
$colu = new Colu('my_company', 'testnet');
// This is your private key, keep it safe!!!
echo 'WIF: '.$colu->getWIF();When you want to use our module in your server you need to generate keys only once. After that you can create an instance of Colu with your key:
require_once ('vendor/autoload.php');
use Colu\ColuSDK\Colu;
$privateKey = 'cQQy71GeXGeFWnDtypas2roY2qrk3KWjJLCxoFqc2wibXr2wWxie'; // this is the WIF version of a private key
$colu = new Colu('my_company', 'testnet', $privateKey);There are two methods for registering a user using 2FA, directly by using a Phonenumber or by generating a QR code and then having the user scan the QR with their phone.
In both methods you need to Create a registration message:
$username = 'bob';
$registrationMessage = $colu->createRegistrationMessage($username);- QR registration:
$qr = $colu->createRegistrationQR($registrationMessage);This will return an array containing the QR and the message to be verified:
"qr" => $qrCode->getDataUri (), // this is the actual QR image
"code" => $qrRegCode, // send this to the registerUserByCode function
"message" => $message // send this to the registerUserByCode function Send the registration request:
$colu->registerUserByCode ( $code, $message );This will send a push notification to the user mobile application that will wait until approval is recieved.
- Phonenumber Registration:
$phonenumber = "+12323455673";
$colu->registerUserByPhonenumber ( $phonenumber, $registrationMessage );This will send a push notification to the user mobile application that will wait until approval is recieved.
If successful both cases return an array:
"success" => true,
"userId" => $user->getId () // this is the user IDsave the userId for future verifications.
To verify a user:
$username = 'bob';
$userId = 'tpubDCgCu2jpxrR7j9JwFQ959wSkNwPQFNQvJJMFnikg1Sb4tkDnBNYaS3Sc1BxKL71hk3jPkQStEY1VE9mTaQjF8kDfEhzxjWid7eVK5F7nWi5';
if ($colu->verifyUser($username, $userId, 0)) {
echo "verified";
}
else {
echo $colu->error;
// something bad happened
}
}This will send a push to the user mobile application and prompt him to sign on your message, you will receive the user signature and verify it locally.