AFNetworking/AFOAuth2Client — pull request #42 by larih (2013-07-10 11:27:52+00:00)
Title: Created AFOAuth2ClientViewController to display a modal "popup" for the authorization request

The AFOAuth2ClientViewController lets the user stay inside the app while loggin in with OAuth2. So there's no need to direct user to Safari.app to get the authorization code.

**Usage:**

```
FOAuth2ClientViewController *vc =
[[AFOAuth2ClientViewController alloc] initWithBaseURL:@"https://myoauthloginserver.tld"
authenticationPath:@"/authorize/"
verificationPath:@"/access_token/"
clientID:kClientId
secret:kClientSecret
scope:@"read+write"
redirectURL:@"myapp://oauth"
delegate:self];

// Wrap it in a nav controller to get navigation bar
// (cancel button, title and spinner added automatically)
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

// Present view controller
[self presentViewController:navController animated:YES completion:^() {}];
```

Set the parent view controller as `AFOAuth2ClientViewControllerDelegate`and add the `- (void)oAuthViewController:(AFOAuth2ClientViewController *)viewController didSucceedWithCredential:(AFOAuthCredential *)credential` method to get the `AFOAuth2Client` or `AFOAuthCredential` to be used:

```
- (void)oAuthViewController:(AFOAuth2ClientViewController *)viewController didSucceedWithCredential:(AFOAuthCredential *)credential {

AFOAuth2Client *apiClient = viewController.client;

[apiClient getPath:@"/api/product/"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *response = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
// Do something with the JSON
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"FAIL: %@", error);
}];
}
```

You can also add `- (void)oAuthViewController:(AFOAuth2ClientViewController *)viewController didFailWithError:(NSError *)error` for error handling.