<div dir="ltr"><div>I&#39;m currently working on a PR that provides &quot;Two factor authentication via email&quot; <a href="https://issues.jboss.org/browse/KEYCLOAK-240">https://issues.jboss.org/browse/KEYCLOAK-240</a>.</div><div><br></div><div>My current implementation comes with a custom EmailCodeAuthenticator</div><div>that generates a short code String in the challenge(...) Method and</div><div>sends an email to the email address that is configured for the current user.</div><div><br></div><div>The user can then copy and paste the code into an input field, similar</div><div>to OTP codes are handled. If the user entered the wrong code, a new</div><div>email is sent to the user&#39;s email address.</div><div><br></div><div>The email code is saved as a user level credential.</div><div><br></div><div>I wonder whether this is the right approach or whether it would be better</div><div>to allow the user to regenerate the code on demand instead of </div><div>regenerating it every time? </div><div><br></div><div>For the former I&#39;d have to provide a REST endpoint similar to what happens for verifying an email</div><div>during registration - where should this be placed?</div><div><br></div><div>For sending the actual email I&#39;m currently using a EmailSenderProvider, however I think a EmailTemplateProvider might be more appropriate ;-)</div><div>May I simply add a method to the EmailTemplateProvider interface?</div><div><br></div><div>Btw. I think this would be a good base for having an SMS based 2nd factor authenticator, as requested here: <a href="https://issues.jboss.org/browse/KEYCLOAK-241">https://issues.jboss.org/browse/KEYCLOAK-241</a></div><div><br></div><div>It would make sense to have the mobile phone number as a first-class user attribute and showing it on the profile page by default instead of just having it only in the data model.</div><div><br></div><div>Another point that comes to my mind is that I could make sense to specify an email code policy in the same way OTP policies are supported. This could then be used to differentiate between email</div><div>codes that are usually handled via copy&amp;paste whereas codes</div><div>that come via SMS are usually typed in by hand and should therefore</div><div>be somewhat short ;-)</div><div><br></div><div>My current WIP can be found here:</div><div><a href="https://github.com/thomasdarimont/keycloak/commits/issue/KEYCLOAK-240-2nd-factor-auth-via-email">https://github.com/thomasdarimont/keycloak/commits/issue/KEYCLOAK-240-2nd-factor-auth-via-email</a></div><div><br></div></div>