In my spare time I have been working on a View Controller that can be used to asynchronously authenticate user credentials (username and password). Your application provides the code that contacts a server to authenticate, and optionally replaces the user interface that gathers the username and password. Your authentication code is called on a background thread, so you can make a simple blocking call to the server to perform the authentication, without blocking the main thread. My LoginViewController class, with its associated View file, is complete and has been posted to GitHub. I created the iOSLogin project to host the files: https://github.com/ijoshsmith/iOSLogin
The following screenshot shows code from the demo’s app delegate file, which configures the LoginViewController and displays it in a modal dialog. Notice that the View used to render the LoginViewController is determined at runtime based on a config value from the bundle’s info plist.
I wrote a simple RESTful authentication service in WCF, which I hosted on my main desktop at home. The DemoLoginOperation has code that calls that service to perform authentication. It works like a champ, even if that service is unavailable.
If you’re interested in getting an overview of how the code works, let me know and I’ll consider writing one up.
Hi – I stumbled across your code example for the iOS login and first, thank you for posting this. I am attempting to port an Android app to iOS (very first iOS app and have never done Objective C before) and this post was extremely helpful in getting me started on the authentication path.
I do, however, have a couple questions – hopefully they are somewhat intelligent…
I have downloaded your project from Git and attempting to modify it to create a sandbox app that simply handles authentication. When I try to inject the didReceiveAuthenticationChallenge, didReceiveResponse, didReceiveData and connectionDidFinishLoading methods, they are never used. I know that probably doesn’t give you much to go on, but basically I tried adding those methods and with the authenticateImpl method running on a separate thread, they never fire. If I modify your “beginAuthenticateUsername” to look like my snippet below, they do fire… Basically, I’m stuck and I’m not sure how to make the “did” methods fire on the same thread as the authenticateImpl…if that makes any sense at all. I’d be happy to send along my code if you would be able to help me offline?
Thank you for the help – I appreciate it,
// Copy the credentials for later use.
_username = [username copy];
_password = [password copy];
// Create an operation that will be executed async.
//_invocationOperation = [[NSInvocationOperation alloc]initWithTarget:self
// Enqueue the operation so that it will be executed on a worker thread.
//_operationQueue = [[NSOperationQueue alloc] init];
Sorry I don’t have time to look into your question, but you might find someone to help you out on stackoverflow.com
Pingback: Reusable iOS user authentication view controller on GitHub | BRAE