栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

第44章 通过GoogleAuthenticator插件执行登录操作

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

第44章 通过GoogleAuthenticator插件执行登录操作

 119 CustomerChangeMultiFactorAuthenticationProviderEvent、MultiFactorAuthenticationProviderModel、MultiFactorAuthenticationModel

    CustomerChangeMultiFactorAuthenticationProviderEvent类,“EventPublisher.PublishAsync”方法通过调用该类的实例,自动的从静态缓存数据库/分布式缓存数据库中,移除与指定用户多因素身份认证相关的一些缓存数据(不管这些缓存数据是否已经达到相应的缓存时间)。

    MultiFactorAuthenticationProviderModel纪录,通过纪录及其成员,为多因素身份认组件在页面中的绑定及其显示提供数据支撑。

    MultiFactorAuthenticationModel纪录,通过纪录及其成员,为我的多因素身份认证页面的绑定及其显示提供数据支撑。

  1. 取消Nop.Services.Installation.InstallationService.InstallSettingsAsync.MultiFactorAuthenticationSettings设置前的注释。

2、取消Nop.Services.Customers.CustomerRegistrationService.ValidateCustomerAsync方法中对下列语句的注释。  

var selectedProvider = await _genericAttributeService.GetAttributeAsync(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插件执行登录操作)。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/940762.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号