Note
|
This project is deprecated and is no longer being maintained. |
Apex classes for validating YubiKey OTP's (One-Time Passwords) againt YubiCloud.
OtpValidator validator = new OtpValidator();
String result = validator.validate(otp, clientId);
if(result == AuthenticationResult.OK) {
/* The OTP is valid! Now we want to check that the YubiKey belongs
* to this user. To do this, we need to compare the ID of the YubiKey
* used to generate the OTP with the YubiKey associated with the user's
* account.
*
* For example:
*/
String yubikeyId = OtpUtils.getYubikeyId(otp)
if(yubiKeyId == user.yubikeyId__c) {
// Successfully authenticated!
} else {
// The wrong YubiKey was used for this user.
}
} else {
// Invalid OTP
}
For a more thorough usage example, see docs/Usage_Example.adoc
.
Although not at all required, you sometimes might want to extract the YubiKey Serial Number from an OTP. This serial number will match the 8-digit number that is printed on the device.
// The first 12 characters of an OTP represents the serial number of the key
String serialNumberEncoded = otp.substring(0, 12);
String serialNumber = ModHex.getSerialNumber(serialNumberEncoded);