views:

53

answers:

1

So what I need to do in my application for loggin in is Perform an HTML request with user/pass which returns XML with a token. The token is used in later http requests.

I know how to perform http requests and also how to parse them, I have already been doing that just with the token hardcoded for testing purposes. I also have it worked out how to use the Application Preferences to allow entry and retreval of the password via:

NSString* settingValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"<Setting Key>"]

The question is if I want this to happen when the application launches where shall I do this? I don't want my application to hang when it launches without giving some feedback to the user, you know if there is no user/pass set or if its rejected by the server. What is your advice? Thanks

A: 

In the app that I am developing, I do it in the first view in a separate thread. This way it doesn't lock the UI. I also do it as a delegate of the main view so it can report back the progress for a progress bar. Later on I'll will be doing it as a slide in view thats just shaded so the person can use parts of the app that don't require auth while the auth is loading.

IMO if you do it in the app delegate it might take several seconds for you to auth and you will not be able to report this to the user easily.

The best way to deal with authentication is using cookies as you are using HTML requests. You can retrieve these cookies using NSHTTPCookieStorage app wide (not just in the class that did the authentication). If you want to continue using your token you can create a global variable in your Application Delegate class (myApplicationAppDelegate.h)

P.S, I wouldn't keep the username and password in NSUserDefaults as its stored in plain text on the device. Use keychain instead.

Rudiger
Where are you storing that token once you have it so that its accessible to other views? App delegate?
startoftext
Well in my project to doesn't return a token to verify the users authed but a cookie which is stored in an App wide storage area called NSHTTPCookieStorage
Rudiger
You can keep global variables in your AppViewController for storing session data, that will be available to other views, because every time you shift between views, the new view will be created from AppViewController.
pMan