• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Company · Blog · Newsletter · Events · Partner Program

Downloads      Support      Security     Admin Login
Rublon

Rublon

Secure Remote Access

  • Product
    • Regulatory Compliance
    • Use Cases
    • Rublon Reviews
    • Authentication Basics
    • What is MFA?
    • Importance of MFA
    • User Experience
    • Authentication Methods
    • Rublon Authenticator
    • Remembered Devices
    • Logs
    • Single Sign-On
    • Access Policies
    • Directory Sync
  • Solutions
    • MFA for Remote Desktop
    • MFA for Remote Access Software
    • MFA for Windows Logon
    • MFA for Linux
    • MFA for Active Directory
    • MFA for LDAP
    • MFA for RADIUS
    • MFA for SAML
    • MFA for RemoteApp
    • MFA for Workgroup Accounts
    • MFA for Entra ID
  • Customers
  • Industries
    • Financial Services
    • Investment Funds
    • Retail
    • Technology
    • Healthcare
    • Legal
    • Education
    • Government
  • Pricing
  • Docs
Contact Sales Free Trial

Rublon PHP SDK: Secure PHP Apps with MFA

October 9, 2024 By Rublon Authors

Last updated on July 8, 2025

Overview

The Rublon PHP SDK library is a client-side implementation of the Rublon API written in PHP. The library includes methods for embedding the Rublon API’s GUI in an HTML-based environment. The Rublon PHP SDK forms a convenient PHP coding language facade for Rublon API’s REST interface.

Use Cases

Rublon adds an extra layer of security by prompting the user to authenticate using an extra authentication method such as Mobile Push. Even if a malicious actor compromises the user’s password, the hacker would not be able to log in to the user’s account because the second secure factor will thwart them.

Rublon can add an extra layer of security in the following two use cases:

  1. When a user signs in to a system (after the user enters the correct password)
  2. When a user undergoes a security-sensitive transaction (such as changing the password or conducting a money transfer)

When a user signs in to a system, the second authentication factor should be initiated only after:

  • the user has successfully completed the first authentication factor (e.g., entered the correct password)
  • the user’s unique username and email address have been gathered

Supported Authentication Methods

Authentication Method Supported Comments
Mobile Push ✔ N/A
WebAuthn/U2F Security Key ✔ N/A
Passcode ✔ N/A
SMS Passcode ✔ N/A
SMS Link ✔ N/A
Phone Call ✔ N/A
QR Code ✔ N/A
Email Link ✔ N/A
YubiKey OTP Security Key ✔ N/A

Before You Start

Before you start implementing the Rublon PHP SDK library into your code, you must create an application in the Rublon Admin Console. We also recommend that you install the Rublon Authenticator mobile app for Mobile Push, Mobile Passcode, and QR Code authentication methods.

Get the SDK

Download the Rublon PHP SDK.

Create an Application in the Rublon Admin Console

  1. Sign up for the Rublon Admin Console. Here’s how.
  2. In the Rublon Admin Console, go to the Applications tab and click Add Application.
  3. Enter a name for your application and then set the type to Custom integration using PHP SDK.
  4. Click Save to add the new PHP SDK application in the Rublon Admin Console.
  5. Copy and save the values of System Token and Secret Key. You are going to need these values later.

Optional: Install Rublon Authenticator

For increased security of Multi-Factor Authentication (MFA), end-users are recommended to install the Rublon Authenticator mobile app.

Download the Rublon Authenticator for:

  • Android
  • iOS
  • HarmonyOS

After installing the mobile app, users can authenticate using the following authentication methods:

  • Mobile Push
  • Mobile Passcode
  • QR Code

In some cases, users may not want to install any additional apps on their phones. Also, some users own older phones that do not support modern mobile applications. These users can authenticate using one of the following authentication methods instead:

  • WebAuthn/U2F Security Keys
  • SMS Passcode
  • SMS Link
  • Email Link
  • WebAuthn/U2F Security Keys
  • YubiKey OTP

