0

我需要在我的 iOS 应用程序中实现 GTMOAuth ..为此我已经下载了 OAuth 库并编写了一些代码

- (GTMOAuthAuthentication *)myCustomAuth {


NSString *myConsumerKey = @"f964039f2d7bc82054";    // pre-registered with service
NSString *myConsumerSecret = @"c9a749c0f1e30c9246a3be7b2586434f"; // pre-assigned by service

GTMOAuthAuthentication *auth;
auth = [[[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
                                                    consumerKey:myConsumerKey
                                                     privateKey:myConsumerSecret] autorelease];

// setting the service name lets us inspect the auth object later to know
// what service it is for
auth.serviceProvider = @"Custom Auth Service";

return auth;
}



- (void)signInToCustomService {

NSURL *requestURL = [NSURL URLWithString:@"http://alpha.easyreceipts.com/api/v1/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:@"http://alpha.easyreceipts.com/api/v1/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:@"http://alpha.easyreceipts.com/api/v1/oauth/authorize"];
NSString *scope = @"http://alpha.easyreceipts.com/api/v1/";

GTMOAuthAuthentication *auth = [self myCustomAuth];

// set the callback URL to which the site should redirect, and for which
// the OAuth controller should look to determine when sign-in has
// finished or been canceled
//
// This URL does not need to be for an actual web page
[auth setCallback:@"http://alpha.easyreceipts.com/api/v1/"];

// Display the autentication view
GTMOAuthViewControllerTouch *viewController;
viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
                                                            language:nil
                                                     requestTokenURL:requestURL
                                                   authorizeTokenURL:authorizeURL
                                                      accessTokenURL:accessURL
                                                      authentication:auth
                                                      appServiceName:@"My App: Custom Service"
                                                            delegate:self
                                                           finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];
viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"myID"];

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

但进一步我不知道如何实现它。请帮助我提前谢谢

4

1 回答 1

0

首先,如果你想用 GTM 库实现一个 OAuth 认证系统,你应该得到这个。您可以在此处找到 GTMOAuth 的完整来源。

其次,您也可以在 git 存储库中找到如何使用它的示例。您应该找到至少进行身份验证所需的一切。如果您还有任何问题,请提供更多信息。

于 2012-10-29T14:15:05.620 回答