Skip to content
Browse files

fixes Auth headers not working for oauth token methods

  • Loading branch information...
1 parent d2e05cb commit f4fadd59b43b0faa3cf46f396a472149791e86c9 @zagraves zagraves committed
Showing with 13 additions and 8 deletions.
  1. +9 −6 Source/YOSSocial/YOSAuthRequest.m
  2. +4 −2 Source/YOSSocial/YOSSession.m
View
15 Source/YOSSocial/YOSAuthRequest.m
@@ -50,8 +50,7 @@ - (YOSRequestToken *)fetchRequestTokenWithCallbackUrl:(NSString *)callbackUrl
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@",self.baseUrl,@"oauth",self.apiVersion,method];
NSURL *url = [NSURL URLWithString:requestUrl];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
- [requestParameters autorelease];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
callbackUrl = (callbackUrl != nil) ? callbackUrl : kOAuthOutOfBand;
[requestParameters setValue:callbackUrl forKey:@"oauth_callback"];
@@ -64,16 +63,19 @@ - (YOSRequestToken *)fetchRequestTokenWithCallbackUrl:(NSString *)callbackUrl
[client setRequestUrl:url];
[client setHTTPMethod:@"POST"];
[client setRequestParameters:requestParameters];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
YOSResponseData *response = [client sendSynchronousRequest];
+ NSLog(@"%@", response.responseText);
+
if(!response.didSucceed) {
return nil;
}
YOSRequestToken *requestToken = [YOSRequestToken tokenFromResponse:response.data];
- return requestToken;
+ return (requestToken.key && requestToken.secret) ? requestToken : nil;
}
- (NSURL *)authUrlForRequestToken:(YOSRequestToken *)requestToken
@@ -93,8 +95,7 @@ - (YOSAccessToken *)fetchAccessToken:(YOAuthToken *)requestOrAccessToken withVer
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@", self.baseUrl, @"oauth", self.apiVersion, method];
NSURL *url = [NSURL URLWithString:requestUrl];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
- [requestParameters autorelease];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
if(verifier != nil) {
[requestParameters setValue:verifier forKey:@"oauth_verifier"];
@@ -111,6 +112,7 @@ - (YOSAccessToken *)fetchAccessToken:(YOAuthToken *)requestOrAccessToken withVer
[client setRequestUrl:url];
[client setHTTPMethod:@"POST"];
[client setRequestParameters:requestParameters];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
YOSResponseData *response = [client sendSynchronousRequest];
@@ -119,7 +121,8 @@ - (YOSAccessToken *)fetchAccessToken:(YOAuthToken *)requestOrAccessToken withVer
}
YOSAccessToken *accessToken = [YOSAccessToken tokenFromResponse:response.data];
- return accessToken;
+
+ return (accessToken.key && accessToken.secret) ? accessToken : nil;
}
@end
View
6 Source/YOSSocial/YOSSession.m
@@ -121,7 +121,7 @@ - (BOOL)resumeSession
return TRUE;
}
} else if(self.accessToken) {
- if(![accessToken key] || ![accessToken secret]) {
+ if(!accessToken.key || !accessToken.secret) {
return FALSE;
}
@@ -168,7 +168,7 @@ - (void)sendUserToAuthorizationWithCallbackUrl:(NSString *)callbackUrl
YOSRequestToken *newRequestToken = [tokenAuthRequest fetchRequestTokenWithCallbackUrl:callbackUrl];
// if it looks like we have a valid request token
- if(newRequestToken.key && newRequestToken.secret) {
+ if(newRequestToken && newRequestToken.key && newRequestToken.secret) {
// store the request token for later use
[self setRequestToken:newRequestToken];
[self saveSession];
@@ -187,6 +187,8 @@ - (void)sendUserToAuthorizationWithCallbackUrl:(NSString *)callbackUrl
[[NSWorkspace sharedWorkspace] openURL:authorizationUrl];
#endif
+ } else {
+ // NSLog(@"error fetching request token. check your consumer key and secret.");
}
}

0 comments on commit f4fadd5

Please sign in to comment.
Something went wrong with that request. Please try again.