You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 13/umbraco-cms/reference/security/two-factor-authentication.md
+63-15Lines changed: 63 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,10 @@ description: >-
6
6
7
7
# Two-factor Authentication
8
8
9
-
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.
9
+
This article includes guides for implementing two-factor authentication options for both backoffice users and website members:
10
+
11
+
*[Two-Factor Authentication for Members](#two-factor-authentication-for-members)
12
+
*[Two-Factor Authentication for Users](#two-factor-authentication-for-users)
10
13
11
14
{% hint style="info" %}
12
15
@@ -16,11 +19,26 @@ If you are using [Umbraco Cloud](https://umbraco.com/products/umbraco-cloud/), y
16
19
17
20
## Two-factor authentication for Members
18
21
19
-
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.
22
+
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 support authentication apps like the Microsoft- or Google Authentication Apps.
20
23
21
-
### Example implementation for Authenticator Apps for Members
24
+
The following guide will take you through implementing an option for your website members to enable two-factor authentication.
22
25
23
-
In the following example, we will use the [GoogleAuthenticator NuGet Package](https://www.nuget.org/packages/GoogleAuthenticator/). Despite the name, this package works for both Google and Microsoft authenticator apps. It can be used to generate the QR code needed to activate the app for the website.
26
+
{% hint style="info" %}
27
+
A setup for members needs to be implemented on your website in order for you to follow this guide. This setup should include:
28
+
29
+
* Login and logout options.
30
+
* Public access restriction configured on at least 1 content item.
31
+
32
+
[Learn more about setting up a members section in Umbraco.](../../tutorials/members-registration-and-login.md)
33
+
{% endhint %}
34
+
35
+
As an example, the guide will use the [GoogleAuthenticator NuGet Package](https://www.nuget.org/packages/GoogleAuthenticator/). This package works for both Google and Microsoft authenticator apps. It can be used to generate the QR code needed to activate the app for the website.
36
+
37
+
1. Install the GoogleAuthenticator Nuget Package on your project.
38
+
2. Create a new file in your project: `QrCodeSetupData.cs`.
39
+
3. Update the file with the following code snippet.
@@ -111,15 +130,17 @@ public class UmbracoAppAuthenticator : ITwoFactorProvider
111
130
}
112
131
```
113
132
114
-
First, we create a model with the information required to set up the 2FA provider. Then we implement the `ITwoFactorProvider` with the use of the `TwoFactorAuthenticator` from the GoogleAuthenticator NuGet package.
133
+
{% endcode %}
134
+
135
+
4. Update `namespace` on line 7 to match your project.
136
+
5. Customize the `applicationName` variable on line 63.
137
+
6. Create a Composer and register the `UmbracoAppAuthenticator` implementation as shown below.
115
138
116
-
Now we need to register the `UmbracoAppAuthenticator` implementation. This can be done on the `IUmbracoBuilder` in your startup or a composer.
@@ -133,8 +154,18 @@ public class UmbracoAppAuthenticatorComposer : IComposer
133
154
}
134
155
```
135
156
157
+
{% endcode %}
158
+
136
159
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.
137
160
161
+
7. Add or choose a members-only page that should have the two-factor authentication setup.
162
+
* The page needs to be behind the public access.
163
+
* The page should not be using strongly types models.
@@ -182,11 +218,23 @@ At this point, the 2FA is active, but no members have set up 2FA yet. The setup
182
218
}
183
219
```
184
220
185
-
In this razor-code sample, we get the current member's unique key and list all registered `ITwoFactorProvider` implementations.
221
+
10.[Optional] Customize the text fields and buttons to match your websites tone of voice.
222
+
223
+
{% endcode %}
224
+
225
+

226
+
227
+
### Test the set up
228
+
229
+
1. Login to the website using a test member.
230
+
2. Navigate to the page where the QR code was added.
231
+
3. Scan the QR code and add the verification code.
232
+
4. Logout of the website.
233
+
5. Login and verify that it asks for the two factor authentication.
186
234
187
-
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. We will show the QR Code and an input field to validate the code from the App Authenticator.
235
+
You can also check that the **Two-factor Authentication** option is checked on the member in the Umbraco backoffice.
188
236
189
-
The last part required is to use the `Login` Partial Macro snippet.
237
+

190
238
191
239
### Notification when 2FA is requested for a member
0 commit comments