Configuration

Follow the steps below to configure Rublon PHP SDK.

INFO: Initial Assumptions

Let’s assume there is a superglobal session associative array $_SESSION. It has access to an object that stores the user data of the currently logged-in user.

The $_SESSION array will be used in PHP code examples later in this document.

INFO: Modifying the Library

The Rublon class implements a few public methods, which, when needed, can be overridden using class inheritance.

We strongly discourage you from modifying any part of the library, as it usually leads to difficulties during library updates. If you need to change the flow or internal structure of the Rublon or RublonCallback classes, do not hesitate to subclass them according to your needs.

Initialize the Library

To initialize the Rublon PHP SDK library, you need to instantiate a Rublon class object. Its constructor takes three arguments.

Rublon class constructor arguments:

NameTypeDescription
$systemTokenstringThe System Token value you copied from the Rublon Admin Console.
$secretKeystringThe Secret Key value you copied from the Rublon Admin Console.
$apiServerstringRublon API Server URIDefault: https://core.rublon.net

Example PHP Code

  require_once "libs/Rublon/Rublon.php";

  $rublon = new Rublon(
     "D166A6E9996A40F0A88252432FA5E490",
     "913eda929c96cf52141b39f5717e25",
     "https://core.rublon.net"
  );

Perform Authentication

The Rublon::auth() method uses the username to check the user’s protection status and returns a URL address the user should be redirected to in their web browser.

Rublon::auth() method arguments:

NameTypeDescription
$callbackUrlstringThe integrated system’s callback URL.Rublon will redirect the user to this URL after successful authentication.
$usernamestringThe user’s username, which allows the user to sign in
$userEmailstringThe user’s email address, which allows to check the user’s protection status and match the user to a Rublon account
$paramsarrayAdditional transaction parameters (optional)
$isPasswordlessbooleanWhether the sign-in attempt is passwordless (optional and false by default)

Example PHP Code

    /**
     * An example method used to log the user in (integrated system's method)
     *
     * @param string $login
     * @param string $password
     */
    function login($login, $password) {
        if (loginPreListener()) {
            if ($user = authenticate($login, $password)) {
                // The user has been authenticated.
                $_SESSION["user"] = $user;
                loginPostListener();
            }
        }
    }

    /**
     * Listener (hook) invoked after a successful first factor user authentication,
     * implemented for Rublon integration purposes.
     */
    function loginPostListener() {
        // Make sure that the user is not logged-in
        unset($_SESSION['user']);

        $rublon = new Rublon(
            "D166A6E9996A40F0A88252432FA5E490",
            "913eda929c96cf52141b39f5717e25",
            "https://core.rublon.net"
        );

        try { // Initiate a Rublon authentication transaction
            $authUrl = $rublon->auth(
                $callbackUrl = "https://example.com?rublon=callback",
                $_SESSION["user"]["login"], // Username
                $_SESSION["user"]["email"] // User email
            );

            if (!empty($authUrl)) { // User protection is active
                // Redirect the user's web browser to Rublon servers to verify the protection:
                header('Location: ' . $authUrl);
            } else {
                // User is not protected by Rublon, so bypass the second factor.
                header('Location: index.php');
            }
        } catch (UserDeniedException $e) {
            // Access Denied
            header('Location: ./');
        } catch (UserBypassedException $e) {
            // User bypassed
            header('Location: ./');
        } catch (RublonException $e) {
            // An error occurred
            die($e->getMessage());
        }
    }

Note: Make sure that your code checks that the user is not signed in. The user should be signed in only after successful Rublon authentication.

Verify Configuration

The Rublon::checkApplication() method verifies the validity of the configuration. Your application should call this method every time you change or save the configuration. A configuration change can be, for example, changing the systemToken or secretKey.

Rublon::checkApplication() method arguments:

