Mikuro
Crotchety UI Nitpicker
I'm trying to write a program in Cocoa that accesses a password-protected web page (specifically, my gmail account atom feed). I'm basing my routine on Apple's sample code.
My problem is that I can't for the life of me figure out how to isolate my program's credentials from other Cocoa programs (e.g., Safari's). If I'm logged in to a gmail account in Safari, my app uses Safari's credentials, no matter what I do! This is bad, because I don't necessary want to access the same account in Safari and my program.
So, let's say that in Safari, I'm logged in as myName@gmail.com. Now how can I access myOtherName@gmail.com in my other program? I've tried putting the login info right into the URL (https://myOtherName:myOtherPassword@mail.google.com/mail/feed/atom), but this will still return the feed for myName, not myOtherName.
I've also wrestled with NSURLCredentialStorage, to no avail. I've tried adding credentials to mimic what Safari seems to have made, hoping to override it. Here's a snippet to show what I mean:
And I've tried that snippet using both setCredential and setDefaultCredential. Either way, I still get the feed for myName, not myOtherName. GAAH!
What am I missing? I'm running out of ideas here. Any help would be greatly appreciated!
My problem is that I can't for the life of me figure out how to isolate my program's credentials from other Cocoa programs (e.g., Safari's). If I'm logged in to a gmail account in Safari, my app uses Safari's credentials, no matter what I do! This is bad, because I don't necessary want to access the same account in Safari and my program.
So, let's say that in Safari, I'm logged in as myName@gmail.com. Now how can I access myOtherName@gmail.com in my other program? I've tried putting the login info right into the URL (https://myOtherName:myOtherPassword@mail.google.com/mail/feed/atom), but this will still return the feed for myName, not myOtherName.
I've also wrestled with NSURLCredentialStorage, to no avail. I've tried adding credentials to mimic what Safari seems to have made, hoping to override it. Here's a snippet to show what I mean:
Code:
NSURLCredential *newCredential =[NSURLCredential credentialWithUser:@"myOtherName" password:@"myOtherPassword" persistence:NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *space;
space = [[NSURLProtectionSpace alloc] initWithHost:@"mail.google.com" port:0 protocol:@"https" realm:nil authenticationMethod:NSURLAuthenticationMethodDefault];
[store setCredential:newCredential forProtectionSpace:space];
space = [[NSURLProtectionSpace alloc] initWithHost:@"gmail.google.com" port:0 protocol:@"https" realm:@"New mail feed" authenticationMethod:NSURLAuthenticationMethodDefault];
[store setCredential:newCredential forProtectionSpace:space];
space = [[NSURLProtectionSpace alloc] initWithHost:@"https://mail.google.com/mail/feed/atom" port:80 protocol:@"https" realm:nil authenticationMethod:NSURLAuthenticationMethodDefault];
[store setCredential:newCredential forProtectionSpace:space];
What am I missing? I'm running out of ideas here. Any help would be greatly appreciated!