Re: Ignoring credentials in shared NSURLCredentialStorage
Re: Ignoring credentials in shared NSURLCredentialStorage
- Subject: Re: Ignoring credentials in shared NSURLCredentialStorage
- From: Becky Willrich <email@hidden>
- Date: Fri, 11 May 2007 09:36:24 -0700
You've got the basic flow right -
- NSURLConnection issues the request and receives an authorization
challenge from the server
- NSURLConnection consults NSURLCredentialStorage to find a suitable
set of credentials
- NSURLCredentialStorage consults the Keychain to find the credentials
- If NSURLCredentialStorage returns a valid set of credentials,
NSURLConnection will silently apply the credentials and complete the
tramsission
- If NSURLCredentialStorage cannot find any credentials, only then
will NSURLConnection consult its delegate via a didReceiveChallenge:
message
I don't know of any way you can ask the NSURLConnection to not consult
the credential storage, so I think you're stuck with removing the
credentials from the storage itself. That will, as you point out,
remove them from the Keychain as well. There are a couple hacks that
might help you workaround this:
- After either of your apps successfully completes an authenticated
transaction (i.e. you received a didReceiveChallenge: message and
applied credentials successfully), extract the credentials from the
CredentialStorage, then remove them from the storage, then save the
extracted credentials somewhere else - a private key in the keychain
will work fine. This will prevent NSURLConnection from finding the
credentials, but you can retrieve them on demand from the private store.
- You can try using poseAs: to insert your own NSURLCredentialStorage
class in place of the default one; it could always fail to find
credentials, or maybe call through to the real NSURLCredentialStorage
in all cases except the ones you want to intercept. If you do this,
you are tinkering with the runtime, so be careful - you'll want to
make sure and implement forward:: to send any unrecognized messages
through to a "real" NSURLCredentialStorage. I'm not a runtime expert,
so I don't know what all the gotchas are, just that there are more
than a few.
Hope that helps,
REW
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden