Latest 0.3.6
Homepage https://github.com/AYastrebov/AF2OAuth1Client
License MIT
Platforms ios 6.0, osx 10.8, requires ARC
Dependencies AFNetworking
Authors

AFOAuth1Client

Instructions

Register your application to launch from a custom URL scheme, and use that with the path success as your callback URL. The callback for the custom URL scheme should send a notification, which will complete the OAuth transaction.

Here’s how to create a client and authenticate:

AFOAuth1Client *twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/"] key:@"..." secret:@"..."];

// Your application will be sent to the background until the user authenticates, and then the app will be brought back using the callback URL
[self.twitterClient authorizeUsingOAuthWithRequestTokenPath:@"/oauth/request_token" userAuthorizationPath:@"/oauth/authorize" callbackURL:[NSURL URLWithString:@"af-twitter://success"] accessTokenPath:@"/oauth/access_token" accessMethod:@"POST" scope:nil success:^(AFOAuth1Token *accessToken, id responseObject) {
    NSMutableURLRequest *request = [self.twitterClient requestWithMethod:@"GET" path:@"statuses/user_timeline.json" parameters:nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperationManager manager] HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", [error localizedDescription]);
    }];
    [manager.operationQueue addOperation:operation];
} failure:^(NSError *error) {
    NSLog(@"Error: %@", error);
}];

Here’s how to respond to the custom URL scheme on iOS:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    NSNotification *notification = [NSNotification notificationWithName:kAFApplicationLaunchedWithURLNotification object:nil userInfo:[NSDictionary dictionaryWithObject:url forKey:kAFApplicationLaunchOptionsURLKey]];
    [[NSNotificationCenter defaultCenter] postNotification:notification];

    return YES;
}

Contact

Joel Chen

http://lnkd.in/bwwnBWR

License

AFOAuth1Client is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "AF2OAuth1Client",
    "version": "0.3.6",
    "summary": "AFNetworking 2 Extension for OAuth 1.0a Authentication.",
    "homepage": "https://github.com/AYastrebov/AF2OAuth1Client",
    "social_media_url": "https://twitter.com/AFNetworking",
    "license": "MIT",
    "authors": {
        "Mattt Thompson": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AYastrebov/AF2OAuth1Client.git",
        "tag": "0.3.6"
    },
    "source_files": "AF2OAuth1Client",
    "requires_arc": true,
    "platforms": {
        "ios": "6.0",
        "osx": "10.8"
    },
    "ios": {
        "frameworks": [
            "MobileCoreServices",
            "SystemConfiguration",
            "Security",
            "CoreGraphics"
        ]
    },
    "osx": {
        "frameworks": [
            "CoreServices",
            "SystemConfiguration",
            "Security"
        ]
    },
    "dependencies": {
        "AFNetworking": [
            "~> 2.0"
        ]
    }
}

Pin It on Pinterest

Share This