I am working with user authentication to use the google account with which it is associated. The problem is that every time a user logs in through my application, “Allow access” always appears in the Google authentication view, even if I clicked “Allow access” from the previous test. Is this normal, or am I doing my codes wrong? Please help me guys.
I used the following codes for loggin in out:
- (IBAction)signIn:(id)sender { if(!isSignedIn){ [self signOutFromAll]; NSString *keychainItemName = nil; // save keychain keychainItemName = kKeychainItemName; NSString *scope = @"https://www.googleapis.com/auth/plus.me"; NSString *clientID = kClientID; NSString *clientSecret = kClientSecret; SEL finishedSel = @selector(viewController:finishedWithAuth:error:); GTMOAuth2ViewControllerTouch *viewController; viewController = [GTMOAuth2ViewControllerTouch controllerWithScope:scope clientID:clientID clientSecret:clientSecret keychainItemName:keychainItemName delegate:self finishedSelector:finishedSel]; [[self navigationController]pushViewController:viewController animated:YES]; } else { [self displayAlertWithMessage:@"Currently Signed in."]; } } - (IBAction)signOut:(id)sender { [self signOutFromAll]; [self displayAlertWithMessage:@"Signed out."]; }
This is for the delegate:
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error{ if(error != nil){ // Authentication failed... NSLog(@"Authentication error: %@", error); NSData *responseData = [[error userInfo] objectForKey:@"data"]; if([responseData length] > 0) NSLog(@"%@", [[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]autorelease]); self.auth = nil; } else { // Authentication succeeded... isSignedIn = YES; self.auth = auth; } }
And awakeFromNib:
- (void)awakeFromNib{
By the way, my link for these codes is located at this link: http://code.google.com/p/gtm-oauth2/wiki/Introduction#Using_the_OAuth_2_Controllers
Aldee
source share