Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin with MSAL cannot save access token as Keychain Access Groups changed during Ad-Hoc provisioning

We have added the latest MSAL library to our Xamarin project and added the Keychain sharing capabilities to the entitlements plist:

enter image description here

The app builds ok on a developer machine and the app authenticates correctly against Azure AD B2C.

When we build through ADO and publish in App Center (Ad-Hoc provisioning) the app builds, and the appears to authenticate against the Azure AD B2C, but does not communicate with our other Azure resources (API, Storage, etc.) It appears that the Keychain access group is not found and whilst the authentication takes place normally MSAL fails to save the access token in the Key Chain.

iOSTokenCacheAccessor.Save (System.String account, System.String service, System.String generic, System.Int32 type, System.String value)

Microsoft.Identity.Client.MsalClientException: The application does not have keychain access groups enabled in the Entitlements.plist. As a result, there was a failure to save to the iOS keychain.

We think this is because during Ad-Hoc provisioning the app is re-signed after the device id has been included in the provisioning profile but the Ad-Hoc profile entitlements section only contain the [app id].* not the com.microsoft.adalcache value.

  1. Does the entitlements.plist get merged during build into the profile, i.e., Keychain Groups added to the entitlements section of the plist?
  2. If so, what does this and when does it happen in the build pipeline?
  3. How does Ad-Hoc provisioning work with this scenario?

Any help really appreciated as this is currently blocking our release.

like image 280
Magic Bullet Dave Avatar asked Dec 18 '18 08:12

Magic Bullet Dave


People also ask

Why does MSAL fail to save the Keychain Access token?

It appears that the Keychain access group is not found and whilst the authentication takes place normally MSAL fails to save the access token in the Key Chain. Microsoft.Identity.Client.MsalClientException: The application does not have keychain access groups enabled in the Entitlements.plist.

Does Xamarin support MSAL and keychain sharing?

Bookmark this question. Show activity on this post. We have added the latest MSAL library to our Xamarin project and added the Keychain sharing capabilities to the entitlements plist: The app builds ok on a developer machine and the app authenticates correctly against Azure AD B2C.

How do I share the token cache across multiple applications?

Starting in MSAL 2.x, you can specify a keychain access group to persist the token cache across multiple applications. This setting enables you to share the token cache among several applications that have the same keychain access group.

How to troubleshoot Keychain Access issues?

To troubleshoot, try to access the KeyChain on your own, for example: Starting in MSAL 2.x, you can specify a keychain access group to persist the token cache across multiple applications. This setting enables you to share the token cache among several applications that have the same keychain access group.


1 Answers

From MSAL 2.7.0, MSAL now resolves the TeamId at runtime. A new property iOSKeychainSecurityGroup should be used instead of KeychainSecurityGroup. More information can be found here. There was also a bug in AppCenter where they were using a wildcard in the Entitlements when they re-signed the app. This has been fixed as of 1/21.

like image 144
Jenny Avatar answered Oct 19 '22 00:10

Jenny