AFURLConnectionOperation should add a property "shouldUseCredentialStorage" #719

krzycube opened this Issue Jan 6, 2013 · 1 comment


None yet

2 participants

krzycube commented Jan 6, 2013

I think the AFURLConnectionOperation object should add one more public property and implement a NSURLConnectionDelegate method:

@property (readwrite, nonatomic, assign) BOOL shouldUseCredentialStorage;
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
    return self.shouldUseCredentialStorage;

Because the NSURLConnection mechanism by default will try to query keychain for credential if there is a Authentication Challenge. And if there is a matched credential to the requesting HTTP API URL, MacOS will popup a window ask for authorization to use the exists credential, which may cause some problem during App login logic, sometimes get data of another account.

I do found there is a block:

AFURLConnectionOperationAuthenticationChallengeBlock authenticationChallenge;

which can handle exists credential problem. But only if there is:

- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
    return NO;

implemented, the popup window will still bother.

@mattt mattt added a commit that referenced this issue Jan 7, 2013
@mattt mattt [Issue #719] Adding shouldUseCredentialStorage property to AFURLConne…
…ctionOperation /thanks Xihe Yu
mattt commented Jan 7, 2013

You can disable this automatic behavior by doing -setAuthenticationChallengeBlock: with a block that simply does [challenge.sender continueWithoutCredentialForAuthenticationChallenge] (and maybe -setAuthenticationAgainstProtectionSpaceBlock:, passing a block that returns NO, for good measure).

But you're right—that's an NSURLConnectionDelegate method left unimplemented that could use a property (having to override in a subclass is lame)

9aeb386 adds this property. Thanks for the great suggestions!

@mattt mattt closed this Jan 7, 2013
@ocollet ocollet added a commit to Bunch/AFNetworking that referenced this issue Jan 21, 2013
@ocollet ocollet Merge remote-tracking branch 'afnetworking/master' into HEAD
* afnetworking/master: (231 commits)
  Rename the `username` variable to `user`
  Use NSURL methods instead of CFURL functions
  Fixing center alignment
  Fixing link to diagram in README
  Adding AFNetworking architecture diagram
  Updating list of implemented NSURLConnectionDelegate method
  [Issue #719] Adding shouldUseCredentialStorage property to AFURLConnectionOperation /thanks Xihe Yu
  Marking connection parameter in connection:needNewBodyStream: as __unused
  Re-ordering NSURLConnectionDelegate method implementations
  Minor reformatting
  [Issue #715] Fixing warnings generated by earlier versions of Xcode (/cc Ignacio Rodrigo)
  Fix request stream exhaustion error by copying the original NSInputStream
  Adding AFHTTPClient -setDefaultCredential:
  Adding credential property to AFURLConnectionOperation
  Added single quote to the chars to escape
  Bumping version to 1.1.0
  Updating Changelog for 1.1.0
  Asynchronously posting all notifications by dispatching to main
  dispatches network request start / end notifications asynchronously
@greghe greghe pushed a commit to skillz/AFNetworking that referenced this issue Sep 3, 2015
@mattt mattt [Issue #719] Adding shouldUseCredentialStorage property to AFURLConne…
…ctionOperation /thanks Xihe Yu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment