Google OAuth2记住用户

时间:2013-07-14 18:18:41

标签: iphone objective-c oauth youtube-api google-account

我一直在他们的Objective-C库中涉及OAuth2 api Google产品。

无论如何,我很难理解如何让应用程序记住谁登录。我已成功使用以下方法进行身份验证。

我调用以下方法从Google呈现OAuth视图控制器,用户登录,并且我已通过身份验证。但是,每次重新启动应用程序时,它都会再次运行登录屏幕,就像我没有通过身份验证一样。据我了解,我需要有一些钥匙串/令牌记忆,以便它识别最近登录的用户。

但是怎么样?我无法从现有的小文档中解决这个问题。

-(void)authenticateUserFromViewController:(UIViewController *)viewController
{
    GTMOAuth2ViewControllerTouch *authViewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLAuthScopeYouTube
                                                                clientID:kClientID
                                                            clientSecret:kClientSecret
                                                        keychainItemName:kKeychainItemName
                                                                delegate:self
                                                        finishedSelector:@selector(viewController:finishedWithAuth:error:)];

    [viewController.navigationController pushViewController:authViewController animated:YES];
}

-(void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
    if (error != nil)
    {
        // Authentication failed
        NSLog(@"Failed to authorise");
    }
    else
    {
        // Authentication succeeded
        NSLog(@"Authorised");
    }
}

1 个答案:

答案 0 :(得分:1)

我不熟悉Objective-C库,但也许this part of the Google Reference可能有用。它解释了如何使用身份验证令牌以及如何在用户重新启动应用程序时处理钥匙串。

相关问题