Last updated on July 8, 2025
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
require_once "libs/Rublon/Rublon.php";
$rublon = new Rublon(
"D166A6E9996A40F0A88252432FA5E490",
"913eda929c96cf52141b39f5717e25",
"https://core.rublon.net"
);
Perform Authentication
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());
}
}
Verify Configuration
Finalize Authentication
Input Params
Handle Authentication Result
Example PHP Code
$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
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);
}
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');
}