gpt4 book ai didi

iOS:谷歌验证码

转载 作者:可可西里 更新时间:2023-11-01 03:32:33 26 4
gpt4 key购买 nike

我正在对用户进行身份验证,以使用与他关联的 Google 帐户。问题是每次用户通过我的应用程序登录时,“允许访问”总是出现在 Google 的身份验证 View 中,即使我已经在之前的测试中点击了允许访问。这是正常现象还是我的代码有误?请帮帮我。

我使用以下代码登录和退出:

- (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:谷歌验证码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9224309/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com