Xamarin.Auth iOS9 Authentication SSL ERROR

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 04:56:15

问题


I've just updated XCode to the 7.0 (7A220) and this take my Simulators to iOS9.

From that moment I cannot perform successfully any OAUTH call from the simulators.. I tried every model, from my App to the "sample Xamarin.Auth App".

The answer is always the same:

"Authentication Error

An SSL error has occurred and a secure connection to the server cannot be made"

The Code is the STANDARD one, I only changed my AppID. The same code is working on the Android version of the same App!

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);

The IOS9 Simulator can surf the web, so it is not a "connectivity problem". I also tried with Facebook SDK, same error. Could it be a certificate issue?

Thanks


回答1:


To Fix this problem, simply add to your Info.plist file these lines:

<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>

If you don't care about extra rules for domains, you can simply add:

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

NOTE: you have to Clean and Rebuild the project in order to see it running with these new settings!



来源:https://stackoverflow.com/questions/32745523/xamarin-auth-ios9-authentication-ssl-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!