Skip to content

Commit

Permalink
Added scheme to POST and arc'd it
Browse files Browse the repository at this point in the history
  • Loading branch information
coneybeare committed Jun 16, 2012
1 parent d0b01e6 commit eccaac8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
Binary file added .DS_Store
Binary file not shown.
16 changes: 8 additions & 8 deletions GCOAuth.h
Expand Up @@ -89,15 +89,15 @@
data will be sent as form URL encoded. Restrictions on the arguments to this
method are the same as the GET request methods.
*/
+ (NSURLRequest *)URLRequestForPath:(NSString *)path
POSTParameters:(NSDictionary *)parameters
host:(NSString *)host
consumerKey:(NSString *)consumerKey
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret;
+ (NSMutableURLRequest *)URLRequestForPath:(NSString *)path
POSTParameters:(NSDictionary *)parameters
scheme:(NSString *)scheme
host:(NSString *)host
consumerKey:(NSString *)consumerKey
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret;
@end

/*
XAuth example (because you may otherwise be scratching your head):
Expand Down
39 changes: 16 additions & 23 deletions GCOAuth.m
Expand Up @@ -98,14 +98,14 @@ - (id)initWithConsumerKey:(NSString *)consumerKey
self = [super init];
if (self) {
OAuthParameters = [[NSDictionary alloc] initWithObjectsAndKeys:
[[consumerKey copy] autorelease], @"oauth_consumer_key",
consumerKey, @"oauth_consumer_key",
[GCOAuth nonce], @"oauth_nonce",
[GCOAuth timeStamp], @"oauth_timestamp",
@"1.0", @"oauth_version",
@"HMAC-SHA1", @"oauth_signature_method",
[[accessToken copy] autorelease], @"oauth_token", // leave accessToken last or you'll break XAuth attempts
accessToken, @"oauth_token", // leave accessToken last or you'll break XAuth attempts
nil];
signatureSecret = [[NSString stringWithFormat:@"%@&%@", [consumerSecret pcen], [tokenSecret ?: @"" pcen]] retain];
signatureSecret = [NSString stringWithFormat:@"%@&%@", [consumerSecret pcen], [tokenSecret ?: @"" pcen]];
}
return self;
}
Expand All @@ -131,7 +131,6 @@ - (NSString *)authorizationHeader {
NSString *entry = [NSString stringWithFormat:@"%@=\"%@\"", [key pcen], [obj pcen]];
[entries addObject:entry];
}];
[dictionary release];
return [@"OAuth " stringByAppendingString:[entries componentsJoinedByString:@","]];
}
- (NSString *)signature {
Expand Down Expand Up @@ -189,17 +188,13 @@ - (void)dealloc {
self.URL = nil;
self.HTTPMethod = nil;
self.requestParameters = nil;
[OAuthParameters release];
OAuthParameters = nil;
[signatureSecret release];
signatureSecret = nil;
[super dealloc];
}

#pragma mark - class methods
+ (void)setUserAgent:(NSString *)agent {
[GCOAuthUserAgent release];
GCOAuthUserAgent = [agent copy];
GCOAuthUserAgent = agent;
}
+ (void)setTimeStampOffset:(time_t)offset {
GCOAuthTimeStampOffset = offset;
Expand All @@ -211,7 +206,7 @@ + (NSString *)nonce {
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
return [(NSString *)string autorelease];
return (__bridge NSString *)string;
}
+ (NSString *)timeStamp {
time_t t;
Expand Down Expand Up @@ -274,17 +269,17 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)path

// return
NSURLRequest *request = [oauth request];
[oauth release];
return request;

}
+ (NSURLRequest *)URLRequestForPath:(NSString *)path
POSTParameters:(NSDictionary *)parameters
host:(NSString *)host
consumerKey:(NSString *)consumerKey
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret {
+ (NSMutableURLRequest *)URLRequestForPath:(NSString *)path
POSTParameters:(NSDictionary *)parameters
scheme:(NSString *)scheme
host:(NSString *)host
consumerKey:(NSString *)consumerKey
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret {

// check parameters
if (host == nil || path == nil) { return nil; }
Expand All @@ -296,9 +291,8 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)path
tokenSecret:tokenSecret];
oauth.HTTPMethod = @"POST";
oauth.requestParameters = parameters;
NSURL *URL = [[NSURL alloc] initWithScheme:@"https" host:host path:path];
NSURL *URL = [[NSURL alloc] initWithScheme:scheme host:host path:path];
oauth.URL = URL;
[URL release];

// create request
NSMutableURLRequest *request = [oauth request];
Expand All @@ -312,7 +306,6 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)path
}

// return
[oauth release];
return request;

}
Expand All @@ -321,10 +314,10 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)path
@implementation NSString (GCOAuthAdditions)
- (NSString *)pcen {
CFStringRef string = CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)self,
(__bridge CFStringRef)self,
NULL,
CFSTR("!*'();:@&=+$,/?%#[]"),
kCFStringEncodingUTF8);
return [(NSString *)string autorelease];
return (__bridge NSString *)string;
}
@end

0 comments on commit eccaac8

Please sign in to comment.