第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<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插件执行登录操作)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值