cooperlyt/keycloak-phone-provider

Register with phone number is not working

peyman1372 opened this issue · 12 comments

Hi,
the register with a phone number does not work and it just shows the same form click on submit; however, if I set the email as username it does work! tested on keycloak 19.0.0, 19.0.1,19.0.3

Update, removing profile validation from the conditions, fixed the problem!
In the profile validation step, keycloak throws an error saying that missing username
Screen Shot 2022-11-01 at 9 37 40 AM

I got the same issue too, this issue arise because keycloak expecting username to be not null, it works for emailAsUsername because in DefaultAttributes.java under normalizeAttributes function username attribute is copied from email. Hence, profile.validate() works, but for phone, the username is not copied from phone, hence validation failed.

https://github.com/keycloak/keycloak/blob/19d69169b16123cd78740e8796886bba23969f6b/server-spi-private/src/main/java/org/keycloak/userprofile/DefaultAttributes.java#L308-L315

if (email != null && realm.isRegistrationEmailAsUsername()) {
           final List<String> lowerCaseEmailList = email.stream()
                   .filter(Objects::nonNull)
                   .map(String::toLowerCase)
                   .collect(Collectors.toList());

           newAttributes.put(UserModel.USERNAME, lowerCaseEmailList);
       }

which doesnt happen to isRegistrationPhoneAsUsername under REGISTRATION_PROFILE context. The validator requires username to be defined (in AbstractUserProfileProvider.java).

I believe removing Profile Validation might cause missing some data updates as shown in DefaultUserProfile under updateInternal.

Also I found that when updating phoneNumber, username is not updated along according to this issue, https://github.com/keycloak/keycloak/issues/13988 which they have submitted a pull request to fix. Which also depens of realm.isRegistrationEmailAsUsername() hence, without isRegistrationPhoneAsUsername in DefaultAttributes file, which will fail to update username.

you need config "Registration Phone User Creation > setting > Phone number as username > checked " in flows

@cooperlyt I've Phone number as username checked and I'm getting the same error!

Please check the following logs:

2023-02-19 17:04:22 2023-02-19 15:04:22,732 WARN  [cc.coopersoft.keycloak.phone.providers.spi.impl.DefaultPhoneProvider] (executor-thread-79) not specify a message sender service provider! Default provider'dummy' will be used. you can use keycloak start param '--spi-phone-default-service' specify other one. 
2023-02-19 17:04:22 2023-02-19 15:04:22,749 WARN  [org.keycloak.events] (executor-thread-79) type=REGISTER_ERROR, realmId=1ce61bee-957c-4ebe-abe2-f098d26794f0, clientId=phone-client, userId=null, ipAddress=172.28.0.1, error=invalid_registration, auth_method=openid-connect, phoneNumber=+201111928812, register_method=form, last_name=User, redirect_uri=https://www.youtube.com/, first_name=Test, code_id=53050911-d4e4-4b91-8af1-e7a915216958, email=test@mail.com, username=+201111123456, authSessionParentId=53050911-d4e4-4b91-8af1-e7a915216958, authSessionTabId=wPvyUJfsTH8

any idea?

@cooperlyt I tried to toggle Phone number as username off and entering the same value for phone and username form fields manually on the registration and it worked fine, so most probably the root cause is the phone number value is not being set properly during the registration!

invalid_registration

I can't reproduce this . what`s your Keycloak version?

@cooperlyt Do you have preview feature: user profile enabled and in the realm setting too?.

I found that user profile enabled, any extra attribute that is not predefined in user profile will not be saved. I believe maybe it has incompatibility with that and if it is saved by other mean it will fail the profile validation.

invalid_registration

I can't reproduce this . what`s your Keycloak version?

@cooperlyt quay.io/keycloak/keycloak:19.0.1

Tip: if Realm parameter 'Email as username' is true, then config 'Phone number as username' and 'hide email' is invalid! if parameter 'duplicate-phone' is true then 'Phone number as username' is invalid!

confirm this!

Tip: if Realm parameter 'Email as username' is true, then config 'Phone number as username' and 'hide email' is invalid! if parameter 'duplicate-phone' is true then 'Phone number as username' is invalid!

confirm this!

Both Email as username and duplicate-phone are set to false/unchecked.

i have same issue even when using docker compose attached in example

fixed it in 2.2.2