I have already discussed how to get OAuth to build for an iPhone in Part 2. To use OAuth to call Netflix there are two small changes needed. The first one is that the way that characters are escaped in URLs needs to be tightened up a bit, otherwise the signature strings will work some of the time and fail when they happen to contain the wrong character sequence. This took a while to figure out...
The file NSString+URLEncoding.m needs to have a few characters (space, plus and asterisk) added as shown below:
Note, I'm having a hard time getting code to look good here, its hard to find a way to render code in a narrow column that doesn't mess up the formatting and works in more than one browser using blogger.com tools and templates.
The second thing is that when the authentication is complete, Netflix returns a token that contains an encoded user identifier, as well as a secret and a key. The standard OAuth code only expects the secret and key, so a new NetflixToken class was created to hold the extra information, and to persist it in the iPhone's defaults store along with the secret and key. This means that once the user has signed into OAuth once, this information is saved and they never have to sign in again unless either Netflix or the User revokes the token. One more method was added to remove an entry from the defaults store, for use during logout.
First the NetflixToken.h header file:
Then the code itself, this is all based on a simple extension of OAToken, which is part of the OAuth code base mentioned in part 2.