Skip to content

Commit 8eb2452

Browse files
authored
Merge pull request #149 from dkarivalis/sign-url-with-query-component_double-encoding
Sign URL with query component double encoding
2 parents d093f83 + 750d045 commit 8eb2452

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

Classes/Auth/TMOAuth.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <CommonCrypto/CommonHMAC.h>
1313
#import <sys/sysctl.h>
1414
#import "TMSDKFunctions.h"
15+
#import "TMURLEncoding.h"
1516

1617
@interface TMOAuth()
1718

@@ -71,16 +72,7 @@ + (NSURL *)signUrlWithQueryComponent:(NSURL *)URL
7172
token: token
7273
tokenSecret: tokenSecret
7374
timestamp: timestamp];
74-
75-
NSMutableArray *queryItems = [NSMutableArray array];
76-
for (NSString *key in oAuthParameters) {
77-
[queryItems addObject:[NSURLQueryItem queryItemWithName:key value:TMURLEncode(oAuthParameters[key])]];
78-
}
79-
80-
NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithURL:URL resolvingAgainstBaseURL:true];
81-
urlComponents.queryItems = queryItems;
82-
83-
return [urlComponents URL];
75+
return [NSURL URLWithString:[URL.absoluteString stringByAppendingFormat:@"?%@", [TMURLEncoding encodedDictionary:oAuthParameters]]];
8476
}
8577

8678
- (id)initWithURL:(NSURL *)URL

ExampleiOS/ExampleiOSTests/TMOAuthTests.m

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ - (void)testSignUrlWithQueryComponentCalculatesProperSignature {
2525
token:@"token"
2626
tokenSecret:@"tokenSecret"
2727
timestamp:@"1511967770"];
28-
29-
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:signedURL resolvingAgainstBaseURL:false];
30-
NSArray *queryItems = urlComponents.queryItems;
31-
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", @"oauth_signature"];
32-
NSURLQueryItem *queryItem = [queryItems filteredArrayUsingPredicate:predicate].firstObject;
33-
34-
XCTAssert([queryItem.value isEqualToString:@"w%2FLP1MdJwiCfakR3GbW9IoeOz1E%3D"], @"The generated OAuth signature should match the expected value.");
28+
XCTAssert([signedURL.absoluteString isEqualToString:@"https://tumblr.com/?oauth_consumer_key=consumerKey&oauth_nonce=1234&oauth_signature=w/LP1MdJwiCfakR3GbW9IoeOz1E%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1511967770&oauth_token=token&oauth_version=1.0"], @"The generated OAuth signature should match the expected value.");
3529
}
3630

3731
- (void)testInitSetsInstanceVariables {

0 commit comments

Comments
 (0)