iOS:Google身份验证代码

iOS:Google身份验证代码,第1张

概述我正在使用身份验证用户来使用与之关联的Google帐户.问题是,每次用户通过我的应用程序登录时,“允许访问”始终显示在Google的身份验证视图中,即使我已经从先前的测试中单击了“允许访问”.这是正常的还是我的代码错了?请帮帮我们. 我在out中使用以下代码进行登录: - (IBAction)signIn:(id)sender { if(!isSignedIn){ [sel 我正在使用身份验证用户来使用与之关联的Google帐户.问题是,每次用户通过我的应用程序登录时,“允许访问”始终显示在Google的身份验证视图中,即使我已经从先前的测试中单击了“允许访问”.这是正常的还是我的代码错了?请帮帮我们.

我在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."]; }

这是代表:

- (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;    }}

和awakeFromNib:

- (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;}

顺便说一句,我对这些代码的引用是在这个链接上:http://code.google.com/p/gtm-oauth2/wiki/Introduction#Using_the_OAuth_2_Controllers

解决方法 来自文档:

The keychain item name is used to save the token on the user’s keychain,and should IDentify both your application name and the service name(s). If keychainItemname is nil,the token will not be saved,and the user will have to sign in again the next time the application is run.

http://code.google.com/p/gtm-oauth2/wiki/Introduction

因此,从您的代码中,它取决于kKeychainItemname的设置.

我以为在阅读文档时我会对此发表评论.

总结

以上是内存溢出为你收集整理的iOS:Google身份验证代码全部内容,希望文章能够帮你解决iOS:Google身份验证代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1099264.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存