if (![ self isAuthorized ]){
GTMOAuth2WindowController *windowController;
windowController = [[[ GTMOAuth2WindowController alloc ] initWithScope : scope clientID : kClientID clientSecret : kClientSecret keychainItemName : kKeychainItemName resourceBundle : nil ] autorelease ];
[windowController signInSheetModalForWindow : self . window
delegate : self
finishedSelector : @selector (windowController:finishedWithAuth:error:)];
}
the finished selector is defined as:
- ( void )windowController:( GTMOAuth2WindowController *)viewController
finishedWithAuth:( GTMOAuth2Authentication *) auth
error:( NSError *)error {
if (error != nil ) {
NSLog ( @"Authenticated failed" );
NSLog ( @"Error code: %@" , [error localizedDescription ]);
} else {
NSLog ( @"Authentication succeeded" );
[[ self driveService ] setAuthorizer :auth];
}
}
After this process is finished. I am told that authentication has succeeded as there is no error given.
When the user clicks a button to upload a file I first double check to make sure the authentication is still valid:
-( BOOL )isAuthorized{
return [(( GTMOAuth2Authentication *) self . driveService . authorizer ) canAuthorize ];
}
Instead of 1 (TRUE) being returned I get a 0 (FALSE). Why does the authentication become invalid?
I looked at the refresh token myself to see if something was wonky with canAuthorize like this:
NSString *refreshToken = (( GTMOAuth2Authentication *)( self . driveService . authorizer )). refreshToken ;
NSLog ( @"Refresh Token: %@" ,refreshToken);
The refresh token was empty, so something is wrong with the authorization.
What am I doing incorrectly?
Any help is appreciated greatly!!
Thanks!