Skip to content

Commit 2a7b678

Browse files
committed
Update steps for the member guide
1 parent 5739b08 commit 2a7b678

File tree

4 files changed

+70
-26
lines changed

4 files changed

+70
-26
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ At this point, the 2FA is active, but no members have set up 2FA yet. The setup
218218
}
219219
```
220220

221-
10. [Optional] Customize the text fields and buttons to match your websites tone of voice.
222-
223221
{% endcode %}
224222

223+
10. [Optional] Customize the text fields and buttons to match your websites tone of voice.
224+
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

227227
### Test the set up for Members
Loading
Loading

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

+68-24
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,41 @@ description: >-
66

77
# Two-factor Authentication
88

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.
1015

1116
{% hint style="info" %}
1217
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.
1318
{% endhint %}
1419

1520
## Two-factor authentication for Members
1621

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.
1829

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 %}
2032

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.
2234

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.
2438

2539
{% code title="UmbracoAppAuthenticator.cs" lineNumbers="true" %}
40+
2641
```csharp
27-
using System;
28-
using System.Threading.Tasks;
2942
using Google.Authenticator;
43+
using System.Runtime.Serialization;
3044
using Umbraco.Cms.Core.Security;
3145
using Umbraco.Cms.Core.Services;
3246

@@ -35,17 +49,19 @@ namespace My.Website;
3549
/// <summary>
3650
/// Model with the required data to setup the authentication app.
3751
/// </summary>
38-
public class QrCodeSetupData
52+
53+
[DataContract]
54+
public class QrCodeSetupData : ISetupTwoFactorModel
3955
{
4056
/// <summary>
4157
/// The secret unique code for the user and this ITwoFactorProvider.
4258
/// </summary>
43-
public string Secret { get; init; }
59+
public string? Secret { get; init; }
4460

4561
/// <summary>
4662
/// The SetupCode from the GoogleAuthenticator code.
4763
/// </summary>
48-
public SetupCode SetupCode { get; init; }
64+
public SetupCode? SetupCode { get; init; }
4965
}
5066

5167
/// <summary>
@@ -82,14 +98,14 @@ public class UmbracoAppAuthenticator : ITwoFactorProvider
8298
/// <param name="userOrMemberKey">The key of the user or member</param>
8399
/// <param name="secret">The secret that ensures only this user can connect to the authenticator app</param>
84100
/// <returns>The required data to setup the authenticator app</returns>
85-
public Task<object> GetSetupDataAsync(Guid userOrMemberKey, string secret)
101+
public Task<ISetupTwoFactorModel> GetSetupDataAsync(Guid userOrMemberKey, string secret)
86102
{
87103
var member = _memberService.GetByKey(userOrMemberKey);
88104

89-
var applicationName = "My application name";
105+
var applicationName = "testingOn15";
90106
var twoFactorAuthenticator = new TwoFactorAuthenticator();
91107
SetupCode setupInfo = twoFactorAuthenticator.GenerateSetupCode(applicationName, member.Username, secret, false);
92-
return Task.FromResult<object>(new QrCodeSetupData()
108+
return Task.FromResult<ISetupTwoFactorModel>(new QrCodeSetupData()
93109
{
94110
SetupCode = setupInfo,
95111
Secret = secret
@@ -112,13 +128,15 @@ public class UmbracoAppAuthenticator : ITwoFactorProvider
112128
public bool ValidateTwoFactorSetup(string secret, string token) => ValidateTwoFactorPIN(secret, token);
113129
}
114130
```
115-
{% endcode %}
116131

117-
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 %}
118133

119-
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.
120137

121138
{% code title="UmbracoAppAuthenticatorComposer.cs" lineNumbers="true" %}
139+
122140
```csharp
123141
using Umbraco.Cms.Core.Composing;
124142
using Umbraco.Cms.Core.DependencyInjection;
@@ -135,15 +153,24 @@ public class UmbracoAppAuthenticatorComposer : IComposer
135153
}
136154
}
137155
```
156+
138157
{% endcode %}
139158

140-
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, add the following to the **view** showing the edit profile of the member.
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.
164+
8. Open the view file for the selected page.
165+
9. Add the following code:
166+
167+
{% code title="ExampleMemberPage.cshtml" lineNumbers="true" %}
141168

142169
```csharp
143-
@using Umbraco.Cms.Core.Services
144-
@using Umbraco.Cms.Web.Website.Controllers
145-
@using Umbraco.Cms.Web.Website.Models
146-
@using My.Website @* Or whatever your namespace with the QrCodeSetupData model is *@
170+
@using Umbraco.Cms.Core.Services;
171+
@using Umbraco.Cms.Web.Website.Controllers;
172+
@using Umbraco.Cms.Web.Website.Models;
173+
@using My.Website;
147174
@inject MemberModelBuilderFactory memberModelBuilderFactory
148175
@inject ITwoFactorLoginService twoFactorLoginService
149176
@{
@@ -160,6 +187,9 @@ At this point, the 2FA is active, but no members have set up 2FA yet. The setup
160187
foreach (var providerName in providerNames)
161188
{
162189
var setupData = await twoFactorLoginService.GetSetupInfoAsync(profileModel.Key, providerName);
190+
191+
// If the `setupData` is `null` for the specified `providerName` it means the provider is already set up.
192+
// In this case, a button to disable the authentication is shown.
163193
if (setupData is null)
164194
{
165195
@using (Html.BeginUmbracoForm<UmbTwoFactorLoginController>(nameof(UmbTwoFactorLoginController.Disable)))
@@ -168,6 +198,7 @@ At this point, the 2FA is active, but no members have set up 2FA yet. The setup
168198
<button type="submit">Disable @providerName</button>
169199
}
170200
}
201+
// If `setupData` is not `null` the type is checked and the UI for how to set up the App Authenticator is shown.
171202
else if(setupData is QrCodeSetupData qrCodeSetupData)
172203
{
173204
@using (Html.BeginUmbracoForm<UmbTwoFactorLoginController>(nameof(UmbTwoFactorLoginController.ValidateAndSaveSetup)))
@@ -186,11 +217,24 @@ At this point, the 2FA is active, but no members have set up 2FA yet. The setup
186217
}
187218
```
188219

189-
In this razor-code sample, we get the current member's unique key and list all registered `ITwoFactorProvider` implementations.
220+
{% endcode %}
221+
222+
10. Update the `@using` in line 4 to match the namespace of your project.
223+
11. [Optional] Customize the text fields and buttons to match your websites tone of voice (lines 33-39).
224+
225+
![The QR Code is shown along with a field to enter a value to set up the two factor authentication.](images/2fa-members-configuration.png)
226+
227+
### Test the set up for Members
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.
190234

191-
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.
192236

193-
The last part required is to use the `Login` Partial View snippet.
237+
![Check the Member profile in the Umbraco backoffice to verify whether two-factor authentication is enabeld.](images/2fa-member-backoffice.png)
194238

195239
### Notification when 2FA is requested for a member
196240

0 commit comments

Comments
 (0)