From f632090d3b7bc67c198184b65ef262fd1cb60230 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 26 Apr 2011 17:36:09 +0100 Subject: [PATCH] Allow HTTPS for GET requests 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. --- TDOAuth.h | 14 ++++++++++++++ TDOAuth.m | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/TDOAuth.h b/TDOAuth.h index 7c0007c..9f90f96 100644 --- a/TDOAuth.h +++ b/TDOAuth.h @@ -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 diff --git a/TDOAuth.m b/TDOAuth.m index de0ed64..7034f8e 100644 --- a/TDOAuth.m +++ b/TDOAuth.m @@ -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; @@ -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];