mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 10:08:01 +01:00
Use a purpose-specific method when checking verification codes via the legacy registration API
This commit is contained in:
committed by
Jon Chambers
parent
8ccab5c1e0
commit
2052e62c01
@@ -181,8 +181,31 @@ public class RegistrationServiceClient implements Managed {
|
||||
final String verificationCode,
|
||||
final Duration timeout) {
|
||||
|
||||
return checkVerificationCodeSession(sessionId, verificationCode, timeout)
|
||||
.thenApply(RegistrationServiceSession::verified);
|
||||
return toCompletableFuture(stub.withDeadline(toDeadline(timeout))
|
||||
.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,
|
||||
|
||||
Reference in New Issue
Block a user