Last updated
Last updated
Two-factor authentication (2FA) for Umbraco members is activated by implementing an ITwoFactorProvider
interface and registering the implementation. The implementation can use third-party packages to archive for example support for authentication apps like Microsoft- or Google Authentication App.
If you are using , you can enable multi-factor authentication in Umbraco ID. For more information, see the article.
Since Umbraco does not control how the UI is for member login and profile edit, the UI for 2FA is shipped as part of the snippets for macros. These can be used as a starting point, before styling the page as you would like.
In the following example, we will use the . Despite the name, this package works for both Google and Microsoft authenticator apps and can be used to generate the QR code needed to activate the app for the website.
First, we create a model with the information required to set up the 2FA provider and then we implement the ITwoFactorProvider
with the use of the TwoFactorAuthenticator
from the GoogleAuthenticator NuGet package.
Now we need to register the UmbracoAppAuthenticator
implementation. This can be done on the IUmbracoBuilder
in your startup or a composer.
At this point, the 2FA is active, but no members have set up 2FA yet. The setup of 2FA depends on the type. In the case of App Authenticator, we will add the following to our view showing the edit profile of the member.
In this razor-code sample, we get the current member's unique key and list all registered ITwoFactorProvider
implementations.
If the setupData
is null
for the specified providerName
it means the provider is already set up. In this case, we show a disable button. Otherwise, we check the type and show the UI for how to set up the App Authenticator, by showing the QR Code and an input field to validate the code from the App Authenticator.
The last part required is to use the Login
Partial Macro snippet.
Umbraco controls how the UI is for user login and user edits, but will still need a view for configuring each 2FA provider.
First, we create a model with the information required to set up the 2FA provider and then we implement the ITwoFactorProvider
with the use of the TwoFactorAuthenticator
from the GoogleAuthenticator NuGet package.
Now we need to register the UmbracoUserAppAuthenticator
implementation and the view to show to set up this provider. This can be done on the IUmbracoBuilder
in your startup or a composer.
Now we need to create the view we just configured, in the path we choose.
As this view uses an angular controller, we need to create that class and configure it in the package.manifest
.
In package.manifest
, we point to the path of the angular controller that we are creating in the next step.
And we create the controller in that location:
At this point, the 2FA is active, but no users have set up 2FA yet.
Each user can now enable the configured 2fa providers on their user. This can be done from the user panel by clicking the user avatar.
When clicking the Configure Two-Factor
button, a new panel is shown, listing all enabled two-factor providers.
When clicking Enable
on one of these, the configured view for the specific provider will be shown
When the authenticator is enabled correctly, a disable button is shown instead.
To disable the two-factor authentication on your user, it is required to enter the verification code, otherwise, admins are allowed to disable providers on other users.
When a 2FA login is requested for a member, the MemberTwoFactorRequestedNotification
is published. This notification can also be used to send the member a one-time password via e-mail or phone. Even though these 2FA types are as App Authentication, it is still a massive improvement compared to no 2FA.
In the following example, we will use the . Despite the name, this package works for both Google and Microsoft authenticator apps and can be used to generate the QR code needed to activate the app for the website.
While the 2FA is enabled, the user will be presented with this screen after entering the username and password.
When a 2FA login is requested for a user, the UserTwoFactorRequestedNotification
is published. This notification can also be used to send the user a one-time password via e-mail or phone, even though these 2FA types are as App Authentication, it is still a massive improvement compared to no 2FA.
Umbraco users and members support a two-factor authentication (2FA) abstraction for implementing a 2FA provider of your choice