Example #1
0
/**
 * Before the framework run.
 * 
 * @return void
 */
function hook_bootstrap()
{
    global $rublon, $config;
    // Create the Rublon object:
    require_once './extended/MyRublon.php';
    require_once './extended/MyCallback.php';
    $rublon = new MyRublon($config['rublon']['systemToken'], $config['rublon']['secretKey']);
    if (!empty($_GET['rublon']) and $_GET['rublon'] == 'callback') {
        // Rublon Callback URL
        try {
            $confirmResult = null;
            // Create instance of MyCallback which is the extended Rublon2FactorCallback class.
            $callback = new MyCallback($rublon);
            $callback->call(function ($userId, Rublon2FactorCallback $callback) use(&$confirmResult) {
                // <--- needed if this is a transaction confirmation.
                login_user($userId);
                $confirmResult = $callback->getCredentials()->getConfirmResult();
                // Save deviceId for remote logout:
                $response = $callback->getCredentials()->getResponse();
                // 					var_dump($response);exit;
                if (isset($response['result']['deviceId'])) {
                    $_SESSION['rublonDeviceId'] = $response['result']['deviceId'];
                }
            }, function (Rublon2FactorCallback $callback) {
                if (!empty($_GET['custom']) and $_GET['custom'] == 'confirm') {
                    die('canceled');
                } else {
                    redirect('./?rublon=cancel');
                }
            });
            if (!is_null($confirmResult)) {
                transaction_confirm_result($confirmResult == RublonAPICredentials::CONFIRM_RESULT_YES, $withRublon = true);
                exit;
            } else {
                redirect($config['websiteUrl'] . '?rublonLogin=success');
            }
        } catch (Exception $e) {
            // Remember to utilize your own error handler.
            if (!empty($_GET['error']) and $_GET['error'] == 'timeout') {
                die('timeout error');
            }
            var_dump(get_class($e));
            echo $e->getMessage();
            var_dump($e->getPrevious());
            exit;
        }
    }
}
Example #2
0
<?php

/**
 * Transaction confirmation logic.
 */
$user = $_SESSION['user'];
$transactionMessage = !empty($_POST['confirmMessage']) ? $_POST['confirmMessage'] : 'Please confirm transaction: ' . rand(1000, 9999);
// Create the Rublon auth URL
if ($timeBuffer = filter_input(INPUT_POST, 'buffer', FILTER_SANITIZE_NUMBER_INT)) {
    // Confirmation with time buffer
    $url = $rublon->confirmWithBuffer($config['rublon']['callbackURL'], $user['login'], $user['email'], $transactionMessage, $timeBuffer, $params = array(RublonAuthParams::FIELD_CUSTOM_URI_PARAM => 'confirm'));
} else {
    // Confirmation without time buffer
    $url = $rublon->confirm($config['rublon']['callbackURL'], $user['login'], $user['email'], $transactionMessage, $params = array(RublonAuthParams::FIELD_CUSTOM_URI_PARAM => 'confirm'));
}
if (!empty($url)) {
    // Redirect to the Rublon confirmation process:
    redirect($url);
} else {
    // Simply confirm the transaction:
    transaction_confirm_result($confirmResult = true, $withRublon = false);
    exit;
}