Skip to content
This repository has been archived by the owner on Oct 14, 2018. It is now read-only.

Commit

Permalink
Allow HTTPS for GET requests
Browse files Browse the repository at this point in the history
We found some service that required an HTTPS call on a GET. Typically this means our elegant API is slightly spoilt.

I added an additional function to allow the scheme to be set because typically you don't need anything but HTTP for GET OAuth requests and well designed APIs should allow you to use 80% of their feature sets without bloat.
  • Loading branch information
mxcl committed Apr 26, 2011
1 parent 9178ced commit f632090
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions TDOAuth.h
Expand Up @@ -56,6 +56,20 @@
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret;

/**
Sometimes the service in question insists on HTTPS for everything. They
shouldn't, since the whole point of OAuth1 is that you *don't* need HTTPS.
But whatever I guess.
*/
+ (NSURLRequest *)URLRequestForPath:(NSString *)unencodedPath_WITHOUT_Query
GETParameters:(NSDictionary *)unencodedParameters
scheme:(NSString *)scheme
host:(NSString *)host
consumerKey:(NSString *)consumerKey
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret;

/**
We always POST with HTTPS. This is because at least half the time the user's
data is at least somewhat private, but also because apparently some carriers
Expand Down
21 changes: 20 additions & 1 deletion TDOAuth.m
Expand Up @@ -212,6 +212,25 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)unencodedPathWithoutQuery
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret
{
return [self URLRequestForPath:unencodedPathWithoutQuery
GETParameters:unencodedParameters
scheme:@"http"
host:host
consumerKey:consumerKey
consumerSecret:consumerSecret
accessToken:accessToken
tokenSecret:tokenSecret];
}

+ (NSURLRequest *)URLRequestForPath:(NSString *)unencodedPathWithoutQuery
GETParameters:(NSDictionary *)unencodedParameters
scheme:(NSString *)scheme
host:(NSString *)host
consumerKey:(NSString *)consumerKey
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret;
{
if (!host || !unencodedPathWithoutQuery)
return nil;
Expand All @@ -236,7 +255,7 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)unencodedPathWithoutQuery
}

oauth->method = @"GET";
oauth->url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://%@%@", host, path]];
oauth->url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@://%@%@", scheme, host, path]];

NSURLRequest *rq = [oauth request];
[oauth->url release];
Expand Down

0 comments on commit f632090

Please sign in to comment.