microsoftconnect / ms-intune-app-sdk-ios

Intune App SDK for iOS enables data protection and mobile app management features in iOS mobile apps with Microsoft Intune
91 stars 27 forks source link

IntuneMAMAppConfig returns NULL value in IOS MAUI application #457

Open MikeP0911 opened 4 months ago

MikeP0911 commented 4 months ago

We are trying to migrate our Xamarin IOS app to MAUI with MSAL integration. Intune logged in successfully and also acquiring access token, but while getting App config values from the Intune portal it returns NULL value, so we are unable to proceed further. This used to work properly in Xamarin.Forms.

Steps to reproduce the behavior:

  1. Create Maui application for IOS platform.
  2. Integrate MSAL in it.
  3. Try to get the AppConfig values from Intune using IntuneMAMAppConfig.
  4. It's not getting any values for given identity (Email) from Intune.

Expected behavior: IntuneMAMAppConfig for given identity should return corresponding AppConfig values.

Screenshots and logs: Please find below the corresponding code:

`
        public Dictionary<string, string> GetIntuneAppConfig()
        {
            Dictionary<string, string> AppConfig = new Dictionary<string, string>();
            try
            {
                LogManager.GetLogger(Constant.ZipLog).Debug(AppResources.processStart);
#if ANDROID
                IMAMAppConfigManager configManager = MAMComponents.Get<IMAMAppConfigManager>();
                IMAMAppConfig appConfig = null;

                if (GetAccountInfo().Email != null)
                {
                    appConfig = configManager.GetAppConfig(GetAccountInfo().Email);
                }
                if (appConfig == null)
                {
                    return AppConfig;
                }

                var fullData = appConfig.FullData;
                foreach (var i in fullData)
                {
                    foreach (string key in i.Keys)
                    {
                        string val = null;
                        i.TryGetValue(key, out val);

                        if (val is string)
                            AppConfig.Add(key, (string)(val as string));
                    }
                }
#elif IOS
                IntuneMAMAppConfig vals = IntuneMAMAppConfigManager.Instance.AppConfigForIdentity(GetAccountInfo().Email);
                var fullData = vals.FullData;
                foreach (var i in fullData)
                {
                    foreach (NSString key in i.Keys)
                    {
                        var val = i.ValueForKey(key);
                        if (val is NSString)
                        {
                            AppConfig.Add(key, (string)(val as NSString));

                        }
                    }
                }
#endif
                LogManager.GetLogger(Constant.ZipLog).Debug(AppResources.processEnd);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(Constant.ZipLog).Error(ex, AppResources.exceptionOccured);
            }
            return AppConfig;
        }

` Issue of getting NULL value screenshot is attached below:

IntuneAppconfigIssue

IntuneIssueCode

Smartphone:

Intune App SDK for iOS:

Additional context: Kindly share if any sample available for connecting with Intune (MSAL integration) in MAUI IOS app.

MikeP0911 commented 4 months ago

Hi @ChismanRaheem, I have included the corresponding code and the screenshots for your reference, kindly check it. Also included the version details in other info section, FYI.. Thanks.

ChismanRaheem commented 4 months ago

Hi @MikeP0911

It looks like you're encountering an issue where fullData is coming back null when using IntuneMAMAppConfigManager.Instance.AppConfigForIdentity(GetAccountInfo().Email) in your MAUI iOS application.

🛠️Here are a few things you might want to check:

  1. Ensure Correct Identity: Make sure that the email you're passing to AppConfigForIdentity is the correct managed user's UPN (User Principal Name). Sometimes, issues arise if the identity is not correctly specified.

  2. Check Intune Configuration: Verify that the Intune app configuration policy is correctly set up and assigned to the user or device. Missing or incorrect configurations can lead to null values being returned.

  3. IntuneMAMUPN Setting: Ensure that the IntuneMAMUPN setting is configured in the MDM app config policy. This setting helps the Intune SDK determine the device-managed user and include the MDM app config in the results.

Recommendation: Use a debugger to step through the code and inspect the value of the email variable before it is passed to AppConfigForIdentity. This will allow you to see the exact value being used. And if possible, please write a unite test to ensure that GetAccountInfo().Email returns the expected email address.

[!NOTE] Ref : https://learn.microsoft.com/en-us/mem/intune/apps/data-transfer-between-apps-manage-ios

MikeP0911 commented 4 months ago

Hi @ChismanRaheem

Thank you for the reply, we have IntuneMAMUPN setting already in Intune and also, we have value as proper email in GetAccountInfo().Email method. After going through your steps mentioned above, again rechecked and everything seems to be proper (IntuneMAMUPN keyvalue in configuration and email we are passing to AppConfigForIdentity method), but still, it's not retrieving Appconfig values from Intune in MAUI code. Not sure what went wrong, kindly check this..

Also, kindly share if any sample available for connecting with Intune (MSAL integration) in MAUI IOS app for our reference. Thanks again.

MikeP0911 commented 2 months ago

Hi @ChismanRaheem Any update on this? Kindly share if any sample available for connecting with Intune (MSAL integration) in MAUI IOS app for our reference.

MikeP0911 commented 2 months ago

Hi @ChismanRaheem to add with the existing issue in MAUI, after updating to latest Intune SDK(version-19.5.0), the method- "public virtual IntuneMAMAppConfig AppConfigForIdentity(string? identity)" is deprecated in IntuneMAMAppConfigManager class and asked to use the new method instead- "public virtual IntuneMAMAppConfig AppConfigForAccountId(string? accountId)" which is also failing to get the AppConfig values from Intune.

So please check this and update as it is a blocker for us. Thanks.

ChismanRaheem commented 2 months ago

HI @MikeP0911 ,

Thank you for the update we are currently investigating. As for the recommended sample there isn’t a dedicated sample for integrating the Intune SDK with .NET MAUI for Android. However, you can adapt the existing Intune SDK for Android to work with your .NET MAUI project by following the general guidelines for integrating the SDK into Android applications.

For Integrating the Intune SDK with Maui and IOS please use this sample https://github.com/microsoftconnect/sample-intune-maui-ios.git. This sample uses MSAL to authenticate users while integrating with Intune SDK for Maui iOS

MikeP0911 commented 2 months ago

Hi @ChismanRaheem, Thanks for the reply.

Also, thanks for providing MAUI sample but we have already referred it for MSAL integration in MAUI. Since the issue is with the latest Intune SDK (version-19.5.0) where the register & deregister methods are deprecated with (IntuneMAMEnrollmentManager.Instance.EnrolledAccount) and there is an issue with the alternative methods mentioned, it would be helpful if you share any sample with the latest Intune version for IOS platform(we have already released Android version of our MAUI app, so no problem in it!!). Also, Appconfig method fails with NULL value in this latest version too, so kindly help to resolve this.

Thanks again..

ChismanRaheem commented 2 months ago

Hi @MikeP0911

Please validate if the app successfully enrolled before the app attempts to query for app config. Also, when you have time can you generate and upload the MAM SDK logs? Note you that you can have someone from your developer team collect them by calling IntuneMAMDiagnosticConsole.DisplayDiagnosticConsole() to get the same MAM diagnostic log collection available in Edge for Microsoft apps.

ref :https://learn.microsoft.com/en-us/mem/intune/apps/manage-microsoft-edge#use-microsoft-edge-to-access-managed-app-logs

MikeP0911 commented 2 months ago

@ChismanRaheem - Thanks for the suggestion, sure will check this and get back to you soon.