From ddc9a707e9a983c6d26f128a5b37826275d3be18 Mon Sep 17 00:00:00 2001 From: Nathan Racklyeft Date: Mon, 9 Feb 2015 13:29:07 -0800 Subject: [PATCH] Add the request operation as a callback argument Adds AFHTTPRequestOperation arguments to the success and failure block signatures, as discussed in issue #84 --- AFOAuth2Manager.podspec | 2 +- AFOAuth2Manager/AFOAuth2Manager.h | 30 +++++++++++++++--------------- AFOAuth2Manager/AFOAuth2Manager.m | 8 ++++---- README.md | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/AFOAuth2Manager.podspec b/AFOAuth2Manager.podspec index f2a0aaf8..5afd05d2 100644 --- a/AFOAuth2Manager.podspec +++ b/AFOAuth2Manager.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'AFOAuth2Manager' - s.version = '2.0.0' + s.version = '3.0.0' s.license = 'MIT' s.summary = 'AFNetworking Extension for OAuth 2 Authentication.' s.homepage = 'https://github.com/AFNetworking/AFOAuth2Manager' diff --git a/AFOAuth2Manager/AFOAuth2Manager.h b/AFOAuth2Manager/AFOAuth2Manager.h index 7e602e30..0853ff81 100644 --- a/AFOAuth2Manager/AFOAuth2Manager.h +++ b/AFOAuth2Manager/AFOAuth2Manager.h @@ -90,41 +90,41 @@ @param username The username used for authentication @param password The password used for authentication @param scope The authorization scope - @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server. + @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the request operation, and the OAuth credential returned by the server. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server. */ - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString username:(NSString *)username password:(NSString *)password scope:(NSString *)scope - success:(void (^)(AFOAuthCredential *credential))success - failure:(void (^)(NSError *error))failure; + success:(void (^)(AFHTTPRequestOperation *operation, AFOAuthCredential *credential))success + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; /** Creates and enqueues an `AFHTTPRequestOperation` to authenticate against the server with a designated scope. @param URLString The URL string used to create the request URL. @param scope The authorization scope - @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server. + @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the request operation, and the OAuth credential returned by the server. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server. */ - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString scope:(NSString *)scope - success:(void (^)(AFOAuthCredential *credential))success - failure:(void (^)(NSError *error))failure; + success:(void (^)(AFHTTPRequestOperation *operation, AFOAuthCredential *credential))success + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; /** Creates and enqueues an `AFHTTPRequestOperation` to authenticate against the server using the specified refresh token. @param URLString The URL string used to create the request URL. @param refreshToken The OAuth refresh token - @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server. + @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the request operation, and the OAuth credential returned by the server. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server. */ - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString refreshToken:(NSString *)refreshToken - success:(void (^)(AFOAuthCredential *credential))success - failure:(void (^)(NSError *error))failure; + success:(void (^)(AFHTTPRequestOperation *operation, AFOAuthCredential *credential))success + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; /** Creates and enqueues an `AFHTTPRequestOperation` to authenticate against the server with an authorization code, redirecting to a specified URI upon successful authentication. @@ -132,27 +132,27 @@ @param URLString The URL string used to create the request URL. @param code The authorization code @param uri The URI to redirect to after successful authentication - @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server. + @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the request operation, and the OAuth credential returned by the server. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server. */ - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString code:(NSString *)code redirectURI:(NSString *)uri - success:(void (^)(AFOAuthCredential *credential))success - failure:(void (^)(NSError *error))failure; + success:(void (^)(AFHTTPRequestOperation *operation, AFOAuthCredential *credential))success + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; /** Creates and enqueues an `AFHTTPRequestOperation` to authenticate against the server with the specified parameters. @param URLString The URL string used to create the request URL. @param parameters The parameters to be encoded and set in the request HTTP body. - @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server. + @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the request operation, and the OAuth credential returned by the server. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server. */ - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString parameters:(NSDictionary *)parameters - success:(void (^)(AFOAuthCredential *credential))success - failure:(void (^)(NSError *error))failure; + success:(void (^)(AFHTTPRequestOperation *operation, AFOAuthCredential *credential))success + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; @end diff --git a/AFOAuth2Manager/AFOAuth2Manager.m b/AFOAuth2Manager/AFOAuth2Manager.m index 21414871..8d4e3dc8 100644 --- a/AFOAuth2Manager/AFOAuth2Manager.m +++ b/AFOAuth2Manager/AFOAuth2Manager.m @@ -189,15 +189,15 @@ - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString parameters:(NSDictionary *)parameters - success:(void (^)(AFOAuthCredential *credential))success - failure:(void (^)(NSError *error))failure + success:(void (^)(AFHTTPRequestOperation *operation, AFOAuthCredential *credential))success + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionaryWithDictionary:parameters]; mutableParameters[@"client_id"] = self.clientID; mutableParameters[@"client_secret"] = self.secret; parameters = [NSDictionary dictionaryWithDictionary:mutableParameters]; - [self POST:URLString parameters:parameters success:^(__unused AFHTTPRequestOperation *operation, id responseObject) { + [self POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { if (!responseObject) { if (failure) { failure(nil); @@ -234,7 +234,7 @@ - (void)authenticateUsingOAuthWithURLString:(NSString *)URLString if (success) { success(credential); } - } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) { + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if (failure) { failure(error); } diff --git a/README.md b/README.md index cdef2c66..f4a07cda 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ AFOAuth2Manager *OAuth2Manager = username:@"username" password:@"password" scope:@"email" - success:^(AFOAuthCredential *credential) { + success:^(AFHTTPRequestOperation *operation, AFOAuthCredential *credential) { NSLog(@"Token: %@", credential.accessToken); } - failure:^(NSError *error) { + failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; ```