Basic authentication errors using iOS 8

I have an iOS application that interacts with the server with Rails and has been stable and reliable for 3 years. The server requires basic and SSL certification, and it works fine, right up to iOS 7, including iOS 7.

However, now I see verification problems on devices running iOS 8. Devices / simulators are working <iOS 8 continues to work fine.

When you initialize the application, there is an error requesting data to synchronize with the server to which you want to pass basic authentication.

The result is the following delegate method,

willSendRequestForAuthenticationChallenge 

... and the problem arises because they are disputed endlessly - the code does not work on time in the second attempt when [calling previousFailureCount]> 0 (the code path follows standard practice, calling cancelAuthenticationChallenge if the previousFailureCount> 0) - see below .

I registered call IDs and they are different for each task, even if the previousFailureCount> 0.

 - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic]) { if ([challenge previousFailureCount] == 0) { NSURLCredential *newCredential; newCredential = [NSURLCredential credentialWithUser:MY_USERNAME password:MY_PASSWORD persistence:NSURLCredentialPersistenceForSession]; // Retain for rest of session [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; } else { [[challenge sender] cancelAuthenticationChallenge:challenge]; // ...error will be handled by connection didFailWithError } } } 

If I knock out a call to test the previousFailureCount, there are endless method call calls.

However, as soon as this flurry of failures failed, subsequent and subsequent "separate" NSUrlRequests successfully authenticated.

Again, this problem is specific to iOS 8. Any ideas why the β€œfast” sequence of authentication requests failed in iOS 8, but working in iOS 7?

Thanks.

+5
source share
4 answers

The answer / update to this question also fixed the issue I saw.

NSURLConnection timeout on iOS8

Again, something has changed in iOS 8 requiring this fix.

0
source

If you are not processing the authentication method (NSURLAuthenticationMethodHTTPBasic), you should in any case call one of these methods:

 useCredential:forAuthenticationChallenge: continueWithoutCredentialForAuthenticationChallenge: cancelAuthenticationChallenge: performDefaultHandlingForAuthenticationChallenge: rejectProtectionSpaceAndContinueWithChallenge: 

If you want to ignore a specific authentication method, which is preferable, you can call performDefaultHandlingForAuthenticationChallenge:

See also: connection: willSendRequestForAuthenticationChallenge:

+1
source

I have the same problem, I removed if ([challenge previousFailureCount] == ​​0) and it works.

But I don’t know why it fails in iOS 8.

0
source

FYI, I found this behavior in my application. I see this only for those requests that could not work immediately, but rather should have waited for other network requests, but basic auth failed.

Using the operational queue to make sure that I have no more than 4 simultaneous requests, this problem is solved (obviously, the NSURLConnection wrapper in the asynchronous NSOperation subclass). In addition, the use of NSURLSession also solved the problem.

It looks like an iOS 8 bug with basic authentication using NSURLConnection .

0
source

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


All Articles