第44章 通过GoogleAuthenticator插件执行登录操作
?119 CustomerChangeMultiFactorAuthenticationProviderEvent、MultiFactorAuthenticationProviderModel、MultiFactorAuthenticationModel
??? CustomerChangeMultiFactorAuthenticationProviderEvent類,“EventPublisher.PublishAsync”方法通過調用該類的實例,自動的從靜態緩存數據庫/分布式緩存數據庫中,移除與指定用戶多因素身份認證相關的一些緩存數據(不管這些緩存數據是否已經達到相應的緩存時間)。
??? MultiFactorAuthenticationProviderModel紀錄,通過紀錄及其成員,為多因素身份認組件在頁面中的綁定及其顯示提供數據支撐。
??? MultiFactorAuthenticationModel紀錄,通過紀錄及其成員,為我的多因素身份認證頁面的綁定及其顯示提供數據支撐。
2、取消Nop.Services.Customers.CustomerRegistrationService.ValidateCustomerAsync方法中對下列語句的注釋。??
var selectedProvider = await _genericAttributeService.GetAttributeAsync<string>(customer, NopCustomerDefaults.SelectedMultiFactorAuthenticationProviderAttribute);
??????????? var methodIsActive = await _multiFactorAuthenticationPluginManager.IsPluginActiveAsync(selectedProvider, customer, (await _storeContext.GetCurrentStoreAsync()).Id);
??????????? if (methodIsActive)
??????????????? return CustomerLoginResults.MultiFactorAuthenticationRequired;
2、重構Nop.Web.Infrastructure.RouteProvider.RegisterRoutes方法,取消對該方法中下列語句的注釋。
//我的多因素身份認證提供程序配置頁面的路由映射。
??????????? endpointRouteBuilder.MapControllerRoute(name: "CustomerMultiFactorAuthenticationProviderConfig",
??????????????? pattern: $"{lang}/customer/providerconfig",
??????????????? defaults: new { controller = "Customer", action = "ConfigureMultiFactorAuthenticationProvider" });
?? //我的多因素身份認證設定頁面的路由映射。
??????????? endpointRouteBuilder.MapControllerRoute(name: "MultiFactorAuthenticationSettings",
??????????????? pattern: $"{lang}/customer/multifactorauthentication",
3、重構Nop.Web.Factories.IcustomerModelFactory和Nop.Web.Factories.CustomerModelFactory,取消對下列方法的注釋:
PrepareMultiFactorAuthenticationModelAsync
PrepareMultiFactorAuthenticationProviderModelAsync
4、在Nop.Web.Controllers.CustomerController定義以下方法:
ParseSelectedProviderAsync
MultiFactorVerification
MultiFactorAuthentication
[HttpPost] MultiFactorAuthentication
ConfigureMultiFactorAuthenticationProvider
GoogleAuthenticator插件執行登錄操作
??? 1、按F5通過初始化安裝頁面,安裝數據庫及其默認數據。
2、通過后臺頁面“https://localhost:44303/Admin/Authentication/MultiFactorMethods”啟用GoogleAuthenticator插件,最終效果如下圖:
?
3、通過前臺頁面“https://localhost:44303/customer/multifactorauthentication”對GoogleAuthenticator插件進行配置,最終效果如下圖:
??? 注意:先點擊“保存”按鈕把當前面中的設置數據信息持久化保存到數據庫相應的表中。然后再點擊“配置”按鈕,以用于把當前程序與手機端“GoogleAuthenticator”進行綁定設定。
?4、通過前臺頁面“https://localhost:44303/customer/providerconfig?providerSysName=MultiFactorAuth.GoogleAuthenticator” 把當前程序與手機端“GoogleAuthenticator”app進行綁定設定,最終效果如下圖:
?
5、關閉整個瀏覽器,再重啟使用本地登錄后會直接跳轉到“GoogleAuthenticator”多因子身份認證頁面“https://localhost:44303/multi-factor-verification”,最終效果如下圖:
6、只有再次輸入手機端“GoogleAuthenticator”app中的“6”位數,才能訪問授權頁面。
??? 注意:因為授權頁面的訪問必須先登錄當前程序的注冊用戶,然后通過手機端“GoogleAuthenticator”app的身份認證后,才能被訪問,這就是“GoogleAuthenticator”被稱為多因素身份認證的原因。
對以上功能更為具體實現和注釋見:22-04-12-044_Nop_4.40.4(通過GoogleAuthenticator插件執行登錄操作)。
總結
以上是生活随笔為你收集整理的第44章 通过GoogleAuthenticator插件执行登录操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: left join 和 left se
- 下一篇: python opencv 边缘检测 抠