gpt4 book ai didi

iphone - GTM OAuth iOS5 保留访问 token

转载 作者:行者123 更新时间:2023-11-29 11:10:51 26 4
gpt4 key购买 nike

我不希望用户每次启动应用程序时都经过授权步骤。相反,我希望应用程序保存来自 3 条腿的 OAuth 1.0a 进程的访问 token ,并使用它们来访问 protected 资源。

这是我到目前为止所拥有的,它每次都要求我授权(而不是登录)。

有什么想法吗?请帮忙。使用 GTMOauth 库。

    - (void)signIn
{
activityIndicator.hidden = NO;
[activityIndicator startAnimating];

NSURL *requestURL = [NSURL URLWithString:@"http://webservice/oauth/request_token/"];
NSURL *accessURL = [NSURL URLWithString:@"http://webservice/oauth/access_token/"];
NSURL *authorizeURL = [NSURL URLWithString:@"http://webservice/oauth/authorize/"];
NSString *scope = @"http://webservice";

auth = [self getAuthForWebservice];

[auth setCallback:@"http://webservice/OAuthCallback"];

GTMOAuthViewControllerTouch *viewController;
viewController = [[GTMOAuthViewControllerTouch alloc] initWithScope:scope
language:nil
requestTokenURL:requestURL
authorizeTokenURL:authorizeURL
accessTokenURL:accessURL
authentication:auth
appServiceName:@"webservice"
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];

[[self navigationController] pushViewController:viewController
animated:YES];

[self navigationController].navigationBarHidden = YES;
}


- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuthAuthentication *)auth
error:(NSError *)error {
if (error == nil) {
[self performSelector:@selector(doAnAuthenticatedAPIFetch)];

}
}

- (void)doAnAuthenticatedAPIFetch {
NSString *urlStr = @"http://webservice/resource/";

NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[auth authorizeRequest:request];

NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];

最佳答案

gtm-oauth Controller 将 token 保存到钥匙串(keychain)中。当应用程序再次启动时从钥匙串(keychain)中读取它,如图 here .

关于iphone - GTM OAuth iOS5 保留访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11650016/

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