Permalink
Browse files

Merge branch 'authheader' of git://github.com/pj4533/AFOAuth1Client i…

…nto pj4533-authheader

Conflicts:
	AFOAuth1Client/AFOAuth1Client.m
  • Loading branch information...
2 parents 2990c00 + 18ea4fe commit ed28a38424d4911f1fdcfa3cb26937117ed8482d @mattt mattt committed Mar 5, 2013
Showing with 38 additions and 25 deletions.
  1. +38 −25 AFOAuth1Client/AFOAuth1Client.m
@@ -143,7 +143,9 @@ - (NSString *)OAuthSignatureForMethod:(NSString *)method
path:(NSString *)path
parameters:(NSDictionary *)parameters
token:(AFOAuth1Token *)requestToken;
-- (NSString *)authorizationHeaderForParameters:(NSDictionary *)parameters;
+- (NSString *)authorizationHeaderForMethod:(NSString*)method
+ path:(NSString*)path
+ parameters:(NSDictionary *)parameters;
@end
@implementation AFOAuth1Client
@@ -208,14 +210,32 @@ - (NSString *)OAuthSignatureForMethod:(NSString *)method
}
}
-- (NSString *)authorizationHeaderForParameters:(NSDictionary *)parameters {
+- (NSString *)authorizationHeaderForMethod:(NSString*)method
+ path:(NSString*)path
+ parameters:(NSDictionary *)parameters
+{
static NSString * const kAFOAuth1AuthorizationFormatString = @"OAuth %@";
- if (!parameters) {
- return nil;
+ NSMutableDictionary *mutableParameters = parameters ? [parameters mutableCopy] : [NSMutableDictionary dictionary];
+ NSMutableDictionary *mutableAuthorizationParameters = [NSMutableDictionary dictionary];
+
+ if (self.key && self.secret) {
+ [mutableAuthorizationParameters addEntriesFromDictionary:[self OAuthParameters]];
+ if (self.accessToken) {
+ [mutableAuthorizationParameters setValue:self.accessToken.key forKey:@"oauth_token"];
+ }
}
- NSArray *sortedComponents = [[AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding) componentsSeparatedByString:@"&"] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
+ [mutableParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
+ if ([key isKindOfClass:[NSString class]] && [key hasPrefix:@"oauth_"]) {
+ [mutableAuthorizationParameters setValue:obj forKey:key];
+ }
+ }];
+
+ [mutableParameters addEntriesFromDictionary:mutableAuthorizationParameters];
+ [mutableAuthorizationParameters setValue:[self OAuthSignatureForMethod:method path:path parameters:mutableParameters token:self.accessToken] forKey:@"oauth_signature"];
+
+ NSArray *sortedComponents = [[AFQueryStringFromParametersWithEncoding(mutableAuthorizationParameters, self.stringEncoding) componentsSeparatedByString:@"&"] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSMutableArray *mutableComponents = [NSMutableArray array];
for (NSString *component in sortedComponents) {
NSArray *subcomponents = [component componentsSeparatedByString:@"="];
@@ -329,27 +349,20 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
path:(NSString *)path
parameters:(NSDictionary *)parameters
{
- NSMutableDictionary *mutableParameters = parameters ? [parameters mutableCopy] : [NSMutableDictionary dictionary];
- NSMutableDictionary *mutableAuthorizationParameters = [NSMutableDictionary dictionary];
-
- if (self.key && self.secret) {
- [mutableAuthorizationParameters addEntriesFromDictionary:[self OAuthParameters]];
- if (self.accessToken) {
- [mutableAuthorizationParameters setValue:self.accessToken.key forKey:@"oauth_token"];
- }
- }
-
- [mutableParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
- if ([key isKindOfClass:[NSString class]] && [key hasPrefix:@"oauth_"]) {
- [mutableAuthorizationParameters setValue:obj forKey:key];
- }
- }];
-
- [mutableParameters addEntriesFromDictionary:mutableAuthorizationParameters];
- [mutableAuthorizationParameters setValue:[self OAuthSignatureForMethod:method path:path parameters:mutableParameters token:self.accessToken] forKey:@"oauth_signature"];
-
NSMutableURLRequest *request = [super requestWithMethod:method path:path parameters:parameters];
- [request setValue:[self authorizationHeaderForParameters:mutableAuthorizationParameters] forHTTPHeaderField:@"Authorization"];
+ [request setValue:[self authorizationHeaderForMethod:method path:path parameters:parameters] forHTTPHeaderField:@"Authorization"];
+ [request setHTTPShouldHandleCookies:NO];
+
+ return request;
+}
+
+- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
+ path:(NSString *)path
+ parameters:(NSDictionary *)parameters
+ constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block
+{
+ NSMutableURLRequest *request = [super multipartFormRequestWithMethod:method path:path parameters:parameters constructingBodyWithBlock:block];
+ [request setValue:[self authorizationHeaderForMethod:method path:path parameters:parameters] forHTTPHeaderField:@"Authorization"];
[request setHTTPShouldHandleCookies:NO];
return request;

0 comments on commit ed28a38

Please sign in to comment.