/** * Initialize object with Rublon instance. * * A Rublon class instance is required for * the object to work. * * @param Rublon2Factor $rublon An instance of the Rublon class * @param string $userId User's ID in the local system. * @param string $userEmail User's email address. * @param boolean $logoutListener Wheter to listen on user's logout. */ public function __construct(Rublon2Factor $rublon, $userId, $userEmail, $logoutListener = false) { $rublon->log(__METHOD__); $this->rublon = $rublon; $this->userId = $userId; $this->userEmail = $userEmail; $this->logoutListener = $logoutListener; }
/** * Constructor. * * @param Rublon2Factor $rublon */ public function __construct(Rublon2Factor $rublon) { if (!$rublon->isConfigured()) { trigger_error(RublonConsumer::TEMPLATE_CONFIG_ERROR, E_USER_ERROR); } $this->rublon = $rublon; $this->log(__METHOD__); }
/** * Hook before actual login the user, after the authentication was successful. * * @param string $userEmail * @return void */ function hook_before_login($userEmail) { // Make sure that the user is not logged-in: unset($_SESSION['user']); try { $rublon = new Rublon2Factor(RUBLON_SYSTEM_TOKEN, RUBLON_SECRET_KEY); $url = $rublon->auth($callbackUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?rublon=callback', $userId = $userEmail, $userEmail, $extraParams = array()); if (!empty($url)) { // Redirect the user's browser to the Rublon's server to authenticate by Rublon: header('Location: ' . $url); exit; } else { return; // User is not protected by Rublon, so bypass the second factor. } } catch (RublonException $e) { die($e->getMessage()); } }