Reusable iOS user authentication view controller on GitHub

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:

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.

This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to Reusable iOS user authentication view controller on GitHub

  1. Kyle Parker says:


    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,
    Kyle Parker

    // Copy the credentials for later use.
    _username = [username copy];
    _password = [password copy];

    [self authenticateImpl:&_errorMessage];

    // Create an operation that will be executed async.
    //_invocationOperation = [[NSInvocationOperation alloc]initWithTarget:self
    // selector:@selector(executeAsync)
    // object:nil];

    // Enqueue the operation so that it will be executed on a worker thread.
    //_operationQueue = [[NSOperationQueue alloc] init];
    //[_operationQueue addOperation:_invocationOperation];

  2. Josh Smith says:

    Hi Kyle,
    Sorry I don’t have time to look into your question, but you might find someone to help you out on

  3. Pingback: Reusable iOS user authentication view controller on GitHub | BRAE

Comments are closed.