Skip to content

Commit df8a487

Browse files
author
Christopher Swasey
committed
Bringing in fix for non-standard ports, courtesy of @theorm
1 parent a777311 commit df8a487

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

GCOAuth.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@
9898
tokenSecret:(NSString *)tokenSecret;
9999
@end
100100

101+
@interface NSString (GCOAuthAdditions)
102+
103+
// better percent escape
104+
- (NSString *)pcen;
105+
@end
106+
107+
@interface NSURL (GCOAuthURL)
108+
109+
/*
110+
Get host:port from URL unless port is 80 or 443 (http://tools.ietf.org/html/rfc5849#section-3.4.1.2). Otherwis reurn only host.
111+
*/
112+
- (NSString *)hostAndPort;
113+
@end
101114
/*
102115
103116
XAuth example (because you may otherwise be scratching your head):

GCOAuth.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ - (NSString *)signature;
7676
// generate signature base
7777
- (NSString *)signatureBase;
7878

79-
@end
80-
@interface NSString (GCOAuthAdditions)
81-
82-
// better percent escape
83-
- (NSString *)pcen;
84-
8579
@end
8680

8781
@implementation GCOAuth
@@ -171,7 +165,7 @@ - (NSString *)signatureBase {
171165
NSURL *URL = self.URL;
172166
NSString *URLString = [NSString stringWithFormat:@"%@://%@%@",
173167
[[URL scheme] lowercaseString],
174-
[[URL host] lowercaseString],
168+
[[URL hostAndPort] lowercaseString],
175169
[URL path]];
176170

177171
// create components
@@ -318,6 +312,17 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)path
318312
}
319313

320314
@end
315+
316+
@implementation NSURL (GCOAuthURL)
317+
- (NSString *)hostAndPort {
318+
if ([self port] != nil && [[self port] intValue] != 80 && [[self port] intValue] != 443) {
319+
return [NSString stringWithFormat:@"%@:%@", [self host], [self port]];
320+
} else {
321+
return [self host];
322+
}
323+
}
324+
@end
325+
321326
@implementation NSString (GCOAuthAdditions)
322327
- (NSString *)pcen {
323328
CFStringRef string = CFURLCreateStringByAddingPercentEscapes(NULL,

0 commit comments

Comments
 (0)