Reputation: 9471
How does this line of code work?
I am trying to modify the URL for this to work, but from looking at the Apple Documentation it doesn't give much on where I should put the password/URL.
NSString *password = [(NSString *)CFURLCopyPassword((CFURLRef)[self.request URL]) autorelease];
This line of code is part of the AFNetworking framework so I can pass authentication.
How is the URL suppose to be structured for this to grab the password correctly? I have no luck with it yet.
I tried putting it in the front username:password, but that is not right. the password doesn't get grabbed.
So basically http://userid:[email protected]/ completely bypasses the method and it's not what I want to do.
Upvotes: 1
Views: 355
Reputation: 8944
You can find a short description of this authentication way here, for more details you'll have to look for the proper standard describing URL.
URL sample in case the page is not available later: ftp://username:password@hostname/
If the delegate does not implement this method the default implementation is used. If a valid credential for the request is provided as part of the URL, or is available from the NSURLCredentialStorage the [challenge sender] is sent a **useCredential:forAuthenticationChallenge: with the credential. If the challenge has no credential or the credentials fail to authorize access, then continueWithoutCredentialForAuthenticationChallenge: is sent to [challenge sender] instead.
Upvotes: 1
Reputation: 150615
Essentially - some URLs are structured with a contained UserName and password
http://userid:[email protected]/
If you pass a URL with this format to the function it will return the password part of the URL if it is in the correct format, or an empty string (CFSTR(""))
if it is not.
In the same way you can get the userid with the CFURLCopyUserName
function.
Upvotes: 1