예제 #1
0
 public virtual void DidReceiveChallenge(NSUrlSession session, NSUrlAuthenticationChallenge challenge, Action <NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler)
 {
     if (challenge.PreviousFailureCount == 2)
     {
         //TODO: update UserCreds
     }
     else if (challenge.PreviousFailureCount > 2)
     {
         XamarinAlertController.showAlertViewForController(this, SDKErrorLoginFailedTitle, SDKErrorLoginFailedMessage);
         completionHandler(NSUrlSessionAuthChallengeDisposition.CancelAuthenticationChallenge, null);
     }
     else
     {
         if (challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodServerTrust")
         {
             completionHandler(NSUrlSessionAuthChallengeDisposition.PerformDefaultHandling, null);
         }
         else if ((challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodHTTPBasic") || (challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodNTLM") || (challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodClientCertificate"))
         {
             handleChallangeforSession(challenge, completionHandler);
         }
         else
         {
             completionHandler(NSUrlSessionAuthChallengeDisposition.CancelAuthenticationChallenge, null);
             XamarinAlertController.showAlertViewForController(this, SDKErrorAuthNotSupportedTitle, SDKErrorAuthNotSupportedMessage);
         }
     }
 }
예제 #2
0
 public virtual void WillSendRequestForAuthenticationChallenge(NSUrlConnection connection, NSUrlAuthenticationChallenge challenge)
 {
     if (challenge.PreviousFailureCount == 2)
     {
         //TODO: update cred
     }
     else if (challenge.PreviousFailureCount > 2)
     {
         //display alert
         XamarinAlertController.showAlertViewForController(this, SDKErrorLoginFailedTitle, SDKErrorLoginFailedMessage);
     }
     else
     {
         //handle challenges
         if (challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodServerTrust")
         {
             var cred = new NSUrlCredential(challenge.ProtectionSpace.ServerSecTrust);
             challenge.Sender.UseCredential(cred, challenge);
         }
         else if ((challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodHTTPBasic") || (challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodNTLM") || (challenge.ProtectionSpace.AuthenticationMethod == "NSURLAuthenticationMethodClientCertificate"))
         {
             handleChallengeForConnection(challenge);
         }
         else
         {
             Console.WriteLine("AWXamarin Authentication challenge is not supported by the SDK");
             XamarinAlertController.showAlertViewForController(this, SDKErrorAuthNotSupportedTitle, SDKErrorAuthNotSupportedMessage);
         }
     }
 }
예제 #3
0
        public void createCredAlertForChallenge(NSUrlAuthenticationChallenge challenge)
        {
            InvokeOnMainThread(() =>
            {
                var alertController       = UIAlertController.Create("Login", challenge.ProtectionSpace.Realm, UIAlertControllerStyle.Alert);
                UIAlertAction loginAction = UIAlertAction.Create("Submit", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                {
                    string username = alertController.TextFields[0].Text;
                    string password = alertController.TextFields[1].Text;
                    if (username != null && password != null)
                    {
                        useCredentialsForLogin(username, password);
                    }
                    else
                    {
                        Console.WriteLine("Cant create creds");
                    }
                });
                alertController.AddAction(loginAction);
                alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (UIAlertAction obj) =>
                {
                    completionHandler(NSUrlSessionAuthChallengeDisposition.CancelAuthenticationChallenge, null);
                }));

                alertController.AddTextField(textField =>
                {
                    textField.Placeholder     = "Username";
                    textField.ClearButtonMode = UITextFieldViewMode.WhileEditing;
                });

                alertController.AddTextField(textField =>
                {
                    textField.Placeholder     = "Password";
                    textField.ClearButtonMode = UITextFieldViewMode.WhileEditing;
                    textField.SecureTextEntry = true;
                });
                XamarinAlertController.showAlertOnTopViewController(alertController);
            });
        }
예제 #4
0
        public static void showAlertOnTopViewController(UIAlertController alertController)
        {
            UIViewController vc = XamarinAlertController.topViewController();

            vc.PresentViewController(alertController, true, null);
        }