Skip to content

0.1.0

Compare
Choose a tag to compare
@hzalaz hzalaz released this 23 Nov 19:52
· 102 commits to master since this release
4c534de

First release of Guardian for Android

Install

Add these lines to your build.gradle dependencies file:

compile 'com.auth0.android:guardian:0.1.0'

Usage

Create an instance of Guardian:

String domain = "<TENANT>.guardian.auth0.com";

Guardian guardian = new Guardian.Builder()
        .domain(domain)
        .build();

To create an enroll, create a pair of RSA keys, obtain the Guardian enrollment data from a Guardian QR code and use it like this:

KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048); // you MUST use at least 2048 bit keys
KeyPair keyPair = keyPairGenerator.generateKeyPair();

CurrentDevice device = new CurrentDevice(context, "gcmToken", "deviceName");

String enrollmentUriFromQr = ...; // the data from a Guardian QR code

guardian
        .enroll(enrollmentUriFromQr, device, keyPair)
        .start(new Callback<Enrollment> {
            @Override
            void onSuccess(Enrollment enrollment) {
               // we have the enrollment data
            }

            @Override
            void onFailure(Throwable exception) {
               // something failed
            }
        });

To allow or reject a login request you first need to get the Guardian Notification:

// at the GCM listener you receive a Bundle
@Override
public void onMessageReceived(String from, Bundle data) {
    Notification notification = Guardian.parseNotification(data);
    if (notification != null) {
        handleGuardianNotification(notification);
        return;
    }

    /* Handle other push notifications you might be using ... */
}

Then, to allow the login request:

guardian
        .allow(notification, enrollment)
        .execute(); // or start(new Callback<> ...) asynchronously