NameTypeDescription
appVerstringThe version of the current application.
paramsarrayOptional.
Additional application parameters.

Rublon::checkApplication() may throw one of the following exceptions:

  • ApplicationNotFoundException – Invalid System Token
  • InvalidSignatureException – Invalid Secret Key
  • UnsupportedVersionException – Incorrect version of the application

Finalize Authentication

After successful authentication, Rublon redirects the user to the callback URL. The callback flow continues and finalizes the authentication process.

Input Params

The callback URL will receive input arguments in the URL address itself (query string).

Callback URL arguments:

NameTypeDescription
rublonStatestringAuthentication result: ok.
rublonTokenstringAccess token (60 alphanumeric characters, upper- and lowercase), which allows to verify the authentication using a background Rublon API connection

Note: If the callback URL has been set to, e.g., https://example.com/auth, the params will be appended to the URL address:

https://example.com/auth?rublonState=ok&rublonToken=Kmad4hAS…

Note: If you want to construct the callback URL differently (e.g., by using mod_rewrite), you can set the callback URL’s template using the meta-tags: %rublonToken% and %rublonState%, like so:

https://example.com/auth/%rublonState%/%rublonToken%

Handle Authentication Result

After the callback is invoked, you need to instantiate a RublonCallback class object for proper finalization of the authentication process.

RublonCallback class constructor method arguments:

NameTypeDescription
$rublonRublonAn instance of the Rublon class

Next, call the RublonCallback::call() method. It takes two arguments.

RublonCallback::call() method arguments:

NameTypeDescription
$successHandlercallableThe name of the function/method, or an anonymous function/closure, to be invoked on successful authentication
$cancelHandlercallableThe name of the function/method, or an anonymous function/closure, to be invoked when the callback is canceled

Arguments of the $successHandler function passed to the RublonCallback::call() method:

NameTypeDescription
$usernamestringThe user’s unique username in the integrated system, that was passed as an argument to the Rublon::auth() method
$callbackRublonCallbackAn instance of the RublonCallback class

Arguments of the $cancelHandler function passed to the RublonCallback::call() method:

NameTypeDescription
$callbackRublonCallbackAn instance of the RublonCallback class

Example PHP Code

An example portraying how to use the RublonCallback class in the callback:

  $rublon = new Rublon(
     "D166A6E9996A40F0A88252432FA5E490",
     "913eda929c96cf52141b39f5717e25",
     "https://code.rublon.net"
  );
  
  try {
     $callback = new RublonCallback($rublon);
     $callback->call(
        $successHandler = function($username, RublonCallback $callback) {
           // The user is finally logged in
           $_SESSION["user"] = $username;
        },
        $cancelHandler = function(RublonCallback $callback) {
           // Cancel the authentication process
           header("Location: ./login");
           exit;
        }
     );
     
     // The authentication process was successful, redirect to the main page:
     header("Location: ./");
     exit;
  } catch (RublonException $e) {
     // Please handle this error in the better way
     die($e->getMessage());
  }

Laravel Configuration

This Laravel configuration example uses the Breeze starting kit.

1. After you create the application and install Breeze, you need to add Rublon PHP SDK:

composer require Rublon/rublon-sdk-php

2. Add those to .env:

RUBLON_TOKEN=”your rublon token”
RUBLON_KEY=”your rublon key”
RUBLON_URL=”
https://core.rublon.net“

3. Create a new route for Rublon callback in routes/auth.php:

Route::get(‘rublon-callback’, [AuthenticatedSessionController::class, ‘rublonCallback’])->name(‘rublon-callback’);

4. Modify the store method in the controller:

