From 90f9d617ce9ac9f68cc4a0d728b203df532224bf Mon Sep 17 00:00:00 2001 From: N Date: Wed, 27 Dec 2023 15:58:33 +0300 Subject: [PATCH] Update DefaultPhoneVerificationCodeProvider.java Fix OTP Verification --- .../spi/impl/DefaultPhoneVerificationCodeProvider.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keycloak-phone-provider/src/main/java/cc/coopersoft/keycloak/phone/providers/spi/impl/DefaultPhoneVerificationCodeProvider.java b/keycloak-phone-provider/src/main/java/cc/coopersoft/keycloak/phone/providers/spi/impl/DefaultPhoneVerificationCodeProvider.java index 6d83a5d3..4e770d99 100644 --- a/keycloak-phone-provider/src/main/java/cc/coopersoft/keycloak/phone/providers/spi/impl/DefaultPhoneVerificationCodeProvider.java +++ b/keycloak-phone-provider/src/main/java/cc/coopersoft/keycloak/phone/providers/spi/impl/DefaultPhoneVerificationCodeProvider.java @@ -7,6 +7,7 @@ import cc.coopersoft.keycloak.phone.credential.PhoneOtpCredentialProvider; import cc.coopersoft.keycloak.phone.credential.PhoneOtpCredentialProviderFactory; import cc.coopersoft.keycloak.phone.providers.constants.TokenCodeType; +import cc.coopersoft.keycloak.phone.providers.exception.PhoneNumberInvalidException; import cc.coopersoft.keycloak.phone.providers.jpa.TokenCode; import cc.coopersoft.keycloak.phone.providers.representations.TokenCodeRepresentation; import cc.coopersoft.keycloak.phone.providers.spi.PhoneVerificationCodeProvider; @@ -54,10 +55,11 @@ private RealmModel getRealm() { public TokenCodeRepresentation ongoingProcess(String phoneNumber, TokenCodeType tokenCodeType) { try { + String resultPhoneNumber = Utils.canonicalizePhoneNumber(session, phoneNumber); TokenCode entity = getEntityManager() .createNamedQuery("ongoingProcess", TokenCode.class) .setParameter("realmId", getRealm().getId()) - .setParameter("phoneNumber", phoneNumber) + .setParameter("phoneNumber", resultPhoneNumber) .setParameter("now", new Date(), TemporalType.TIMESTAMP) .setParameter("type", tokenCodeType.name()) .getSingleResult(); @@ -75,6 +77,9 @@ public TokenCodeRepresentation ongoingProcess(String phoneNumber, TokenCodeType return tokenCodeRepresentation; } catch (NoResultException e) { return null; + } catch (PhoneNumberInvalidException e) { + logger.warn("Invalid number: "+phoneNumber); + throw new BadRequestException("Phone number is invalid"); } }