应用程序未启用钥匙串访问组。

4
我们有一个Xamarin.Forms应用程序,尝试使用MSAL身份验证,在iOS项目中遇到了问题。它在模拟器中工作正常,但是当通过Azure管道构建并安装在真实的iPhone上时,会出现异常:
MSAL.Xamarin.iOS.4.14.0.MsalClient Exception: ErrorCode: missing_entitlements Microsoft.Identity.Client.MsalClientException: 应用程序在Entitlements.plist中未启用钥匙串访问组。因此,无法保存到iOS钥匙串。钥匙串访问组“OURID.com.microsoft.adalcache”未在Entitlements.plist中启用...
OURID当然是实际值的替代。
以下是我们在entitlements.plist中的内容:
 <key>keychain-access-groups</key>
  <array>
     <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
  </array>

在B2CAuthenticationService的构造函数中:

            var builder = PublicClientApplicationBuilder.Create(B2CConstants.ClientID)
            .WithB2CAuthority(B2CConstants.AuthoritySignInSignUp)
            .WithIosKeychainSecurityGroup(B2CConstants.IOSKeyChainGroup)
            .WithRedirectUri($"msal{B2CConstants.ClientID}://auth");

我可能会漏掉什么导致出现异常?

补充:如果我在管道中添加一个变量替换任务,即使这些任务只能替换xml和json配置文件中的值,也不能替换plist文件。


你是在真实设备还是模拟器上进行测试? - Ali Ahmad
@Ali Ahmad 两者都有。在模拟器上没有问题,异常只发生在真实的iPhone上。 - David Shochet
所以你正在使用一个配置文件来在iPhone上构建应用程序? - Ali Ahmad
@Ali Ahmad 是的,在Azure管道中可以这样做。 - David Shochet
让我们在聊天中继续这个讨论。 - Ali Ahmad
显示剩余2条评论
1个回答

5

我通过在文本编辑器中编辑项目并指定entitlements.plist来解决了这个问题。

    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>

在属性组内

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">

之前我通过项目GUI完成时,它仅影响了属性组。

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">

这就是为什么在模拟器上可以工作,但在真实设备上不能。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接