Authentication handling on the iPhone

This iPhone tutorial about encapsulating authentication logic in a separate controller was planned as a chapter for an upcoming iPhone Recipes Book, but unfortunately the book got cancelled. As I had written most of it and already finished the example code I thought it might be of interest for some of you and I would like to share it before it gets dusty.


Most applications that deal with users registered on a backend (like webapps) are likely to verify the user credentials. This recipe explains how to extract the authentication functionality that handles the workflow of prompting the user for credentials and verifying them at the backend.


A separate (Modal View) Controller that acts as the apps AuthenticationController and gets called by other controllers. This controller encapsulates the authentication logic so that it is cleanly separated from the rest of the app. The provided code is compatible for all iPhone OS from 2.0 on.

The code for this recipe is available on GitHub and it contains an example app that features authentication with the Twitter API (HTTP Basic Auth, keepin’ it simple) along with explanatory notes in the README.