Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: Google Authentication Code
    primarykey
    data
    text
    <p>I am working with authenticating user to use the google account he is associated with. The problem is that everytime the user logs in through my app, the "Allow Access" always appears on the Google's authentication view even I had clicked the Allow Access already from previous test. Is this normal or am I doing my codes wrong? Please help me guys.</p> <p>I used the following codes for loggin in an out:</p> <pre><code>- (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."]; } </code></pre> <p>This is for the delegate:</p> <pre><code>- (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] &gt; 0) NSLog(@"%@", [[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]autorelease]); self.auth = nil; } else { // Authentication succeeded... isSignedIn = YES; self.auth = auth; } } </code></pre> <p>And awakeFromNib:</p> <pre><code>- (void)awakeFromNib{ // Fill in the Client ID and Client Secret text fields NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; // First, we'll try to get the saved Google authentication, if any, from the keychain // Normal applications will hardcode in their client ID and client secret, // But the sample app allows the user to enter them in a text field, and saves them in the preferences NSString *clientID = [defaults stringForKey:kGoogleClientIDKey]; NSString *clientSecret = [defaults stringForKey:kGoogleClientSecretKey]; GTMOAuth2Authentication *auth; auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName clientID:clientID clientSecret:clientSecret]; if (auth.canAuthorize) { // There is saved google authentication // self.serviceSegments.selectedSegmentIndex = 0; } // Save the authentication object, which holds the auth tokens self.auth = auth; [self setAuth:auth]; isSignedIn = self.auth.canAuthorize; } </code></pre> <p>By the way my reference for these codes is on this link: <a href="http://code.google.com/p/gtm-oauth2/wiki/Introduction#Using_the_OAuth_2_Controllers" rel="nofollow noreferrer">http://code.google.com/p/gtm-oauth2/wiki/Introduction#Using_the_OAuth_2_Controllers</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload