|
| 1 | +# Change Log |
| 2 | + |
| 3 | +## [0.0.1](https://github.com/auth0/Guardian.java/tree/0.0.1) (2017-03-10) |
| 4 | + |
| 5 | +First release of Guardian for Java |
| 6 | + |
| 7 | +### Install |
| 8 | + |
| 9 | +Get Guardian Java via Maven: |
| 10 | + |
| 11 | +```xml |
| 12 | +<dependency> |
| 13 | + <groupId>com.auth0</groupId> |
| 14 | + <artifactId>guardian</artifactId> |
| 15 | + <version>0.0.1</version> |
| 16 | +</dependency> |
| 17 | +``` |
| 18 | + |
| 19 | +or Gradle: |
| 20 | + |
| 21 | +```gradle |
| 22 | +compile 'com.auth0:guardian:0.0.1' |
| 23 | +``` |
| 24 | + |
| 25 | +### Usage |
| 26 | + |
| 27 | +Create an instance of `Guardian` using you Guardian URL: |
| 28 | + |
| 29 | +```java |
| 30 | +Guardian guardian = new Guardian("https://<tenant>.guardian.auth0.com"); |
| 31 | +``` |
| 32 | + |
| 33 | +Obtain an enrollment ticket from API2: |
| 34 | + |
| 35 | +```java |
| 36 | +String enrollmentTicket = "Ag1qX7vZVBvyTKhFwrkzaCH2M8vn5b6c"; |
| 37 | +``` |
| 38 | + |
| 39 | +#### Enrollment |
| 40 | + |
| 41 | +Use the ticket and `EnrollmentType.TOTP()` to request an TOTP enrollment, or `EnrollmentType.SMS()` and the phone number |
| 42 | +for an SMS enrollment. |
| 43 | + |
| 44 | +For TOTP you must ask for the TOTP URI to show to the user in the QR code. |
| 45 | + |
| 46 | +```java |
| 47 | +Transaction enrollmentTransaction; |
| 48 | +try { |
| 49 | + enrollmentTransaction = guardian |
| 50 | + .requestEnroll(enrollmentTicket, EnrollmentType.TOTP()); |
| 51 | + // or .requestEnroll(enrollmentTicket, EnrollmentType.SMS("+549XXXXXXXX58")); |
| 52 | + |
| 53 | + // Only for TOTP: use the TOTP URI to create a QR and scan with an app |
| 54 | + String totpURI = enrollmentTransaction.totpURI("Username", "Issuer"); |
| 55 | + System.out.println(totpURI); |
| 56 | + |
| 57 | +} catch (IOException e) { |
| 58 | + // connection issue, might be internet (or invalid certificates for example) |
| 59 | +} catch (GuardianException e) { |
| 60 | + if (e.isAlreadyEnrolled()) { |
| 61 | + // the user was already enrolled |
| 62 | + } else if (e.isInvalidToken()) { |
| 63 | + // the ticket is not valid anymore, or was already used |
| 64 | + } else { |
| 65 | + // some other guardian error, check the message |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +#### Transaction storage |
| 71 | + |
| 72 | +`Transaction` implements `java.io.Serializable` interface so you can save and restore it easily. |
| 73 | + |
| 74 | +> The transaction contains sensitive information like the transaction token and the recovery code. Keep in mind this |
| 75 | +> when considering possible storage options. |
| 76 | +
|
| 77 | +#### Confirm enrollment |
| 78 | + |
| 79 | +Restore the enrollment transaction from wherever you saved it, and use it together with the OTP that the user inputs to |
| 80 | +confirm the enrollment, whether it's TOTP or SMS. |
| 81 | + |
| 82 | +If the OTP was valid, the enrollment is confirmed and you get an object that contains the recovery code. |
| 83 | + |
| 84 | +```java |
| 85 | +// get the OTP from SMS or TOTP app |
| 86 | +String code = "123456"; |
| 87 | + |
| 88 | +try { |
| 89 | + Enrollment enrollment = guardian.confirmEnroll(enrollmentTransaction, code); |
| 90 | + |
| 91 | + // Get the recovery code and show to the user |
| 92 | + String recoveryCode = enrollment.getRecoveryCode(); |
| 93 | + System.out.println(recoveryCode); |
| 94 | + |
| 95 | +} catch (IOException e) { |
| 96 | + // connection issue, might be internet (or invalid certificates for example) |
| 97 | +} catch (GuardianException e) { |
| 98 | + if (e.isInvalidToken()) { |
| 99 | + // the transaction is not valid anymore |
| 100 | + } else if (e.isInvalidOTP()) { |
| 101 | + // the OTP is not valid |
| 102 | + } else { |
| 103 | + // some other guardian error, check the message |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
0 commit comments