Skip to content

Commit

Permalink
Add the request operation as a callback argument
Browse files Browse the repository at this point in the history
Adds AFHTTPRequestOperation arguments to the success and failure block signatures, as discussed in issue AFNetworking#84
  • Loading branch information
Nathan Racklyeft committed Feb 9, 2015
1 parent 5ab481d commit b059163
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion AFOAuth2Manager.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
30 changes: 15 additions & 15 deletions AFOAuth2Manager/AFOAuth2Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,69 +90,69 @@
@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.
@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

Expand Down
8 changes: 4 additions & 4 deletions AFOAuth2Manager/AFOAuth2Manager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}];
```
Expand Down

0 comments on commit b059163

Please sign in to comment.