diff --git a/16/umbraco-cms/reference/security/two-factor-authentication.md b/16/umbraco-cms/reference/security/two-factor-authentication.md index bc8e437faac..aab07d6193b 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(); @@ -173,47 +173,61 @@ 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.Models; @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) + foreach (var provider in providerNameList) { - var setupData = await twoFactorLoginService.GetSetupInfoAsync(profileModel.Key, providerName); + 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 @provider.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:

- - - - + + } } }