Skip to content

Commit

Permalink
Merge pull request #92 from Njoodd/master
Browse files Browse the repository at this point in the history
Fix OTP Verification Issue #91
  • Loading branch information
cooperlyt authored Feb 29, 2024
2 parents 8337184 + 90f9d61 commit 353095b
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,10 +56,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();
Expand All @@ -76,6 +78,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");
}
}

Expand Down

0 comments on commit 353095b

Please sign in to comment.