After pulling the latest updates on main and testing the email authenticator, I found that the email authenticator is always shown as active and the delete button is enabled, even if the email authenticator is not set up.
I have debugged this and I found it's because the email authenticator always returns a dummy credential object if the authenticator is not configured.
{
"type": "email-authenticator",
"category": "two-factor",
"displayName": "email-authenticator-display-name",
"helptext": "email-authenticator-help-text",
"iconCssClass": "kcAuthenticatorEmailClass",
"createAction": "email-authenticator-setup",
"removeable": true,
"userCredentialMetadatas": [
{
"credential": {
"id": "email-authenticator-id",
"type": "email-authenticator",
"createdDate": -1,
"priority": 0
}
}
]
}
Since I have a custom theme that doesn't show the Set up Email Authenticator button for the email authenticator if there's one 2FA email credentail is returned, for the same reason, to allow only having one email authenticator configured. This results in not being able to configure the 2FA email authenticator.
I think a better approach for enforcing only one 2FA email authenticator at most is to do that in the backend by raising an error when the user requests to set it up again if he has one 2FA email authenticator configured, and keep returning userCredentialMetadatas empty if it's not configured.
After pulling the latest updates on main and testing the email authenticator, I found that the email authenticator is always shown as active and the delete button is enabled, even if the email authenticator is not set up.
I have debugged this and I found it's because the email authenticator always returns a dummy credential object if the authenticator is not configured.
{ "type": "email-authenticator", "category": "two-factor", "displayName": "email-authenticator-display-name", "helptext": "email-authenticator-help-text", "iconCssClass": "kcAuthenticatorEmailClass", "createAction": "email-authenticator-setup", "removeable": true, "userCredentialMetadatas": [ { "credential": { "id": "email-authenticator-id", "type": "email-authenticator", "createdDate": -1, "priority": 0 } } ] }Since I have a custom theme that doesn't show the
Set up Email Authenticatorbutton for the email authenticator if there's one 2FA email credentail is returned, for the same reason, to allow only having one email authenticator configured. This results in not being able to configure the 2FA email authenticator.I think a better approach for enforcing only one 2FA email authenticator at most is to do that in the backend by raising an error when the user requests to set it up again if he has one 2FA email authenticator configured, and keep returning
userCredentialMetadatasempty if it's not configured.