Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Repository files navigation

AFOAuth1Client

AFOAuth1Client is an extension for AFNetworking that simplifies the process of authenticating against an OAuth 1.0a provider.

Usage

NSURL *baseURL = [NSURLURLWithString:@"https://twitter.com/oauth/"];
AFOAuth1Client *OAuth1Client = [[AFOAuth1Client alloc] initWithBaseURL:baseURL
key:@"..."secret:@"..."];

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.

NSURL *callbackURL = [NSURLURLWithString:@"x-com-YOUR-APP-SCHEME://success"];
[OAuth1Client authorizeUsingOAuthWithRequestTokenPath:@"/request_token"userAuthorizationPath:@"/authorize"callbackURL:callbackURL
accessTokenPath:@"/access_token"success:^(AFOAuth1Token *accessToken) {
NSLog(@"Success: %@", accessToken);
}
failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];

Responding to the custom URL scheme on iOS:

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)URL
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
NSNotification *notification =
[NSNotificationnotificationWithName:kAFApplicationLaunchedWithURLNotificationobject:niluserInfo:@{kAFApplicationLaunchOptionsURLKey: URL}];
[[NSNotificationCenterdefaultCenter] postNotification:notification];
returnYES;
}

Contact

Mattt Thompson

License

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

About

AFNetworking Extension for OAuth 1.0a Authentication

Resources

Stars

209 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages