【问题标题】:Xamarin.Auth iOS9 Authentication SSL ERRORXamarin.Auth iOS9 身份验证 SSL 错误
【发布时间】:2015-12-21 02:56:15
【问题描述】:

我刚刚将 XCode 更新到 7.0 (7A220),这会将我的模拟器升级到 iOS9。

从那一刻起,我无法从模拟器成功执行任何 OAUTH 调用。我尝试了每个模型,从我的应用程序到“示例 Xamarin.Auth 应用程序”。

答案总是一样的:

"验证错误

发生 SSL 错误,无法与服务器建立安全连接”

代码是标准代码,我只更改了我的 AppID。 相同的代码在同一个 App 的 Android 版本上运行!

var auth = new OAuth2Authenticator (
            clientId: "my app id",
            scope: "",
            authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
            redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

        auth.AllowCancel = allowCancel;

        // If authorization succeeds or is canceled, .Completed will be fired.
        auth.Completed += (s, e) =>
        {
            // We presented the UI, so it's up to us to dismiss it.
            dialog.DismissViewController (true, null);

            if (!e.IsAuthenticated) {
                facebookStatus.Caption = "Not authorized";
                dialog.ReloadData();
                return;
            }

            // Now that we're logged in, make a OAuth2 request to get the user's info.
            var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
            request.GetResponseAsync().ContinueWith (t => {
                if (t.IsFaulted)
                    facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message;
                else if (t.IsCanceled)
                    facebookStatus.Caption = "Canceled";
                else
                {
                    var obj = JsonValue.Parse (t.Result.GetResponseText());
                    facebookStatus.Caption = "Logged in as " + obj["name"];
                }

                dialog.ReloadData();
            }, uiScheduler);
        };

        UIViewController vc = auth.GetUI ();
        dialog.PresentViewController (vc, true, null);

IOS9模拟器可以上网,所以不是“连接问题”。我也尝试过使用 Facebook SDK,同样的错误。会不会是证书问题?

谢谢

【问题讨论】:

    标签: facebook xamarin ios-simulator ios9 xamarin.auth


    【解决方案1】:

    要解决此问题,只需将以下行添加到您的 Info.plist 文件中:

    <key>NSAppTransportSecurity</key>
      <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
      <key>facebook.com</key>
      <dict>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSExceptionRequiresForwardSecrecy</key>
        <false/>
      </dict>
      <key>fbcdn.net</key>
      <dict>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSExceptionRequiresForwardSecrecy</key>
        <false/>
      </dict>
      <key>akamaihd.net</key>
      <dict>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSExceptionRequiresForwardSecrecy</key>
        <false/>
      </dict>
    </dict>
    

    如果您不关心域的额外规则,您可以简单地添加:

     <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
    

    注意:您必须清理并重建项目才能看到它在这些新设置下运行!

    【讨论】:

    • 你的问题是天赐之物!。我整天都在处理这个问题。你用什么程序来编辑你的 info.plist 文件?
    • 请更正第二段代码:NSAppTransportSecurityNSAllowsArbitraryLoads
    • 有人能解释一下这个修复的作用吗?根本问题是什么?为什么添加 .. er.. 这些额外的行 .. 可以解决问题?
    • 哈利路亚 :-) 你拯救了这一天。谢谢你,我的 Xamarin 项目快疯了。
    猜你喜欢
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    相关资源
    最近更新 更多