Xamarin.Auth iOS9 SSL Authentication ERROR

I just upgraded Xcode to 7.0 (7A220) and it forced my sims to iOS9.

From now on, I cannot successfully complete any OAUTH call from the simulators. I tried every model, from my application, into a "Xamarin.Auth sample application."

The answer is always the same:

"Authentication failed

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

Exception is thrown

The code is STANDARD, I just changed my AppID. The same code works with the Android version of the same application!

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 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 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 Simulator can work on the Internet, so this is not a connection problem. I also tried using the SDK for Facebook, the same error. Could this be a certificate issue?

thanks

+5
source share
1 answer

To fix this problem, simply add the following lines to your Info.plist file:

 <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 do not need additional rules for domains, you can simply add:

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

NOTE: you need to clean and rebuild the project to see how it works with these new settings!

+8
source

Source: https://habr.com/ru/post/1232120/


All Articles