Intune MAM SDK: How to get user-ID in iOS and Android?

1.5k Views Asked by At

I am using Intune for enrolling the app through the Company Portal app, and now my question is: How do I get the current users ID (UPN/e-mail) in Xamarin Forms?

In Xamarin.iOS I am using the Intune Wrappers and it works fine with the Authentication but How do I get the UPN?

On Xamarin.Android I have done this:

I’ve setup the project as described here using the SDK and the MAM.Remapper tool. I also added a new application class deriving from MAMApplication.

In my MainActivity I’ve implemented OnMAMCreate like this:

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; 
}

It keeps giving me error saying that the MAMComponents has no such method as GetUserInfo(). I tried digging around in the Assembly browser and did not find anything similar in MAMComponents.

There is no help online at all on Xamarin.Forms integration with Intune.

1

There are 1 best solutions below

0
On BEST ANSWER

I found help on this and was able to figure it out. First this has to be done platform specific which means the global PCL project of Xamarin.forms can do nothing. You need to add the nuget packages to the iOS and Android projects of Xamarin.forms separately.

On iOS add this to your AppDelegate.cs:

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

In the Entitlement.plist Enable Keychain and add the two groups for MAM and adalcache as shown:

enter image description here

In your Main.cs or any place that you need the UPN add:

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

If you wish to manipulate the UPN in the global PCL project the use Dependency Service to send the data to the PCL.