Skip to content

A-Zak/Colu-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Colu-node

Colu platform, PHP SDK

Install

Install Composer in your project:

    $curl -s http://getcomposer.org/installer | php

Create a composer.json file in your project root:

    {
        "require": {
            "Colu/Colu": "1.0.4"
        }
    }

Install via Composer

    $php composer.phar install

Generate keys for your company:

If 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();

Create instance from an existing key:

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);

Register a user using 2FA:

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);
  1. 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.

  1. 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 ID

save the userId for future verifications.

Verify user:

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.

About

Colu php SDK

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 82.1%
  • HTML 17.9%