Xamarin 表单多重身份验证

Xamarin Forms Multi-Factor Authentication

需要在 iOS、Android 和 Windows UWP 的 Xamarin Forms 移动应用程序中进行多重身份验证。用户输入有效的用户名和密码后,应该有第二个因素 AUTH - phone call/SMS 到注册设备。分步指南和示例应用程序将有助于加快此方案的实施。

我想分享的实现之一:

  • Azure Active Directory 作为目录和 multi-factor 身份验证服务。您可以使用 Azure AD 帐户访问或将 Azure AD 与企业 Active Directory 域与 Active Directory 联合身份验证服务集成。在这里您可以获得帐户管理和 multi-factor 基础设施(phone 注册,call/SMS 服务和政策)
  • Active Directory Authentication Library (ADAL) 在 Xamarin Forms 应用程序中使用。
  • 在 Xamarin.Forms 应用程序中使用依赖服务来定义身份验证接口,例如:

    public interface IAuthenticator
    {
      Task<AuthenticationResult> Authenticate(string authority, string resource, string clientId, string returnUri);
    }
    
  • 为每个平台(here is all details)提供程序集依赖元数据属性的实现:

    [assembly: Dependency(typeof(MFATestPCL.Droid.Helper.Authenticator))]
    namespace MFATestPCL.Droid.Helper
    
  • 通过共享代码拨打电话:

    var auth = DependencyService.Get<IAuthenticator>();
    authResult = await auth.Authenticate(authority, graphResourceUri, clientId, returnUri);
    

此处提供了完整的 GitHub sample Xamarin app repo with step-by-step guide of configuring Azure AD – iOS、Android 和 Windows 10 个 UWP 实现。