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

Commit

Permalink
Introducing API-breaking changes to AFOAuth1Client
Browse files Browse the repository at this point in the history
Adding scope parameter to AFOAuth1Client methods

Adding responseObject argument in success block parameter
  • Loading branch information
mattt committed May 7, 2013
1 parent 8e945e5 commit 7eff30f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 52 deletions.
28 changes: 6 additions & 22 deletions AFOAuth1Client/AFOAuth1Client.h
Expand Up @@ -72,16 +72,6 @@ typedef enum {
/// @name Authenticating
///---------------------


- (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
userAuthorizationPath:(NSString *)userAuthorizationPath
callbackURL:(NSURL *)callbackURL
accessTokenPath:(NSString *)accessTokenPath
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *accessToken))success
failure:(void (^)(NSError *error))failure;

/**
*/
Expand All @@ -90,24 +80,18 @@ typedef enum {
callbackURL:(NSURL *)callbackURL
accessTokenPath:(NSString *)accessTokenPath
accessMethod:(NSString *)accessMethod
success:(void (^)(AFOAuth1Token *accessToken))success
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *accessToken, id responseObject))success
failure:(void (^)(NSError *error))failure;


- (void)acquireOAuthRequestTokenWithPath:(NSString *)path
callback:(NSURL *)url
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *requestToken))success
failure:(void (^)(NSError *error))failure;

/**
*/
- (void)acquireOAuthRequestTokenWithPath:(NSString *)path
callback:(NSURL *)url
callbackURL:(NSURL *)url
accessMethod:(NSString *)accessMethod
success:(void (^)(AFOAuth1Token *requestToken))success
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *requestToken, id responseObject))success
failure:(void (^)(NSError *error))failure;

/**
Expand All @@ -116,7 +100,7 @@ typedef enum {
- (void)acquireOAuthAccessTokenWithPath:(NSString *)path
requestToken:(AFOAuth1Token *)requestToken
accessMethod:(NSString *)accessMethod
success:(void (^)(AFOAuth1Token *accessToken))success
success:(void (^)(AFOAuth1Token *accessToken, id responseObject))success
failure:(void (^)(NSError *error))failure;

@end
Expand Down
38 changes: 9 additions & 29 deletions AFOAuth1Client/AFOAuth1Client.m
Expand Up @@ -248,40 +248,29 @@ - (NSString *)authorizationHeaderForMethod:(NSString*)method

#pragma mark -

- (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
userAuthorizationPath:(NSString *)userAuthorizationPath
callbackURL:(NSURL *)callbackURL
accessTokenPath:(NSString *)accessTokenPath
accessMethod:(NSString *)accessMethod
success:(void (^)(AFOAuth1Token *accessToken))success
failure:(void (^)(NSError *error))failure
{
[self authorizeUsingOAuthWithRequestTokenPath:requestTokenPath userAuthorizationPath:userAuthorizationPath callbackURL:callbackURL accessTokenPath:accessTokenPath accessMethod:accessMethod scope:nil success:success failure:failure];
}

- (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
userAuthorizationPath:(NSString *)userAuthorizationPath
callbackURL:(NSURL *)callbackURL
accessTokenPath:(NSString *)accessTokenPath
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *accessToken))success
success:(void (^)(AFOAuth1Token *accessToken, id responseObject))success
failure:(void (^)(NSError *error))failure
{
[self acquireOAuthRequestTokenWithPath:requestTokenPath callback:callbackURL accessMethod:(NSString *)accessMethod scope:scope success:^(AFOAuth1Token *requestToken) {
[self acquireOAuthRequestTokenWithPath:requestTokenPath callbackURL:callbackURL accessMethod:(NSString *)accessMethod scope:scope success:^(AFOAuth1Token *requestToken, id responseObject) {
__block AFOAuth1Token *currentRequestToken = requestToken;
[[NSNotificationCenter defaultCenter] addObserverForName:kAFApplicationLaunchedWithURLNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
NSURL *url = [[notification userInfo] valueForKey:kAFApplicationLaunchOptionsURLKey];

currentRequestToken.verifier = [AFParametersFromQueryString([url query]) valueForKey:@"oauth_verifier"];

[self acquireOAuthAccessTokenWithPath:accessTokenPath requestToken:currentRequestToken accessMethod:accessMethod success:^(AFOAuth1Token * accessToken) {
[self acquireOAuthAccessTokenWithPath:accessTokenPath requestToken:currentRequestToken accessMethod:accessMethod success:^(AFOAuth1Token * accessToken, id responseObject) {

if (accessToken) {
self.accessToken = accessToken;

if (success) {
success(accessToken);
success(accessToken, responseObject);
}
} else {
if (failure) {
Expand Down Expand Up @@ -312,19 +301,10 @@ - (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
}

- (void)acquireOAuthRequestTokenWithPath:(NSString *)path
callback:(NSURL *)callbackURL
accessMethod:(NSString *)accessMethod
success:(void (^)(AFOAuth1Token *requestToken))success
failure:(void (^)(NSError *error))failure
{
[self acquireOAuthRequestTokenWithPath:path callback:callbackURL accessMethod:accessMethod scope:nil success:success failure:failure];
}

- (void)acquireOAuthRequestTokenWithPath:(NSString *)path
callback:(NSURL *)callbackURL
callbackURL:(NSURL *)callbackURL
accessMethod:(NSString *)accessMethod
scope:(NSString *)scope
success:(void (^)(AFOAuth1Token *requestToken))success
success:(void (^)(AFOAuth1Token *requestToken, id responseObject))success
failure:(void (^)(NSError *error))failure
{
NSMutableDictionary *parameters = [[self OAuthParameters] mutableCopy];
Expand All @@ -339,7 +319,7 @@ - (void)acquireOAuthRequestTokenWithPath:(NSString *)path
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
AFOAuth1Token *accessToken = [[AFOAuth1Token alloc] initWithQueryString:operation.responseString];
success(accessToken);
success(accessToken, responseObject);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
Expand All @@ -353,7 +333,7 @@ - (void)acquireOAuthRequestTokenWithPath:(NSString *)path
- (void)acquireOAuthAccessTokenWithPath:(NSString *)path
requestToken:(AFOAuth1Token *)requestToken
accessMethod:(NSString *)accessMethod
success:(void (^)(AFOAuth1Token *accessToken))success
success:(void (^)(AFOAuth1Token *accessToken, id responseObject))success
failure:(void (^)(NSError *error))failure
{
self.accessToken = requestToken;
Expand All @@ -367,7 +347,7 @@ - (void)acquireOAuthAccessTokenWithPath:(NSString *)path
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
AFOAuth1Token *accessToken = [[AFOAuth1Token alloc] initWithQueryString:operation.responseString];
success(accessToken);
success(accessToken, responseObject);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/"] key:@"4oFCF0AjP4PQDUaCh5RQ" secret:@"NxAihESVsdUXSUxtHrml2VBHA0xKofYKmmGS01KaSs"];
[self.twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]];

[self.twitterClient authorizeUsingOAuthWithRequestTokenPath:@"oauth/request_token" userAuthorizationPath:@"oauth/authorize" callbackURL:[NSURL URLWithString:@"af-twitter://success"] accessTokenPath:@"oauth/access_token" accessMethod:@"POST" success:^(AFOAuth1Token *accessToken) {
[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) {
NSLog(@"Success: %@", accessToken);

[self.twitterClient getPath:@"1/statuses/user_timeline.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
Expand Down

0 comments on commit 7eff30f

Please sign in to comment.