From 64f8c127a42d93dc547df1d2c77cf975387e8c33 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 7 Oct 2025 12:35:14 +0100 Subject: [PATCH 1/5] Update two-factor-authentication.md Updated members two factor example code for Umbraco v16 --- .../security/two-factor-authentication.md | 67 +++++++++++-------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/16/umbraco-cms/reference/security/two-factor-authentication.md b/16/umbraco-cms/reference/security/two-factor-authentication.md index bc8e437faac..4af6713342b 100644 --- a/16/umbraco-cms/reference/security/two-factor-authentication.md +++ b/16/umbraco-cms/reference/security/two-factor-authentication.md @@ -100,7 +100,7 @@ public class UmbracoAppAuthenticator : ITwoFactorProvider /// The required data to setup the authenticator app public Task GetSetupDataAsync(Guid userOrMemberKey, string secret) { - var member = _memberService.GetByKey(userOrMemberKey); + var member = _memberService.GetById(userOrMemberKey); var applicationName = "testingOn15"; var twoFactorAuthenticator = new TwoFactorAuthenticator(); @@ -175,45 +175,58 @@ If you already have a members-only page with the edit profile options, you can s @using Umbraco.Cms.Web.Website.Controllers; @using Umbraco.Cms.Web.Website.Models; @using My.Website; -@inject MemberModelBuilderFactory memberModelBuilderFactory -@inject ITwoFactorLoginService twoFactorLoginService +@inject MemberModelBuilderFactory MemberModelBuilderFactory +@inject IMemberTwoFactorLoginService MemberTwoFactorLoginService @{ // Build a profile model to edit - var profileModel = await memberModelBuilderFactory - .CreateProfileModel() - .BuildForCurrentMemberAsync(); + var profileModel = await MemberModelBuilderFactory + .CreateProfileModel() + .BuildForCurrentMemberAsync(); + + List? providerNameList = null; + if (profileModel != null) + { + var providerNamesAttempt = await MemberTwoFactorLoginService.GetProviderNamesAsync(profileModel.Key); + + if (providerNamesAttempt.Success) + { + providerNameList = providerNamesAttempt.Result.ToList(); + } + } // Show all two factor providers - var providerNames = twoFactorLoginService.GetAllProviderNames(); - if (providerNames.Any()) + if (providerNameList != null && providerNameList.Any()) {
- foreach (var providerName in providerNames) - { - var setupData = await twoFactorLoginService.GetSetupInfoAsync(profileModel.Key, providerName); + foreach (var provider in providerNameList) + {0 + var setupData = await MemberTwoFactorLoginService.GetSetupInfoAsync(profileModel.Key, provider.ProviderName); - // If the `setupData` is `null` for the specified `providerName` it means the provider is already set up. - // In this case, a button to disable the authentication is shown. - if (setupData is null) + // If the `setupData.Success` is `true` for the specified `providerName` it means the provider is not set up. + if (setupData.Success) { - @using (Html.BeginUmbracoForm(nameof(UmbTwoFactorLoginController.Disable))) + if (setupData.Result is QrCodeSetupData qrCodeSetupData) { - - + @using (Html.BeginUmbracoForm(nameof(UmbTwoFactorLoginController.ValidateAndSaveSetup))) + { +

Setup @providerName

+ +

Scan the code above with your authenticator app
and enter the resulting code here to validate:

+ + + + + } } } - // If `setupData` is not `null` the type is checked and the UI for how to set up the App Authenticator is shown. - else if(setupData is QrCodeSetupData qrCodeSetupData) + // If `setupData.Success` is `false` the provider is already setup. + // In this case, a button to disable the authentication is shown. + else { - @using (Html.BeginUmbracoForm(nameof(UmbTwoFactorLoginController.ValidateAndSaveSetup))) + @using (Html.BeginUmbracoForm(nameof(UmbTwoFactorLoginController.Disable))) { -

Setup @providerName

- -

Scan the code above with your authenticator app
and enter the resulting code here to validate:

