Skip to content

Commit

Permalink
Fix/keycloak (#1199)
Browse files Browse the repository at this point in the history
yoma-628: The system is currently sending SMS login OTPs to unregistered numbers.
yoma-631: Cellphone number input asks for +27, although only requires 0
yoma-633: A registered cellphone number can initiate sign up process
  • Loading branch information
jasondicker authored Jan 20, 2025
1 parent abc5205 commit fadb5b9
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 10 deletions.
Binary file modified src/keycloak/providers/jars/keycloak-phone-provider.jar
Binary file not shown.
Binary file modified src/keycloak/providers/jars/keycloak-phone-provider.resources.jar
Binary file not shown.
Binary file modified src/keycloak/providers/jars/keycloak-sms-provider-dummy.jar
Binary file not shown.
Binary file modified src/keycloak/providers/jars/keycloak-sms-provider-twilio.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div id="kc-info-message">
<p class="instruction">${message.summary}<#if requiredActions??><#list requiredActions>: <b><#items as reqActionItem>${kcSanitize(msg("requiredAction.${reqActionItem}"))?no_esc}<#sep>, </#items></b></#list><#else></#if></p>
<#if skipLink??>
<p>TODO: skipLink</p>
<#else>
<#if pageRedirectUri?has_content>
<p><a href="${pageRedirectUri}">${kcSanitize(msg("backToApplication"))?no_esc}</a></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<label for="phoneNumber" class="${properties.kcLabelClass!}">${msg("enterPhoneNumber")}</label>

<!-- INPUT: phone number -->
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel" placeholder="+27"
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel"
aria-invalid="<#if messagesPerField.existsError('phoneNumber')>true</#if>" autocomplete="mobile tel"
v-model="phoneNumber" @input="resetPhoneVerification" v-intl-tel-input />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<label for="phoneNumber" class="${properties.kcLabelClass!}">${msg("enterPhoneNumber")}</label>

<!-- INPUT: phone number -->
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel" placeholder="+27"
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel"
aria-invalid="<#if messagesPerField.existsError('phoneNumber')>true</#if>" autocomplete="mobile tel"
v-model="phoneNumber" @input="resetPhoneVerification" v-intl-tel-input />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<label for="phoneNumber" class="${properties.kcLabelClass!}">${msg("enterPhoneNumber")}</label>

<!-- INPUT: phone number -->
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel" placeholder="+27"
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel"
aria-invalid="<#if messagesPerField.existsError('phoneNumber')>true</#if>" autocomplete="mobile tel"
v-model="phoneNumber" @input="resetPhoneVerification" v-intl-tel-input />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<label for="phoneNumber" class="${properties.kcLabelClass!}">${msg("enterPhoneNumber")}</label>

<!-- INPUT: phone number -->
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel" placeholder="+27"
<input id="phoneNumber" class="${properties.kcInputClass!}" name="phoneNumber" type="tel"
aria-invalid="<#if messagesPerField.existsError('phoneNumber')>true</#if>" autocomplete="mobile tel"
v-model="phoneNumber" @input="resetPhoneVerification" v-intl-tel-input :disabled="phoneVerified" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ public Response getTokenCode(@NotBlank @QueryParam("phoneNumber") String phoneNu
throw new BadRequestException("Phone number is invalid");
}

// everybody phones authenticator send AUTH code
if (!TokenCodeType.REGISTRATION.equals(tokenCodeType)
&& !TokenCodeType.AUTH.equals(tokenCodeType)
&& !TokenCodeType.VERIFY.equals(tokenCodeType)
&& Utils.findUserByPhone(session, session.getContext().getRealm(), phoneNumber).isEmpty()) {
throw new ForbiddenException("Phone number not found");
// check if phone number exists
boolean phoneNumberExists = !Utils.findUserByPhone(session, session.getContext().getRealm(), phoneNumber).isEmpty();

// check if the phone number is valid for the requested operation
if ((TokenCodeType.AUTH.equals(tokenCodeType) || TokenCodeType.RESET.equals(tokenCodeType)) && !phoneNumberExists) {
throw new ForbiddenException("We can't find your number, sign up first if you haven't.");
} else if (TokenCodeType.REGISTRATION.equals(tokenCodeType) && phoneNumberExists) {
throw new ForbiddenException("This phone number is already registered. Sign in or use a different number.");
}

logger.info(String.format("Requested %s code to %s", tokenCodeType.label, phoneNumber));
Expand Down

0 comments on commit fadb5b9

Please sign in to comment.