Http/Controllers/Auth/AuthenticatedSessionController.php

  public function store(LoginRequest $request)
  {
     $request->authenticate();

     $rublon = new Rublon(
        env('RUBLON_TOKEN'),
        env('RUBLON_KEY'),
        env('RUBLON_URL'),
     );

     try { // Initiate a Rublon authentication transaction
        $url = $rublon->auth(
           $callbackUrl = url('/rublon-callback'),
           Auth::user()->email, // User email used as username
           Auth::user()->email  // User email
        );

        if (!empty($url)) {
           Auth::logout();
           return redirect()->away($url);
        } else {
           // User is not protected by Rublon, so bypass the second factor.
           $request->session()->regenerate();
           return redirect()->to('dashboard');
        }
     } catch (UserBypassedException $e) {
        return redirect()->to('login');
     } catch (RublonException $e) {
        // An error occurred
        die($e->getMessage());
     }

     return redirect()->intended(RouteServiceProvider::HOME);
  }

5. Add a new method for Rublon callback:

  public function rublonCallback(Request $request)
  {
     $rublon = new Rublon(
        env('RUBLON_TOKEN'),
        env('RUBLON_KEY'),
        env('RUBLON_URL'),
     );

     try {
        $callback = new RublonCallback($rublon);
        $request->session()->regenerate();
        $callback->call(
           $successHandler = function($username, RublonCallback $callback) {
              $user = User::where('email', $username)->firstOrFail();
              Auth::login($user);
              if (Auth::check()) {
                 return redirect()->to('dashboard');
              } else {
                 return redirect()->to('login');
              }
           },
           $cancelHandler = function(RublonCallback $callback) {
              return redirect()->to('login');
           }
        );

        return redirect()->to('dashboard');
     } catch (Rublon Exception $e) {
        die($e->getMessage());
     }

     return redirect()->to('dashboard');
  }

Troubleshooting

If you encounter any issues with your Rublon integration, please contact Rublon Support.

Filed Under: Documentation

Primary Sidebar

Contents

  • Overview
  • Use Cases
  • Supported Authentication Methods
  • Before You Start
    • Get the SDK
    • Create an Application in the Rublon Admin Console
    • Optional: Install Rublon Authenticator
  • Configuration
    • INFO: Initial Assumptions
    • INFO: Modifying the Library
    • Initialize the Library
    • Example PHP Code
    • Perform Authentication
      • Example PHP Code
    • Verify Configuration
    • Finalize Authentication
      • Input Params
      • Handle Authentication Result
      • Example PHP Code
  • Laravel Configuration
  • Troubleshooting
Try Rublon for Free
Start your 30-day Rublon Trial to secure your employees using multi-factor authentication.
No Credit Card Required


Footer

Product

  • Regulatory Compliance
  • Use Cases
  • Rublon Reviews
  • Authentication Basics
  • What is MFA?
  • Importance of MFA
  • User Experience
  • Authentication Methods
  • Rublon Authenticator
  • Remembered Devices
  • Logs
  • Single Sign-On
  • Access Policies
  • Directory Sync

Solutions

  • MFA for Remote Desktop
  • MFA for Windows Logon
  • MFA for Remote Access Software
  • MFA for Linux
  • MFA for Active Directory
  • MFA for LDAP
  • MFA for RADIUS
  • MFA for SAML
  • MFA for RemoteApp
  • MFA for Workgroup Accounts
  • MFA for Entra ID

Industries

  • Financial Services
  • Investment Funds
  • Retail
  • Technology
  • Healthcare
  • Legal
  • Education
  • Government

Documentation

  • 2FA for Windows & RDP
  • 2FA for RDS
  • 2FA for RD Gateway
  • 2FA for RD Web Access
  • 2FA for SSH
  • 2FA for OpenVPN
  • 2FA for SonicWall VPN
  • 2FA for Cisco VPN
  • 2FA for Office 365

Support

  • Knowledge Base
  • FAQ
  • System Status

About

  • About Us
  • Blog
  • Events
  • Co-funded by the European Union
  • Contact Us

  • Facebook
  • GitHub
  • LinkedIn
  • Twitter
  • YouTube

© 2025 Rublon · Imprint · Legal & Privacy · Security

  • English