该应用程序无法访问Xamarin.Forms中的iOS钥匙串,但可以在Android中使用 [英] The application cannot access the iOS keychain in Xamarin.Forms but works in Android

查看:66
本文介绍了该应用程序无法访问Xamarin.Forms中的iOS钥匙串,但可以在Android中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在学习使用MSAL,但遇到了有线问题.我完全按照教程,而我正在使用示例代码.但是我仍然在构建 App.xaml.cs 中的客户端时遇到了此异常:

Hello I am learning using MSAL but met a wired issue. I totally followed the tutorial, and I am using the sample code. But I still got this exception building the client in App.xaml.cs:

microsoft.identity.client.msalclientexception:应用程序无法访问应用程序发布者的ios钥匙串(团队ID为空值).这是启用以下应用程序之间的单点登录所必需的相同的发布者.这是一个ios配置问题.看 https://aka.ms/msal-net-enable-keychain-access有关更多详细信息启用钥匙串访问.

microsoft.identity.client.msalclientexception: the application cannot access the ios keychain for the application publisher (the team id is null). this is needed to enable single sign on between applications of the same publisher. this is an ios configuration issue. see https://aka.ms/msal-net-enable-keychain-access for more details on enabling keychain access.

AuthenticationClient = PublicClientApplicationBuilder.Create(Constants.ClientId)
                .WithIosKeychainSecurityGroup(Constants.IosKeychainSecurityGroups)
                .WithB2CAuthority(Constants.AuthoritySignin)
                .WithRedirectUri($"msal{Constants.ClientId}://auth")
                .Build();

相对设置如下:

info.plist:

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>ADB2C Auth</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>msal....</string>
            </array>
            <key>CFBundleTypeRole</key>
            <string>None</string>
        </dict>
        <dict>
            <key>CFBundleURLName</key>
            <string>URL Type 1</string>
        </dict>
    </array>

Contants.cs中的iOS钥匙串:

 // set to a unique value for your app, such as your bundle identifier. Used on iOS to share keychain access.
        static readonly string iosKeychainSecurityGroup = "com.xamarin.adb2cauthorization";

Entitlements.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)com.xamarin.adb2cauthorization</string>
    </array>
</dict>
</plist>

AppDelegate:

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
        {
            AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(url);
            return base.OpenUrl(app, url, options);
        }

我试图将Microsoft.Identity.Client升级到v4.17.1,但仍无法正常工作.由于共享代码适用于Android部分,因此我真的不确定自己可能会缺少什么.任何帮助将不胜感激.

And I tried to upgrade the Microsoft.Identity.Client to v4.17.1, it is still not working. Since the share code is working for the Android part, I am really not sure what I could be missing. Any help would be appreciated.

推荐答案

转到ios项目属性=>iOS捆绑签名,然后选择您的Entitlements.plist.

Go to the ios project properties => iOS Bundle Signing and select your Entitlements.plist.

Entitlements.plist文件应如下所示:

The Entitlements.plist file should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>aps-environment</key>
    <string>development</string>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
    </array>
</dict>
</plist>

这篇关于该应用程序无法访问Xamarin.Forms中的iOS钥匙串,但可以在Android中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