-
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
Custom header fields in NXOAuth2Request #132
base: develop
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -163,9 +163,7 @@ - (NSURLConnection *)createConnection; | |
![[requestParameters objectForKey:@"grant_type"] isEqualToString:@"refresh_token"]) { | ||
|
||
// if token is expired don't bother starting this connection. | ||
NSDate *tenSecondsAgo = [NSDate dateWithTimeIntervalSinceNow:(-10)]; | ||
NSDate *tokenExpiresAt = client.accessToken.expiresAt; | ||
if (client.accessToken.refreshToken && [tenSecondsAgo earlierDate:tokenExpiresAt] == tokenExpiresAt) { | ||
if (client.accessToken.refreshToken && client.accessToken.hasExpired) { | ||
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. The merge request is for adding header fields (a useful thing) but please only do that and do not change unrelated code. |
||
[self cancel]; | ||
[client refreshAccessTokenAndRetryConnection:self]; | ||
return nil; | ||
|
@@ -187,6 +185,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"]; | ||
} | ||
|
||
if (client.userAgent && ![startRequest valueForHTTPHeaderField:@"User-Agent"]) { | ||
|
@@ -415,10 +415,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); | ||
|
||
if (shouldRefresh) { | ||
[self cancel]; | ||
[client refreshAccessTokenAndRetryConnection:self]; | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
@interface NXOAuth2Request : NSObject { | ||
@private | ||
NSDictionary *parameters; | ||
NSDictionary *headerFields; | ||
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 think |
||
NSURL *resource; | ||
NSString *requestMethod; | ||
NXOAuth2Account *account; | ||
|
@@ -37,6 +38,14 @@ | |
sendProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler | ||
responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler; | ||
|
||
+ (void)performMethod:(NSString *)method | ||
onResource:(NSURL *)resource | ||
usingParameters:(NSDictionary *)parameters | ||
headerFields:(NSDictionary *)headerFields | ||
withAccount:(NXOAuth2Account *)account | ||
sendProgressHandler:(NXOAuth2ConnectionSendingProgressHandler)progressHandler | ||
responseHandler:(NXOAuth2ConnectionResponseHandler)responseHandler; | ||
|
||
|
||
#pragma mark Lifecycle | ||
|
||
|
@@ -50,6 +59,7 @@ | |
@property (nonatomic, strong, readwrite) NSString *requestMethod; | ||
@property (nonatomic, strong, readwrite) NSURL *resource; | ||
@property (nonatomic, strong, readwrite) NSDictionary *parameters; | ||
@property (nonatomic, strong, readwrite) NSDictionary *headerFields; | ||
|
||
|
||
#pragma mark Signed NSURLRequest | ||
|
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.
Please do not leave in commented out code. If you think this should be removed do so, otherwise remove the comment.