I assume that we need a small specification for this, which at least brings together the essential requirements to be able to check the present implementation against it.
I would be glad to hear your thoughts :)
Some additional questions:
Q1 Backup Code Encoding
I currently encode backup codes similar to passwords with pbkdf2-sha256 with 1000 iterations to save some CPU since we generate ten codes at once and store the backup codes in the credentials table. Is my approach for storing backup codes sound?
Q1.1 Handle "Used" Backup Codes
I currently "burn" a used backup code by deleting it from the credentials table. Is this okay, or should I rather keep it and mark it as "used"?
Q1.2 Backup Codes are only Displayed once
The user can only see the generated backup codes when they are generated. After that, there is no way for Keycloak to present the raw backup codes again.
Does this make sense to you?
Q2 Backup Codes as a Recovery Mechanism vs. independent 2nd Factor?
Should backup codes work as a general second-factor on their own, or should they only be considered if at least one alternative 2FA is configured?
Q3 How to configure Backup Codes details?
How should an admin be able to configure (backup-code length, number of codes, hash mechanism, hash iterations)? The backup code configuration should probably be realms-specific. Should I use realm attributes or password policies (which makes sense as a config container) for this?
Q3.1 Backup Codes Config via (more flexible) Password Policies?
If I use password policies, I need to ensure that they are only applied to backup codes and not regular passwords.
Perhaps we need to add a `default boolean supports(String credentialType) { return PasswordCredentialModel.TYPE; }` to
the PasswordPolicyProvider interface, which allows extensions to control the credential type to apply the policy.
Q4 Backup Codes and User Events
On backup code generation, I want to send an event. Currently, I use the UPDATE_PASSWORD event with some additional detail metadata.
Does it make sense to have a new event type like EventType.UPDATE_BACKUP_CODE or something generic like EventType.UPDATE_SECOND_FACTOR?
Q5 Backup Code Display in Account-Console
I currently generate ten backup codes at once, which are then displayed in the account console as a rather clunky long list.
Would it make sense to have support to use a collapsible list here that by default only shows that the user has backup codes registered?
E.g., something like the HTML details element would work here: [2]