- - - - + + } } } From 0391c156fd406bdcabd6f85ea37172eda2fb3b26 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 20 Oct 2025 15:06:04 +0100 Subject: [PATCH 2/5] Update 16/umbraco-cms/reference/security/two-factor-authentication.md Co-authored-by: Esha Noronha <82437098+eshanrnh@users.noreply.github.com> --- 16/umbraco-cms/reference/security/two-factor-authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/16/umbraco-cms/reference/security/two-factor-authentication.md b/16/umbraco-cms/reference/security/two-factor-authentication.md index 4af6713342b..43e45ada5fe 100644 --- a/16/umbraco-cms/reference/security/two-factor-authentication.md +++ b/16/umbraco-cms/reference/security/two-factor-authentication.md @@ -199,7 +199,7 @@ If you already have a members-only page with the edit profile options, you can s {
foreach (var provider in providerNameList) - {0 + { var setupData = await MemberTwoFactorLoginService.GetSetupInfoAsync(profileModel.Key, provider.ProviderName); // If the `setupData.Success` is `true` for the specified `providerName` it means the provider is not set up. From 774305730bdc4c786c31496b7de967a336354c64 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 20 Oct 2025 15:10:33 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Esha Noronha <82437098+eshanrnh@users.noreply.github.com> --- .../reference/security/two-factor-authentication.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/16/umbraco-cms/reference/security/two-factor-authentication.md b/16/umbraco-cms/reference/security/two-factor-authentication.md index 43e45ada5fe..f03e092c442 100644 --- a/16/umbraco-cms/reference/security/two-factor-authentication.md +++ b/16/umbraco-cms/reference/security/two-factor-authentication.md @@ -209,10 +209,10 @@ If you already have a members-only page with the edit profile options, you can s { @using (Html.BeginUmbracoForm(nameof(UmbTwoFactorLoginController.ValidateAndSaveSetup))) { -

Setup @providerName

+

Setup @provider.ProviderName

Scan the code above with your authenticator app
and enter the resulting code here to validate:

- + @@ -225,8 +225,8 @@ If you already have a members-only page with the edit profile options, you can s { @using (Html.BeginUmbracoForm(nameof(UmbTwoFactorLoginController.Disable))) { - - + + } } } From 195217b9a6dfb88f0290b135cc3beff637ed8941 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 20 Oct 2025 15:11:42 +0100 Subject: [PATCH 4/5] Update two-factor-authentication.md --- 16/umbraco-cms/reference/security/two-factor-authentication.md | 1 + 1 file changed, 1 insertion(+) diff --git a/16/umbraco-cms/reference/security/two-factor-authentication.md b/16/umbraco-cms/reference/security/two-factor-authentication.md index f03e092c442..a5f27fe1c89 100644 --- a/16/umbraco-cms/reference/security/two-factor-authentication.md +++ b/16/umbraco-cms/reference/security/two-factor-authentication.md @@ -173,6 +173,7 @@ If you already have a members-only page with the edit profile options, you can s ```csharp @using Umbraco.Cms.Core.Services; @using Umbraco.Cms.Web.Website.Controllers; +@using Umbraco.Cms.Core.Services; @using Umbraco.Cms.Web.Website.Models; @using My.Website; @inject MemberModelBuilderFactory MemberModelBuilderFactory From 3c3c821dc838c6b43716b399627d3b956d8b56ff Mon Sep 17 00:00:00 2001 From: Esha Noronha <82437098+eshanrnh@users.noreply.github.com> Date: Tue, 21 Oct 2025 09:33:01 +0200 Subject: [PATCH 5/5] Update 16/umbraco-cms/reference/security/two-factor-authentication.md --- 16/umbraco-cms/reference/security/two-factor-authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/16/umbraco-cms/reference/security/two-factor-authentication.md b/16/umbraco-cms/reference/security/two-factor-authentication.md index a5f27fe1c89..aab07d6193b 100644 --- a/16/umbraco-cms/reference/security/two-factor-authentication.md +++ b/16/umbraco-cms/reference/security/two-factor-authentication.md @@ -173,7 +173,7 @@ If you already have a members-only page with the edit profile options, you can s ```csharp @using Umbraco.Cms.Core.Services; @using Umbraco.Cms.Web.Website.Controllers; -@using Umbraco.Cms.Core.Services; +@using Umbraco.Cms.Core.Models; @using Umbraco.Cms.Web.Website.Models; @using My.Website; @inject MemberModelBuilderFactory MemberModelBuilderFactory