xudusheng / gdata-objectivec-client

Automatically exported from code.google.com/p/gdata-objectivec-client
Other
0 stars 0 forks source link

GDataOAuthAuthentication canAutorize method unreliable (MacOS) #89

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
In two different machines behaviour changes. In development machine works as 
expected; in test machine, the following code misbehaves (my code itself has a 
lot of errors btw):

// GDataOAuthAuthentication self.auth initialized with scope 
@"http://www.google.com/reader/api/*"
-(void)loadFriends
  if (![self.auth canAuthorize]) { // Check auth status and return if can not authorize
    [[NSAlert alertWithMessageText:@"Not logged in"
                     defaultButton:@"OK"
                   alternateButton:nil
                       otherButton:nil
         informativeTextWithFormat:@"GDataOAuthAuthentication canAutorize returned NO"] runModal];
    return;
  }

  NSMutableURLRequest *friendsRequest =
  [NSMutableURLRequest requestWithURL:[NSURL
                                       URLWithString:@"http://www.google.com/reader/api/0/friend/list?output=json"]];

  // Authorize request with (supposedly) valid GDataOAuthAuthentication object
  [self.auth authorizeRequest:friendsRequest];

  NSLog(@"%@", [friendsRequest allHTTPHeaderFields]); // Output NSURLRequest headers

  NSHTTPURLResponse *response;
  NSError *error;

  // Send synchronous request
  NSData *friendsData =
  [NSURLConnection sendSynchronousRequest:friendsRequest
                        returningResponse:&response
                                    error:&error];
  // Check response
  if ([response statusCode] != 200) {
    friends=nil;
    NSLog(@"Error getting friends: %d", [response statusCode]);
    [[NSAlert alertWithError:error] runModal];
    return;
  }
  // method continues (processing received data)

What is the expected output? What do you see instead?
Expected: either the hand-made alert indicating [self.auth canAuthorize] 
returned NO or no error and subsequent processing of data. This works in 
development machine.
Obtained (in test machine): Second alert pops up and shows "NSURLErrorDomain 
error -1012" (matches kCFURLErrorUserCancelledAuthentication in CFNetwork). 
Console shows a "good looking" Authentication HTTP header. 

What version of the product are you using? On what operating system?
Checked both with 1.12 and trunk from Apr. 13th 2011.
Development machine (works): Mac OS X 10.6.7 (iMac Mid 2010, running 64 bit 
kernel), works running app compiled as either 32 or 64 bit.
Test machine (misbehaves): Mac OS X 10.6.7 (MacMini Early 2006 Core Duo)

Please provide any additional information below.
Same Google account used in both machines.
No console output in application besides manually generated (i.e., no 
Objective-C runtime errors).
Behavior is the same in both machines regardless of object being obtained from 
KeyChain or through initWithScope:language:appServiceName:resourceBundle.

Original issue reported on code.google.com by r.pedroc...@gmail.com on 13 Apr 2011 at 1:13

GoogleCodeExporter commented 9 years ago
Fixed, problem was not with the library itself but with my code: scope was 
incorrect, correct is "http://www.google.com/reader/api" (without "/*").

My apologies.

Original comment by r.pedroc...@gmail.com on 13 Apr 2011 at 2:25

GoogleCodeExporter commented 9 years ago
Thank you for updating the issue report.

Original comment by gregrobbins on 13 Apr 2011 at 4:02