Skip to content
egg82 edited this page Jun 16, 2019 · 1 revision

The developer API is fairly simple and straight-forward, so I'll leave you with some basic documentation and some examples.

Maven

To include the plugin into your Maven project, just use the repository and link below.

<repository>
  <id>egg82-ninja</id>
  <url>https://www.myget.org/F/egg82-java/maven/</url>
</repository>

Link to latest version is available here.

Make sure to use <scope>provided</scope> when adding the dependency!

Documentation

Get the API instance.

ExternalAPI api = ExternalAPI.getInstance();

API methods

long getCurrentSQLTime() throws APIException;
void registerAuthy(UUID uuid, String email, String phone, [String countryCode]) throws APIException;
String registerTOTP(UUID uuid, long codeLength) throws APIException;
String registerHOTP(UUID uuid, long codeLength, [long initialCounterValue]) throws APIException;
void seekHOTPCounter(UUID uuid, Collection<String> tokens) throws APIException;
void seekHOTPCounter(UUID uuid, String[] tokens) throws APIException;
boolean isRegistered(UUID uuid) throws APIException;
void delete(UUID uuid) throws APIException;
boolean isVerified(UUID uuid, boolean refresh) throws APIException;
boolean verify(UUID uuid, String token) throws APIException;

Examples

Register a user for TOTP

ExternalAPI api = ExternalAPI.getInstance();
try {
    String key = api.registerTOTP(playerUuid, codeLength);
    // Send player key (QR code, raw data, etc)
} catch (APIException ex) {
    // Handle exception
}

Delete a user from all 2FA services entirely

ExternalAPI api = ExternalAPI.getInstance();
try {
    api.delete(playerUuid);
} catch (APIException ex) {
    // Handle exception
}

Detect if a user has 2FA enabled

ExternalAPI api = ExternalAPI.getInstance();
try {
    if (api.isRegistered(playerUuid)) {
        // User has 2FA enabled
    } else {
        // User does not have 2FA enabled
    }
} catch (APIException ex) {
    // Handle exception
}

Detect if a user has recently authenticated themselves, and reset their verification if they have

ExternalAPI api = ExternalAPI.getInstance();
try {
    if (api.isVerified(playerUuid, true)) {
        // User has recently put in their 2FA code
    } else {
        // User has not recently put in their 2FA code
    }
} catch (APIException ex) {
    // Handle exception
}

Attempt to authenticate a user

ExternalAPI api = ExternalAPI.getInstance();
try {
    if (api.verify(playerUuid, token)) {
        // User has successfully authenticated themselves
    } else {
        // Authentication code was wrong
    }
} catch (APIException ex) {
    // Handle exception
}