Пример #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);
         }
     }
 }