Software listing / yubico-java-client / v2client View on GitHub

yubico-java-client

Client library written in Java for verifying Yubikey one-time passwords (OTPs).

A validation client for use with the Yubico validation API (version 2). By default, it uses the Yubico YubiCloud validation platform, but can be configured for another validation server. To use YubiCloud you need a client ID and an API key that can be fetched from https://upgrade.yubico.com/getapikey.

Usage

Add this to your pom.xml:

<dependency>
  <groupId>com.yubico</groupId>
  <artifactId>yubico-validation-client2</artifactId>
  <version>2.0.1</version>
</dependency>

A simple implementation would be:

// otp is the OTP from the Yubikey
// clientId is the client ID from https://upgrade.yubico.com/getapikey/
boolean validate(String otp, int clientId) {
   YubicoClient client = YubicoClient.getClient(clientId);
   YubicoResponse response = client.verify(otp);
   return response.getStatus() == YubicoResponseStatus.OK;
}

After validating the OTP you should make sure that the publicId part belongs to the correct user. For example:

YubicoClient.getPublicId(otp)
    .equals(/* Yubikey ID associated with the user */);

Read more about this here.

Logging

The validation client depends on slf4j-api for logging. To get the actual logs and not receive warnings on System.out you will need to depend on a slf4j logger binding, for example slf4j-log4j with the following maven configuration:

<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-log4j</artifactId>
 <version>1.6.1</version>
</dependency>

Read more

For more complete descriptions of methods and failure states, please see the javadoc.