Skip to content

Commit 5b7aa5d

Browse files
committed
Update steps for user 2fa
1 parent 6fd9f5b commit 5b7aa5d

File tree

2 files changed

+73
-33
lines changed

2 files changed

+73
-33
lines changed
14.4 KB
Loading

13/umbraco-cms/reference/security/two-factor-authentication.md

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This article includes guides for implementing two-factor authentication options
1111
* [Two-Factor Authentication for Members](#two-factor-authentication-for-members)
1212
* [Two-Factor Authentication for Users](#two-factor-authentication-for-users)
1313

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.
15+
1416
{% hint style="info" %}
1517

1618
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.
@@ -19,8 +21,6 @@ If you are using [Umbraco Cloud](https://umbraco.com/products/umbraco-cloud/), y
1921

2022
## Two-factor authentication for Members
2123

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.
23-
2424
The following guide will take you through implementing an option for your website members to enable two-factor authentication.
2525

2626
{% hint style="info" %}
@@ -224,7 +224,7 @@ At this point, the 2FA is active, but no members have set up 2FA yet. The setup
224224

225225
![The QR Code is shown along with a field to enter a value to set up the two factor authentication.](images/2fa-Members-QR-code.png)
226226

227-
### Test the set up
227+
### Test the set up for Members
228228

229229
1. Login to the website using a test member.
230230
2. Navigate to the page where the QR code was added.
@@ -242,11 +242,19 @@ When a 2FA login is requested for a member, the `MemberTwoFactorRequestedNotific
242242

243243
## Two-factor authentication for Users
244244

245-
Umbraco controls how the UI is for user login and user edits, but will still need a view for configuring each 2FA provider.
245+
The following guide will take you through implementing an option for backoffice users to enable two-factor authentication.
246+
247+
This guide will not cover setting up the UI for user login and edits as this is handled elsewhere in the CMS.
246248

247249
### Example implementation for Authenticator Apps for Users
248250

249-
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.
251+
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.
252+
253+
1. Install the GoogleAuthenticator Nuget Package on your project.
254+
2. Create a new file in your project: `TwoFactorAuthInfo.cs`.
255+
3. Update the file with the following code snippet.
256+
257+
{% code title="TwoFactorAuthInfo.cs" lineNumbers="true" %}
250258

251259
```csharp
252260
using System.Runtime.Serialization;
@@ -257,6 +265,9 @@ using Umbraco.Cms.Core.Services;
257265

258266
namespace My.Website;
259267

268+
/// <summary>
269+
/// Create a model with the information required to set up the 2FA provider
270+
/// </summary>
260271
[DataContract]
261272
public class TwoFactorAuthInfo
262273
{
@@ -268,7 +279,7 @@ public class TwoFactorAuthInfo
268279
}
269280

270281
/// <summary>
271-
/// App Authenticator implementation of the ITwoFactorProvider
282+
/// Implement the `ITwoFactorProvider` with the use of the `TwoFactorAuthenticator` from the GoogleAuthenticator NuGet package
272283
/// </summary>
273284
public class UmbracoUserAppAuthenticator : ITwoFactorProvider
274285
{
@@ -307,8 +318,9 @@ public class UmbracoUserAppAuthenticator : ITwoFactorProvider
307318

308319
ArgumentNullException.ThrowIfNull(user);
309320

321+
var applicationName = "My application name";
310322
var twoFactorAuthenticator = new TwoFactorAuthenticator();
311-
SetupCode setupInfo = twoFactorAuthenticator.GenerateSetupCode("My application name", user.Username, secret, false);
323+
SetupCode setupInfo = twoFactorAuthenticator.GenerateSetupCode(applicationName, user.Username, secret, false);
312324
return Task.FromResult<object>(new TwoFactorAuthInfo()
313325
{
314326
QrCodeSetupImageUrl = setupInfo.QrCodeSetupImageUrl,
@@ -333,17 +345,19 @@ public class UmbracoUserAppAuthenticator : ITwoFactorProvider
333345
}
334346
```
335347

336-
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.
348+
{% endcode %}
349+
350+
4. Update `namespace` on line 7 to match your project.
351+
5. Customize the `applicationName` variable on line 59.
352+
6. Create a new file in your project: `UmbracoAppAuthenticatorComposer.cs`.
353+
7. Implement a new composer and register the `UmbracoAppAuthenticator` implementation as shown below.
337354

338-
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.
355+
{% code title="UmbracoAppAuthenticatorComposer.cs" lineNumbers="true" %}
339356

340357
```csharp
341-
using Microsoft.Extensions.DependencyInjection;
342358
using Umbraco.Cms.Core.Composing;
343-
using Umbraco.Cms.Core.DependencyInjection;
344359
using Umbraco.Cms.Core.Security;
345360
using Umbraco.Cms.Web.BackOffice.Security;
346-
using Umbraco.Extensions;
347361

348362
namespace My.Website;
349363

@@ -363,7 +377,18 @@ public class UmbracoAppAuthenticatorComposer : IComposer
363377
}
364378
```
365379

366-
Now we need to create the view we configured, in the path we choose.
380+
{% endcode %}
381+
382+
8. Update the `namespace` on line 5 to match your project.
383+
384+
In the composer above, a view for the two-factor authentication is configured. This view needs to be created.
385+
386+
9. Open the project directory.
387+
10. Locate or create the path as defined in the composer above: `App_Plugins\TwoFactorProviders`.
388+
11. Create a new file: `twoFactorProviderGoogleAuthenticator.html`.
389+
12. Open the file and add the following markup:
390+
391+
{% code title="twoFactorProviderGoogleAuthenticator.html" lineNumbers="true" %}
367392

368393
```html
369394
<div ng-controller="CustomCode.TwoFactorProviderGoogleAuthenticator as vm">
@@ -430,19 +455,14 @@ Now we need to create the view we configured, in the path we choose.
430455
</div>
431456
```
432457

433-
As this view uses an angular controller, we need to create that class and configure it in the `package.manifest`.
458+
{% endcode %}
434459

435-
In `package.manifest`, we point to the path of the angular controller that we are creating in the next step.
460+
The view above uses an Angular controller, which needs to be created and configured in a `package.manifest` file.
436461

437-
```json
438-
{
439-
"javascript": [
440-
"~/App_Plugins/TwoFactorProviders/twoFactorProviderGoogleAuthenticator.controller.js"
441-
]
442-
}
443-
```
462+
13. Create a new file: `App_Plugins/TwoFactorProviders/twoFactorProviderGoogleAuthenticator.controller.js`.
463+
14. Add the following code:
444464

445-
And we create the controller in that location:
465+
{% code title="twoFactorProviderGoogleAuthenticator.controller.js" lineNumbers="true" %}
446466

447467
```javascript
448468
!(function () {
@@ -514,29 +534,49 @@ And we create the controller in that location:
514534
})();
515535
```
516536
517-
At this point, the 2FA is active, but no users have set up 2FA yet.
537+
{% endcode %}
538+
539+
15. Create a new file: `App_Plugins\TwoFactorProviders\package.manifest`.
540+
16. Point to the path of the Angular controller created above:
518541
519-
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.
542+
{% code title="package.manifest" lineNumbers="true" %}
543+
544+
```json
545+
{
546+
"javascript": [
547+
"~/App_Plugins/TwoFactorProviders/twoFactorProviderGoogleAuthenticator.controller.js"
548+
]
549+
}
550+
```
551+
552+
{% endcode %}
553+
554+
At this point, the 2FA is active, but no users have set it up.
555+
556+
### Test the set up for Users
557+
558+
Each user can now enable the configured 2fa providers on their user.
559+
560+
1. Access the Umbraco backoffice.
561+
2. Click the user avatar in the top-right corner.
520562
521563
![User panel](images/user-panel.png)
522564
523-
When clicking the `Configure Two-Factor` button, a new panel is shown, listing all enabled two-factor providers.
565+
3. Select `Configure Two-Factor` button to open a new panel listing all enabled two-factor providers.
524566
525567
![Configure 2fa](images/configure-2fa.png)
526568
527-
When clicking `Enable` on one of these, the configured view for the specific provider will be shown
569+
4. Select `Enable` to show the configured view.
528570
529571
![Enable 2fa](images/enable-2fa.png)
530572
531-
When the authenticator is enabled correctly, a disable button is shown instead.
573+
5. Follow the instructions to configure 2FA.
532574
533-
![Disable 2fa](images/disable-2fa.png)
534-
535-
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.
575+
When the authenticator is enabled correctly, a disable button is shown instead.
536576
537-
![Verify disable](images/verify-disable.png)
577+
![Disable 2fa](images/2fa-user-disable.png)
538578
539-
If the code is correct, the provider is disabled.
579+
To disable the two-factor authentication on your user, it is required to enter the verification code.
540580
541581
### Notification when 2FA is requested for a user
542582

0 commit comments

Comments
 (0)