title: How to implement NTLM authentication in Objective-C with NSURLConnection?
body: <p>I'm making cross-platform applications with Apache Cordova. Apache Cordova provides plugins to foresee native functionality. But the plugin to download and upload files doesn't support NTLM... So I try to extend the plugin in Xcode. But I really miss a lot of experience with Objective-C and can't manage to extend it myself.</p>
  
  <p>The full code of the plugin can be found here: <a href="https://github.com/apache/cordova-plugin-file-transfer/blob/master/src/ios/CDVFileTransfer.m" rel="nofollow noreferrer">CDVFileTransfer.m</a></p>
  
  <p>I really think I have to edit something in the last code-block where I already succeeded to enter <code>if(self.trustAllHosts)</code>:</p>
  
  <pre><code>    // for self signed certificates
  - (void)connection:(NSURLConnection*)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
  {
      if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
          if (self.trustAllHosts) {
              NSURLCredential* credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
              [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
          }
          [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
      } else {
          [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge];
      }
  }
  </code></pre>
  
  <p>I've seen threads of collegues in which they try to implement NSURLCredentials as seen <a href="https://stackoverflow.com/questions/21825164/ntlm-authentication-from-ios-client">here</a>...</p>
  
  <p>Anyone knows how to put those two pieces together, or isn't it that simple at all? If I could authorize with hardcoded credentials, I would be happy.</p>