Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Preserve trailing slash in signature base

This patch changes the library to preserve the trailing slash when computing
the signature base string.

-[NSURL path] function always excludes a trailing slash. Since the oauth specification
makes no mention of excluding a trailing slash, it seems correct to preserve it. At least
one python server-side library will not accept requests without this patch.
  • Loading branch information...
commit 60f0c6721cf9cd883a87d451c04623b95a0f27d0 1 parent e40e2d0
@nwg nwg authored
Showing with 19 additions and 2 deletions.
  1. +1 −0  OAuth+Additions.h
  2. +16 −0 OAuth+Additions.m
  3. +2 −2 OAuthCore.m
View
1  OAuth+Additions.h
@@ -10,6 +10,7 @@
@interface NSURL (OAuthAdditions)
+ (NSDictionary *)ab_parseURLQueryString:(NSString *)query;
+- (NSString *)ab_actualPath;
@end
View
16 OAuth+Additions.m
@@ -26,6 +26,22 @@ + (NSDictionary *)ab_parseURLQueryString:(NSString *)query
return [NSDictionary dictionaryWithDictionary:dict];
}
+- (NSString *)ab_actualPath
+{
+ NSString *urlString = [self absoluteString];
+
+ NSRange range = [urlString rangeOfString:@"?"];
+ if (range.location != NSNotFound) {
+ urlString = [urlString substringToIndex:range.location];
+ }
+
+ if ([urlString hasSuffix:@"/"]) {
+ return [NSString stringWithFormat:@"%@/", [self path]];
+ }
+
+ return [self path];
+}
+
@end
@implementation NSString (OAuthAdditions)
View
4 OAuthCore.m
@@ -80,9 +80,9 @@ static NSInteger SortParameter(NSString *key1, NSString *key2, void *context) {
NSString *normalizedURLString;
if([url port] == nil) {
- normalizedURLString = [NSString stringWithFormat:@"%@://%@%@", [url scheme], [url host], [url path]];
+ normalizedURLString = [NSString stringWithFormat:@"%@://%@%@", [url scheme], [url host], [url ab_actualPath]];
} else {
- normalizedURLString = [NSString stringWithFormat:@"%@://%@:%@%@", [url scheme], [url host], [url port], [url path]];
+ normalizedURLString = [NSString stringWithFormat:@"%@://%@:%@%@", [url scheme], [url host], [url port], [url ab_actualPath]];
}
NSString *signatureBaseString = [NSString stringWithFormat:@"%@&%@&%@",
Please sign in to comment.
Something went wrong with that request. Please try again.