Issue with retrieving auth with Mac OS X app

76 views
Skip to first unread message

Steffen Andersen

unread,
Dec 7, 2015, 9:47:00 AM12/7/15
to Google APIs Client Library for Objective-C

I’m working on a Mac OS X app, where the user will need to access their Google Calendar. However, I can’t get the authentication to work and it doesn’t really make any sense to me why it’s not working.


Google API is installed via Cocoapods: pod ‘Google-API-Client/Calendar'


I’ve got a NSTabViewController inside a NSWindow, when a user clicks a button I called the following:


@property (nonatomic, strong)GTMOAuth2WindowController *windowController;


static NSString *const scope = @"https://www.googleapis.com/auth/calendar";


  • (void)startAuthentication {


   GTMOAuth2Authentication *auth;

    auth  =  [GTMOAuth2WindowController authForGoogleFromKeychainForName:kKeychainItemName clientID:kClientID clientSecret:kClientSecret];

    


if ( auth.canAuthorize) {

return;

}


 self.windowController = [[GTMOAuth2WindowController alloc] initWithScope:scope

                                                                    clientID:kClientID

                                                                clientSecret:kClientSecret

                                                            keychainItemName:kKeychainItemName

                                                              resourceBundle:nil];


[self.windowController  signInSheetModalForWindow:self.view.window

                                             delegate:self

                                     finishedSelector:@selector(windowController:finishedWithAuth:error:)];

}



- (void)windowController:(GTMOAuth2WindowController *)windowController

        finishedWithAuth:(GTMOAuth2Authentication *)auth

                   error:(NSError *)error {

}



Don’t know why, but the selector is never called. From debug I noticed the Fetcher starts, and kGTMOAuth2UserSignedIn gets posted, but it never ends. 


Any ideas why this isn’t working?

David Phillip Oster

unread,
Dec 7, 2015, 10:00:55 AM12/7/15
to google-api-obj...@googlegroups.com
For what it's worth, my working code to access calendar looks like this:

- (void)signIn {

  [self runSigninCompletion:^{ [self fetchCalendarList]; }];

}


- (void)runSigninCompletion:(void(^)(void))signInDoneBlock {

  // Show the OAuth 2 sign-in controller

  NSBundle *frameworkBundle = [NSBundle bundleForClass:[GTMOAuth2WindowController class]];

  GTMOAuth2WindowController *windowController;

  windowController = [GTMOAuth2WindowController controllerWithScope:kGTLAuthScopeCalendar

                                                           clientID:kClientID

                                                       clientSecret:kClientSecret

                                                   keychainItemName:kKeychainItemName

                                                     resourceBundle:frameworkBundle];


  NoteAppDelegate *appDelegate = (NoteAppDelegate *)[NSApp delegate];

  [windowController signInSheetModalForWindow:[appDelegate window]

                            completionHandler:^(GTMOAuth2Authentication *auth,

                                                NSError *error) {

                              if (error == nil) {

                                self.calendarService.authorizer = auth;

                                if (signInDoneBlock) {

                                  signInDoneBlock();

                                }

                              } else {

                                [self presentError:error];

                              }

                              [self postSignInChanged];

  }];

}



--
You received this message because you are subscribed to the Google Groups "Google APIs Client Library for Objective-C" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-api-objective...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages