cooperlyt/keycloak-phone-provider

Error setting up SMS OTP

korridor opened this issue · 22 comments

During the action “CONFIGURE_SMS_OTP” only get the following error:
Phone number not found

Looks to me like this error comes from here:

image

Looks to me like a bug because if I set up an SMS OTP I don't need a phone number as a user property, right?
I would like to fix that, but I do not get where tokenCodeType comes from.
If you provide me with a bit more information, I can provide a PR.

Hi, can you tell how you got this form? Can you make a video of how to set it up?

I can send you a few screenshots of the configuration, in a few hours. Does using SMS only as a second factor work for you?

@Teut2711 But with this plugin? And only as a second factor or instead of a password?

I started from a relatively blank realm.

  1. Activate SMS authenticator
Screenshot 2023-07-12 at 17 31 05
  1. Duplicate default browser flow

  2. Adapt the new flow to use SMS 2FA instead of OTP

Screenshot 2023-07-12 at 17 34 52
  1. Bind new custom flow as “browser flow”
image
  1. If I create a new user and login, I'll be forced to setup SMS 2FA, but this does not work because I get the error from the screenshot.

Well, first user logins through username password-> otp screen comes up with this package=>I enter otp => I get to dashboard.
I forgot if I put my phone number on that otp page.

In the examples/docker-compose.yaml,

Modify the command as follows for testing with twilio api.

command:

      - start-dev --spi-phone-default-service=twilio --spi-message-sender-service-twilio-account=AC0c7bc956dc97e07c49d4b6d53ad3c74d --spi-message-sender-service-twilio-token=7e283a3acb3dc032f881803abb161521 --spi-message-sender-service-twilio-number=+16186814535 

I get the SMS OTP screen (see screenshot in the original issue), but if I enter a telephone number I get a “Phone number not found” error.

244955011-87a286e3-deb4-481e-b317-687c37379a80

Does your user registration require the user to provide a phone number? Does your 2FA page look like mine? Do you also have to enter a phone number or only the code?

Oh sorry, I was in the dilemma that it was my post. Try your std code. Like in India +0124-<some-10-digit-number> or for mobile number +91-<some-mobile-number-10-digits> . Also if it's twilio's api, you need to verify that number with twilio in test mode or buy a paid plan for spamming anyone.

I tried all types of phone numbers. I now also tried a indian phone number like this one: +917428730894
I'm currently using the dummy phone driver for testing purposes.

Could you send me the REST request that the client sends when you click on “Send code”? My custom theme might change the request somehow.

What api are you using? Is it some own implementation of yours of the base class or something from the given services?

Try twilio for the start and once you get that working, you can go with your own implementation. Twilio's api for testing is free.

I mean the API endpoint that this plugin provides. For example: realms/somerealm/sms/otp-code

image

After you put your number for the first time it saves it.

I really dont know why you first don't go with twilio then just overwrite the parts of that twilio/or dummy class by inheriting it to implement with your own api.

I don't have my own API I'm just using the plain dummy provider. I was talking about the XHR request that happens if you press the Send code button. That is not my API and I did not customize this API.

Please listen to me. Go to twilio, create an account, verify your number on twilio and use that in that mobile number box in your image. Get back if you have any trouble.

The first part of debugging is comparing things that work with things that don't work.

Are you saying that the Twilio provider is more stable than the dummy provider that was made for testing purposes?

First of all, dummy does nothing. It should print to console is what the docs say. Secondly, no, I am saying to use twilio because that worked for me.

My point was that it does not even work with the dummy provider, so I would assume it has nothing to do with the provider. More likely a problem with the configuration of the plugin itself.

Could you please send me a screenshot of your browser flow? Then I can compare it to your setup.

I am facing same problem here.

I have setup a fresh realm, and createed 2 users, A, B, and both of them do not have any phoneNumber attribute and not enrolled SMS OTP. Then I enabled Configure OTP over SMS required action in realm authentication.

When A login with his password, due to no SMS OTP configured, user A comes to configure OTP over SMS page. Now user A input his phone number N1 and click "Send Code", but unfornately it shows "Phone number not found", he cannot complete the SMS OTP setup and stuck there.

I checked the backend logic, it seems the js called the /realms/maple/sms/otp-code?phoneNumber=xxxxxx endpoint, in this endpoint, it searchs any user that have a attribute named phoneNumber and equals the phoneNumber parameter. If found, send the code, else it will return the message "Phone number not found".

 // 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");
    }

If I manually add phoneNumber attribute to user B with requested phoneNumber then login A with password, it sends the code correctly!!!

Actually, I dont understand the logic here, it's very strange, if all users in realms do not have phoneNumber attribute, how can I enable the SMS OTP feature, I am really confused.

Perhaps the js should call /realms/maple/sms/registration-code?phoneNumber=xxxxxx in the SMS OTP enrollment page...