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
89 stars 25 forks source link

IntuneMAMAppConfig returns NULL value in IOS MAUI application #457

Open MikeP0911 opened 1 month ago

MikeP0911 commented 1 month 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 1 month 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 1 month 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 1 month 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 3 days 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 3 days 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.