@@ -86,6 +86,9 @@ public Transaction requestEnroll(String ticket, EnrollmentType type)
86
86
* transaction initiated with {@link EnrollmentType#TOTP()}) or when the user received the OTP code delivered to his
87
87
* phone number by SMS (for a transaction initiated with {@link EnrollmentType#SMS(String)}).
88
88
*
89
+ * This method can be used in stateful applications where a {@link Transaction} is preserved in memory between user
90
+ * interactions.
91
+ *
89
92
* @param transaction the enrollment transaction
90
93
* @param otp the code obtained from the TOTP app or delivered to the phone number by SMS
91
94
* @return extra information about the enrollment, like the recovery code
@@ -108,4 +111,34 @@ public Enrollment confirmEnroll(Transaction transaction, String otp)
108
111
109
112
return new Enrollment (transaction .getRecoveryCode ());
110
113
}
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
+ }
111
144
}
0 commit comments