I would like to restrict the registration process only to specific email domains.
Eg, only accept registration from *@adomain.com or *@anotherdomain.org and reject all other registrations.
I’m not able to find a way to achieve that.
2020-12-04 12:35:26,919 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of “keycloak-registration-mail-restrict-1.2-SNAPSHOT.jar” (runtime-name: “keycloak-registration-mail-restrict-1.2-SNAPSHOT.jar”)
2020-12-04 12:35:26,946 WARN [org.jboss.as.dependency.private] (MSC service thread 1-8) WFLYSRV0018: Deployment “deployment.keycloak-registration-mail-restrict-1.2-SNAPSHOT.jar” is using a private module (“org.keycloak.keycloak-server-spi-private”) which may be changed or removed in future versions without notice.
2020-12-04 12:35:26,946 WARN [org.jboss.as.dependency.private] (MSC service thread 1-8) WFLYSRV0018: Deployment “deployment.keycloak-registration-mail-restrict-1.2-SNAPSHOT.jar” is using a private module (“org.keycloak.keycloak-services”) which may be changed or removed in future versions without notice.
2020-12-04 12:35:26,947 INFO [org.keycloak.subsystem.server.extension.KeycloakProviderDeploymentProcessor] (MSC service thread 1-3) Deploying Keycloak provider: keycloak-registration-mail-restrict-1.2-SNAPSHOT.jar
2020-12-04 12:35:26,955 WARN [org.keycloak.services] (MSC service thread 1-3) KC-SERVICES0047: registration-mail-check-action (net.micedre.keycloak.registration.RegistrationProfileWithMailDomainCheck) is implementing the internal SPI form-action. This SPI is internal and may change without notice
2020-12-04 12:35:26,991 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed “keycloak-registration-mail-restrict-1.2-SNAPSHOT.jar” (runtime-name : “keycloak-registration-mail-restrict-1.2-SNAPSHOT.jar”)
but I still don’t see it available under the flows
Releases are pushed to maven central, I’ll also publish next releases to github.
Also, if you are using the last versions of keycloak, it may be better to use the nex features around user profiles to whitelist, or blacklist user emails (and do so much more )
hi,
i just implemented this with the user profile, thanks to @nosan for the tip!
it can be found here in the doumentation: Server Administration Guide
here’s the steps i took, but this may not be the perfect way to implement this:
i enabled the ‘user profile’ preview by passing KC_FEATURES=declarative-user-profile as an environment variable in my docker-compose.yml and restarted the container.
on the admin dashboard i went to ‘realm settings’ → ‘general’ and set the ‘user profile enabled’ to true.
after a reload i went to ‘realm settings’ → ‘user profile’, klicked on ‘email’, scrolled down to ‘validators’ and klicked ‘create validator’.
i selected ‘pattern’ from the list and added .+@mydomain.com as a pattern and Sorry! Only E-Mails with *@mydomain.com are allowed! If you still need an account please message admin@mydomain.com (the error message might be too long)
after saving i get the error message displayed upon creating an account with e.g. a gmail email adress. *@mydomain.com works fine.
not solved:
this also seems to restrict an admin adding any account not ending in @mydomain.com
i haven’t yet got around to making locales, so the error message shows like this in every selected language.