Intune MAM SDK:如何在iOS和Android中获取用户ID?

时间:2018-09-10 19:40:28

标签: xamarin.forms intune upn

我正在使用Intune通过Company Portal应用程序注册该应用程序,现在我的问题是:如何在Xamarin Forms中获取当前用户ID(UPN /电子邮件)?

在Xamarin.iOS中,我使用的是Intune包装器,它可以与身份验证正常工作,但如何获得UPN?

在Xamarin.Android上,我已经这样做了:

我已使用SDK和MAM.Remapper工具按此处所述设置了项目。我还添加了一个从MAMApplication派生的新应用程序类。

在MainActivity中,我已经实现了OnMAMCreate,如下所示:

protected override async void OnMAMCreate(Bundle bundle)
{ 
    base.OnMAMCreate(bundle);
      Xamarin.Forms.Forms.Init(this, bundle);
      LoadApplication(new App());

      var userInfo = MAMComponents.GetUserInfo();
      var userEmail = userInfo.PrimaryUser; 
}

它总是给我错误,说MAMComponents没有GetUserInfo()这样的方法。我尝试在Assembly浏览器中进行挖掘,但在MAMComponents中找不到类似的内容。

Xamarin.Intunes与Intune集成完全没有在线帮助。

1 个答案:

答案 0 :(得分:1)

我在此方面找到了帮助,并且能够解决。首先,必须完成特定于平台的操作,这意味着Xamarin.forms的全球PCL项目什么也做不了。您需要将nuget包分别添加到Xamarin.forms的iOS和Android项目中。

在iOS上,将其添加到您的AppDelegate.cs:

string identity = null;
IntuneMAMEnrollmentManager.Instance.LoginAndEnrollAccount(identity);
IntuneMAMPolicyManager.Instance.IsIdentityManaged(IntuneMAMEnrollmentManager.Instance.EnrolledAccount);

在Entitlement.p列表中,启用Keychain并添加MAM和adalcache的两个组,如下所示:

enter image description here

在Main.cs或需要UPN的任何地方添加:

IntuneMAMPolicyManager.Instance.IsIdentityManaged(IntuneMAMEnrollmentManager.Instance.EnrolledAccount); 
string testUser = IntuneMAMEnrollmentManager.Instance.EnrolledAccount;

如果要在全局PCL项目中操作UPN,请使用“依赖关系服务”将数据发送到PCL。