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: 15/umbraco-cms/reference/security/two-factor-authentication.md
+113-38
Original file line number
Diff line number
Diff line change
@@ -6,27 +6,41 @@ 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)
13
+
14
+
Two-factor authentication (2FA) for Umbraco Users and 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.
10
15
11
16
{% hint style="info" %}
12
17
If you are using [Umbraco Cloud](https://umbraco.com/products/umbraco-cloud/), you can enable multi-factor authentication in Umbraco ID. For more information, see the [Multi-Factor Authentication](https://docs.umbraco.com/umbraco-cloud/set-up/multi-factor-authentication-on-cloud) article.
13
18
{% endhint %}
14
19
15
20
## Two-factor authentication for Members
16
21
17
-
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 Partial View snippets. These can be used as a starting point, before styling the page as you would like.
22
+
The following guide will take you through implementing an option for your website members to enable two-factor authentication.
23
+
24
+
{% hint style="info" %}
25
+
A setup for members needs to be implemented on your website in order for you to follow this guide. This setup should include:
26
+
27
+
* Login and logout options.
28
+
* Public access restriction configured on at least 1 content item.
18
29
19
-
### Example implementation for Authenticator Apps for Members
30
+
[Learn more about setting up a members section in Umbraco.](../../tutorials/members-registration-and-login.md)
31
+
{% endhint %}
20
32
21
-
In the following example, we will use the [GoogleAuthenticator NuGet Package](https://www.nuget.org/packages/GoogleAuthenticator/).
33
+
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.
22
34
23
-
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.
35
+
1. Install the GoogleAuthenticator Nuget Package on your project.
36
+
2. Create a new file in your project: `UmbracoAppAuthenticator.cs`.
37
+
3. Update the file with the following code snippet.
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.
132
+
{% endcode %}
117
133
118
-
Now we need to register the `UmbracoAppAuthenticator` implementation. This can be done on the `IUmbracoBuilder` in your startup or a composer.
134
+
4. Update `namespace` on line 7 to match your project.
135
+
5. Customize the `applicationName` variable on line 64.
136
+
6. Create a Composer and register the `UmbracoAppAuthenticator` implementation as shown below.
@@ -134,15 +153,28 @@ public class UmbracoAppAuthenticatorComposer : IComposer
134
153
}
135
154
}
136
155
```
156
+
137
157
{% endcode %}
138
158
139
-
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.
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, the **view** showing the option to edit member profiles needs to be modified.
160
+
161
+
{% hint style="info" %}
162
+
If you already have a members-only page with the edit profile options, you can skip directly to step 8.
163
+
{% endhint %}
164
+
165
+
7. Add or choose a members-only page that should have the two-factor authentication setup.
166
+
* The page needs to be behind the public access.
167
+
* The page should **not** be using strongly types models.
@@ -185,25 +221,45 @@ At this point, the 2FA is active, but no members have set up 2FA yet. The setup
185
221
}
186
222
```
187
223
188
-
In this razor-code sample, we get the current member's unique key and list all registered `ITwoFactorProvider` implementations.
224
+
{% endcode %}
225
+
226
+
10. Update the `@using` in line 4 to match the namespace of your project.
227
+
11.[Optional] Customize the text fields and buttons to match your websites tone of voice (lines 33-39).
228
+
229
+

230
+
231
+
### Test the set up for Members
189
232
190
-
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.
233
+
1. Login to the website using a test member.
234
+
2. Navigate to the page where the QR code was added.
235
+
3. Scan the QR code and add the verification code.
236
+
4. Logout of the website.
237
+
5. Login and verify that it asks for the two factor authentication.
191
238
192
-
The last part required is to use the `Login` Partial View snippet.
239
+
You can also check that the **Two-factor Authentication** option is checked on the member in the Umbraco backoffice.
240
+
241
+

193
242
194
243
### Notification when 2FA is requested for a member
195
244
196
245
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 [not considered secure](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/mfa?view=aspnetcore-6.0#mfa-sms) as App Authentication, it is still a massive improvement compared to no 2FA.
197
246
198
247
## Two-factor authentication for Users
199
248
200
-
Umbraco controls how the UI is for user login and user edits, but will still need a view for configuring each 2FA provider.
249
+
The following guide will take you through implementing an option for backoffice users to enable two-factor authentication.
250
+
251
+
This guide will not cover setting up the UI for user login and edits as this is handled elsewhere in the CMS.
201
252
202
253
### Example implementation for Authenticator Apps for Users
203
254
204
-
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.
255
+
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.
256
+
257
+
1. Install the GoogleAuthenticator Nuget Package on your project.
258
+
2. Create a new file in your project: `UmbracoUserAppAuthenticator.cs`.
259
+
3. Update the file with the following code snippet.
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.
351
+
4. Update `namespace` on line 7 to match your project.
352
+
5. Customize the `applicationName` variable on line 59.
353
+
6. Create a new file in your project: `UmbracoUserAppAuthenticatorComposer.cs`.
354
+
7. Implement a new composer and register the `UmbracoUserAppAuthenticator` implementation as shown below.
294
355
295
-
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.
@@ -311,11 +371,18 @@ public class UmbracoAppAuthenticatorComposer : IComposer
311
371
}
312
372
}
313
373
```
374
+
314
375
{% endcode %}
315
376
316
-
The last thing required is to register the provider in the Backoffice client so that the user can enable it. This can be done in a `umbraco-package.json` file.
377
+
8. Update the `namespace` on line 4 to match your project.
378
+
379
+
With the 2FA in place, the provider needs to be registered in the backoffice client so the user can use it.
380
+
381
+
9. Add a new file to your project directory: `~/App_Plugins/TwoFactorProviders/umbraco-package.json`.
@@ -334,27 +401,35 @@ The last thing required is to register the provider in the Backoffice client so
334
401
]
335
402
}
336
403
```
404
+
337
405
{% endcode %}
338
406
339
407
At this point, the 2FA is active, but no users have set up 2FA yet.
340
408
341
-
* 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.
409
+
### Test the set up for Users
410
+
411
+
Each user can now enable the configured 2FA providers on their user.
412
+
413
+
1. Access the Umbraco backoffice.
414
+
2. Click the user avatar in the top-right corner.
342
415
343
416

344
417
345
-
* When clicking the `Configure Two-Factor` button, a new panel is shown, listing all enabled two-factor providers.
418
+
3. Select `Configure Two-Factor` button to get a list of all enabled two-factor providers.
346
419
347
420

348
421
349
-
* When clicking `Enable`on one of these, the configured view for the specific provider will be shown
422
+
4. Select `Enable`to show the configured view.
350
423
351
424

352
425
353
-
* When the authenticator is enabled correctly, a disable button is shown instead.
426
+
5. Follow the instructions to configure 2FA.
427
+
428
+
When the authenticator is enabled correctly, a disable button is shown instead.
354
429
355
430

356
431
357
-
*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.
432
+
To disable the two-factor authentication on your user, it is required to enter the verification code.
0 commit comments