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 Java Code
import com.rublon.sdk.twofactor.Rublon;
...
Rublon rublon = new Rublon(
// system token:
"A69FC450848B4B94A040416DC4421523",
// secret key:
"bLS6NDP7pGjg346S4IHqTHgQQjjSLw3CyApvz5iRjYzgIPN4e9EOi1cQJLrTlvLoHY8zeqg4ILrItYidKJ6JjEUZaA6pR1tZMwSZ"
);
Verify Configuration
Perform Authentication
Example Java Code
/**
* An example method used to log the user in (integrated system's method)
*/
void login(String login, String password) {
if (loginPreListener()) {
User user = authenticate(login, password);
if (user != null) {
// The user has been authenticated.
Session.setUser(user);
loginPostListener();
}
}
}
/**
* Listener (hook) invoked after a successful first factor user authentication,
* implemented for Rublon integration purposes.
*/
void loginPostListener() {
Rublon rublon = new Rublon(
// systemToken (please store in a config):
"A69FC450848B4B94A040416DC4421523",
// secretKey (please store in a safe config):
"bLS6NDP7pGjg346S4IHqTHgQQjjSLw3CyApvz5iRjYzgIPN4e9EOi1cQJLrTlvLoHY8zeqg4ILrItYidKJ6JjEUZaA6pR1tZMwSZ"
);
try { // Initiate a Rublon authentication transaction
String url = rublon.auth(
"https://example.com/rublon_callback", // callback URL
Session.getUser().getId(), // User Id
Session.getUser().getEmail() // User email
);
if (url != null) { // User protection is active
// Log the user out before checking the second factor:
Session.setUser(null);
// Redirect the user's web browser to Rublon servers
// to verify the protection:
HttpServer.sendHeader("Location", url);
}
} catch (RublonException e) {
// An error occurred
Session.setUser(null);
HttpServer.setStatus(500);
HttpServer.setResponse("There was an error, please try again later.");
}
/* If we're here, the user's account is not protected by Rublon.
The user can be authenticated. */
}
Finalize Authentication
Input Params
Handle Authentication Result
Example Java Code
class Callback extends RublonCallback {
public String getState() {
return HttpServer.getRequestHandler().getParam(PARAMETER_STATE);
}
public String getAccessToken() {
return HttpServer.getRequestHandler().getParam(PARAMETER_ACCESS_TOKEN);
}
protected void handleCancel() {
HttpServer.sendHeader("Location", "/login");
}
protected void handleError() {
HttpServer.sendHeader("Location", "/login?msg=rublon-error");
}
protected void userAuthenticated(String appUserId) {
Session.setUser(User.getById(appUserId));
HttpServer.sendHeader("Location", "/dashboard");
}
}
...
Rublon rublon = new Rublon(
"A69FC450848B4B94A040416DC4421523",
"bLS6NDP7pGjg346S4IHqTHgQQjjSLw3CyApvz5iRjYzgIPN4e9EOi1cQJLrTlvLoHY8zeqg4ILrItYidKJ6JjEUZaA6pR1tZMwSZ"
);
try {
RublonCallback callback = new Callback(rublon);
callback.call();
} catch (CallbackException e) {
// Please handle this error in the better way:
HttpServer.setStatus(500);
HttpServer.setResponse("There was an error, please try again later. " + e.getMessage());
}