Accounts count sets to 0 in MSAL, after the application auto update. (Windows)

Vaibhav Methuku 80 Reputation points
2024-06-08T09:03:40.0266667+00:00

Hello,

I hope this message finds you well. I am reaching out to report an issue I am encountering with MSAL authentication in my MAUI application, specifically related to the automatic update process using the embedded appinstaller.

Here is the scenario:

  1. Currently, I have version 1.0.0 of my MAUI application installed on my machine.
  2. Whenever an update is available on the server, the application automatically downloads and updates to the latest version.
  3. Let's say version 2.0.0 is available on the server, and my application updates successfully to this version.
  4. After the update to version 2.0.0, I can see the previously authenticated accounts within the application.
  5. However, upon closing and reopening the application after the update, the previously authenticated accounts are no longer visible.

This behavior is unexpected and disrupts the user experience, as users are required to log in again after each application update, even though they were previously authenticated.

I have followed the approach outlined in the Microsoft documentation on how to embed an appinstaller file for automatic updates, but it seems that the authentication state is not being preserved during the update process. [https://learn.microsoft.com/en-us/windows/msix/app-installer/how-to-embed-an-appinstaller-file]

Could you please assist me in resolving this issue? I would appreciate any guidance or suggestions on how to ensure that the MSAL authentication state is maintained across application updates.

Thank you for your attention to this matter. I look forward to your prompt response and assistance in resolving this issue.

FYI
User's image

I'm using this way for caching for windows.

if(Device.RuntimePlatform == Device.UWP)
{
	mPublicClientApplication = PublicClientApplicationBuilder.Create(options.ClientId)
													.WithAuthority(options.Authority)
													.WithRedirectUri(SpecialRedirectUri ?? $"msal{options.ClientId}://auth")
                                                    .WithWindowsEmbeddedBrowserSupport()

                                                    .Build();
	AttachTokenCache(mPublicClientApplication.UserTokenCache);
}

	private async Task AttachTokenCache(ITokenCache tokenCache)
	{
		string CacheFilePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\abccache\\msalcache.bin";
		StorageCreationProperties storageProperties = new StorageCreationPropertiesBuilder("abccache", CacheFilePath).Build();

		MsalCacheHelper msalcachehelper = await MsalCacheHelper.CreateAsync(storageProperties);
		msalcachehelper.RegisterCache(tokenCache);

	}

Thanks,
Vaibhav Methuku.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,185 questions
{count} votes