title: AFNetworking setAuthenticationChallengeBlock
body: <p>My server requires a client certifiacte, after some time searching and reading examples in AFNetworking docs I tried to set setAuthenticationChallengeBlock and provide a client certificate.</p>
  
  <p>In browser provided certifacete works fine.</p>
  
  <pre><code>[requestOperation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge)
      {
          NSLog(@"AuthenticationChallenge");
  
          NSString *thePath = [[NSBundle mainBundle] pathForResource:@"client" ofType:@"pfx"];
          NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath];
          CFDataRef inPKCS12Data = (__bridge CFDataRef)PKCS12Data;
          SecIdentityRef identity;
  
          [self extractIdentity:inPKCS12Data :&amp;identity];
  
          SecCertificateRef certificate = NULL;
          SecIdentityCopyCertificate (identity, &amp;certificate);
  
          const void *certs[] = {certificate};
          CFArrayRef certArray = CFArrayCreate(kCFAllocatorDefault, certs, 1, NULL);
  
          NSURLCredential *credential = [NSURLCredential credentialWithIdentity:identity certificates:(__bridge NSArray*)certArray persistence:NSURLCredentialPersistencePermanent];
          [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
      }];
      [requestOperation start];
  </code></pre>
  
  <p>but the code inside block is never being called and server returns 403 error as expected.</p>
  
  <p>The code in other blocks such as setUploadBlock etc. works fine.</p>
  
  <p>Any idea where is my mistake?</p>