Skip to content

Commit 31a5c25

Browse files
author
Michael Mroz
committed
Exposed transaction properties, added a new enrollment confirmation method
1 parent 6fa69c1 commit 31a5c25

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/main/java/com/auth0/guardian/Guardian.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public Transaction requestEnroll(String ticket, EnrollmentType type)
8686
* transaction initiated with {@link EnrollmentType#TOTP()}) or when the user received the OTP code delivered to his
8787
* phone number by SMS (for a transaction initiated with {@link EnrollmentType#SMS(String)}).
8888
*
89+
* This method can be used in stateful applications where a {@link Transaction} is preserved in memory between user
90+
* interactions.
91+
*
8992
* @param transaction the enrollment transaction
9093
* @param otp the code obtained from the TOTP app or delivered to the phone number by SMS
9194
* @return extra information about the enrollment, like the recovery code
@@ -108,4 +111,34 @@ public Enrollment confirmEnroll(Transaction transaction, String otp)
108111

109112
return new Enrollment(transaction.getRecoveryCode());
110113
}
114+
115+
/**
116+
* Confirms an enrollment started with {@link Guardian#requestEnroll(String, EnrollmentType)}.
117+
* <p>
118+
* Use this method to confirm an enrollment transaction once the user scanned the QR code with a TOTP app (for a
119+
* transaction initiated with {@link EnrollmentType#TOTP()}) or when the user received the OTP code delivered to his
120+
* phone number by SMS (for a transaction initiated with {@link EnrollmentType#SMS(String)}).
121+
*
122+
* This method can be used in stateless applications where {@link Transaction} may not be preserved between user
123+
* interactions.
124+
*
125+
* @param transactionToken the token associated with the transaction to confirm.
126+
* @param otp the code obtained from the TOTP app or delivered to the phone number by SMS
127+
* @throws IOException when there's a connection issue
128+
* @throws IllegalArgumentException when the transaction is not valid
129+
* @throws GuardianException when there's a Guardian specific issue (invalid otp for example)
130+
*/
131+
public void confirmEnrollStateless(String transactionToken, String otp)
132+
throws IOException, IllegalArgumentException, GuardianException {
133+
if (transactionToken == null) {
134+
throw new IllegalArgumentException("Invalid enrollment transaction");
135+
}
136+
if (otp == null) {
137+
throw new IllegalArgumentException("Invalid OTP");
138+
}
139+
140+
apiClient
141+
.verifyOTP(transactionToken, otp)
142+
.execute();
143+
}
111144
}

src/main/java/com/auth0/guardian/Transaction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public class Transaction implements Serializable {
4848
this.otpSecret = otpSecret;
4949
}
5050

51-
String getTransactionToken() {
51+
public String getTransactionToken() {
5252
return transactionToken;
5353
}
5454

55-
String getRecoveryCode() {
55+
public String getRecoveryCode() {
5656
return recoveryCode;
5757
}
5858

src/test/java/com/auth0/guardian/GuardianTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public void shouldFailConfirmationWhenTransationIsNull() throws Exception {
240240
server.emptyResponse();
241241

242242
guardian
243-
.confirmEnroll(null, OTP_CODE);
243+
.confirmEnroll((Transaction)null, OTP_CODE);
244244
}
245245

246246
@Test

0 commit comments

Comments
 (0)