Use a purpose-specific method when checking verification codes via the legacy registration API
This commit is contained in:
parent
8ccab5c1e0
commit
2052e62c01
|
@ -181,8 +181,31 @@ public class RegistrationServiceClient implements Managed {
|
||||||
final String verificationCode,
|
final String verificationCode,
|
||||||
final Duration timeout) {
|
final Duration timeout) {
|
||||||
|
|
||||||
return checkVerificationCodeSession(sessionId, verificationCode, timeout)
|
return toCompletableFuture(stub.withDeadline(toDeadline(timeout))
|
||||||
.thenApply(RegistrationServiceSession::verified);
|
.legacyCheckVerificationCode(CheckVerificationCodeRequest.newBuilder()
|
||||||
|
.setSessionId(ByteString.copyFrom(sessionId))
|
||||||
|
.setVerificationCode(verificationCode)
|
||||||
|
.build()))
|
||||||
|
.thenApply(response -> {
|
||||||
|
if (response.hasError()) {
|
||||||
|
switch (response.getError().getErrorType()) {
|
||||||
|
case CHECK_VERIFICATION_CODE_ERROR_TYPE_RATE_LIMITED ->
|
||||||
|
throw new CompletionException(new RateLimitExceededException(response.getError().getMayRetry()
|
||||||
|
? Duration.ofSeconds(response.getError().getRetryAfterSeconds())
|
||||||
|
: null, true));
|
||||||
|
|
||||||
|
case CHECK_VERIFICATION_CODE_ERROR_TYPE_NO_CODE_SENT,
|
||||||
|
CHECK_VERIFICATION_CODE_ERROR_TYPE_ATTEMPT_EXPIRED,
|
||||||
|
CHECK_VERIFICATION_CODE_ERROR_TYPE_SESSION_NOT_FOUND ->
|
||||||
|
throw new CompletionException(new RegistrationServiceException(null));
|
||||||
|
|
||||||
|
default -> throw new CompletionException(
|
||||||
|
new RuntimeException("Failed to check verification code: " + response.getError().getErrorType()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return response.getVerified();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<RegistrationServiceSession> checkVerificationCodeSession(final byte[] sessionId,
|
public CompletableFuture<RegistrationServiceSession> checkVerificationCodeSession(final byte[] sessionId,
|
||||||
|
|
|
@ -26,6 +26,8 @@ service RegistrationService {
|
||||||
* session.
|
* session.
|
||||||
*/
|
*/
|
||||||
rpc check_verification_code (CheckVerificationCodeRequest) returns (CheckVerificationCodeResponse) {}
|
rpc check_verification_code (CheckVerificationCodeRequest) returns (CheckVerificationCodeResponse) {}
|
||||||
|
|
||||||
|
rpc legacy_check_verification_code (CheckVerificationCodeRequest) returns (LegacyCheckVerificationCodeResponse) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateRegistrationSessionRequest {
|
message CreateRegistrationSessionRequest {
|
||||||
|
@ -343,6 +345,20 @@ message CheckVerificationCodeResponse {
|
||||||
CheckVerificationCodeError error = 3;
|
CheckVerificationCodeError error = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message LegacyCheckVerificationCodeResponse {
|
||||||
|
/**
|
||||||
|
* Indicates whether the verification code given in the request that produced
|
||||||
|
* this response was correct.
|
||||||
|
*/
|
||||||
|
bool verified = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a code could not be checked, explains the underlying error. Will be
|
||||||
|
* absent if no error occurred.
|
||||||
|
*/
|
||||||
|
CheckVerificationCodeError error = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message CheckVerificationCodeError {
|
message CheckVerificationCodeError {
|
||||||
/**
|
/**
|
||||||
* The type of error that prevented a verification code from being checked.
|
* The type of error that prevented a verification code from being checked.
|
||||||
|
|
Loading…
Reference in New Issue