-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/header fields #168
base: develop
Are you sure you want to change the base?
Changes from 8 commits
5851287
ad83f96
6e89cd5
732f7d5
a16e2f6
e005d1a
c6b05ed
f26a429
645d723
062e59f
8fdfb81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,8 @@ - (NSURLConnection *)createConnection; | |
|
||
if (oauthAuthorizationHeader) { | ||
[startRequest setValue:oauthAuthorizationHeader forHTTPHeaderField:@"Authorization"]; | ||
// some services require the access token in the "t_auth_token" header field | ||
[startRequest setValue:client.accessToken.accessToken forHTTPHeaderField:@"t_auth_token"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be that some services require this, but this is not part of the IETF standard in any RFC that I'm aware of, or am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was making this request based on the previous one, removed Code! |
||
} | ||
|
||
if (client.userAgent && ![startRequest valueForHTTPHeaderField:@"User-Agent"]) { | ||
|
@@ -415,10 +417,10 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon | |
} | ||
} | ||
} | ||
if (/*self.statusCode == 401 // TODO: check for status code once the bug returning 500 is fixed | ||
&&*/ client.accessToken.refreshToken != nil | ||
&& authenticateHeader | ||
&& [authenticateHeader rangeOfString:@"expired_token"].location != NSNotFound) { | ||
|
||
BOOL shouldRefresh = (self.statusCode == 401) && (client.accessToken.hasExpired) && (client.accessToken.refreshToken != nil); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm for using a BOOL it makes things more clear. As for the commented out code, that was an oversight in another merge and it's removed in 5fe6147 |
||
|
||
if (shouldRefresh) { | ||
[self cancel]; | ||
[client refreshAccessTokenAndRetryConnection:self]; | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ @implementation NXOAuth2Request | |
+ (void)performMethod:(NSString *)aMethod | ||
onResource:(NSURL *)aResource | ||
usingParameters:(NSDictionary *)someParameters | ||
headerFields:(NSDictionary *)headerFields | ||
withAccount:(NXOAuth2Account *)anAccount | ||
sendProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler | ||
responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler; | ||
|
@@ -45,9 +46,24 @@ + (void)performMethod:(NSString *)aMethod | |
method:aMethod | ||
parameters:someParameters]; | ||
request.account = anAccount; | ||
request.customHeaderFields = headerFields; | ||
[request performRequestWithSendingProgressHandler:progressHandler responseHandler:responseHandler]; | ||
} | ||
|
||
+ (void)performMethod:(NSString *)aMethod | ||
onResource:(NSURL *)aResource | ||
usingParameters:(NSDictionary *)someParameters | ||
withAccount:(NXOAuth2Account *)anAccount | ||
sendProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler | ||
responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler; | ||
{ | ||
[self performMethod:aMethod | ||
onResource:aResource | ||
usingParameters:someParameters | ||
withAccount:anAccount | ||
sendProgressHandler:progressHandler | ||
responseHandler:responseHandler]; | ||
} | ||
|
||
#pragma mark Lifecycle | ||
|
||
|
@@ -66,6 +82,7 @@ - (instancetype)initWithResource:(NSURL *)aResource method:(NSString *)aMethod p | |
#pragma mark Accessors | ||
|
||
@synthesize parameters; | ||
@synthesize customHeaderFields; | ||
@synthesize resource; | ||
@synthesize requestMethod; | ||
@synthesize account; | ||
|
@@ -105,6 +122,15 @@ - (void)performRequestWithSendingProgressHandler:(NXOAuth2ConnectionSendingProgr | |
|
||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.resource]; | ||
[request setHTTPMethod:self.requestMethod]; | ||
|
||
if (self.customHeaderFields) { | ||
[self.customHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *field, NSString *value, BOOL *stop) { | ||
if ([field isKindOfClass:NSString.class] && [value isKindOfClass:NSString.class]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather |
||
[request setValue:value forHTTPHeaderField:field]; | ||
} | ||
}]; | ||
} | ||
|
||
self.connection = [[NXOAuth2Connection alloc] initWithRequest:request | ||
requestParameters:self.parameters | ||
oauthClient:self.account.oauthClient | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this change? These characters need to be escaped here for URL encoding to be RFC compliant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was making this request based on the previous one, re-added Code!