0

I have a iOS app which talks to a ASP.NET web app hosted in Azure. I use the Azure authentication to provide a social login to Users from Google, Yahoo, Facebook, etc.

The problem is that if I kill the App, then I lose everything and I need to login again.

Is there anyway I can retain the cookies for the browser control within my iOS app so that, once a user logs in, as long as the cookies remain unexpired, they don't have to login again?

There must be someway to prevent users from having to login multiple times just because they killed the app or restarted the phone, etc.

Is there some way to uniquely identify the phone from iOS which I can save on my server and lookup? - some kind of anonymous ID which I can get from javascript and pass to the server using AJAX call?

1 Answers1

0

Did you set the cookie policy when your app launches?

NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

When you relaunch do you still have the cookies, or is something else going on?

NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
    NSLog(@"Cookies: %@", cookie);
}
Shaunti Fondrisi
  • 1,081
  • 10
  • 13
  • Nope, I am not setting the cookie policy. I am quite sure that when the app relaunches, the cookies are all lost. I'll try this. – user3154855 Jan 02 '14 at 19:51
  • Ok, I added this code, the cookies are getting retained and I can read them back also. However, I see the same behavior in my app as before. It still is unable to use the cookie values in the next session. I also notice the same behavior in Safari if I kill Safari and go to the site again. – user3154855 Jan 02 '14 at 20:07
  • So there are no cookies when you re-enter the app, or do you see the session_id ASPX cookie? Look into the connection management of the "next session" you are referring to. Make sure it is using the shared cookies storage. – Shaunti Fondrisi Jan 02 '14 at 20:12
  • Sorry, I just noticed your comment "I also notice the same behavior in Safari if I kill Safari and go to the site again." Then your app will behave the same. I would suggest storing the credentials in the keychain, and the re-using them if you get an auth challenge. – Shaunti Fondrisi Jan 02 '14 at 20:15
  • Also note, Azure I think is using Oauth 2, so cookies aren't going to help you. I stumbled upon this which might help you look into it more.http://stackoverflow.com/questions/18867504/how-to-logout-from-oauth2-0-authentication-of-windows-azure-active-directory-aut – Shaunti Fondrisi Jan 02 '14 at 20:23
  • Is there some way to uniquely identify the phone from iOS which I can save on my server and lookup? - some kind of anonymous ID which I can get from javascript and pass to the server using AJAX call? – user3154855 Jan 02 '14 at 20:31
  • Set your own custom header value. – Shaunti Fondrisi Jan 02 '14 at 20:49