如何在我的iPhone应用程序中使用OAuth? [英] How To Use OAuth in My iPhone App?
本文介绍了如何在我的iPhone应用程序中使用OAuth?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将OAuth配置到我的iPhone应用程序中以连接到另一个Web服务,但是我遇到了问题.
I'm trying to configure OAuth into my iPhone app to connect to another web service but I'm having problems with it.
我已经下载了google gtm-oauth文件,并将它们添加到我的项目中.
I have downloaded the google gtm-oauth files and added them to my project.
- (GTMOAuthAuthentication *)myCustomAuth {
NSString *myConsumerKey = @"2342343242"; // pre-registered with service
NSString *myConsumerSecret = @"324234234242"; // 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 = @"RunKeeper";
return auth;
}
- (void)signInToCustomService {
NSURL *requestURL = [NSURL URLWithString:@"https://runkeeper.com/apps/token"];
NSURL *accessURL = [NSURL URLWithString:@"https://runkeeper.com/apps/token"];
NSURL *authorizeURL = [NSURL URLWithString:@"https://runkeeper.com/apps/authorize"];
NSString *scope = @"http://example.com/scope";
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://www.example.com/OAuthCallback"];
// Display the autentication view
GTMOAuthViewControllerTouch *viewController;
viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
language:nil
requestTokenURL:requestURL
authorizeTokenURL:authorizeURL
accessTokenURL:accessURL
authentication:auth
appServiceName:@"RunKeeper"
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];
[[self navigationController] pushViewController:viewController
animated:YES];
}
这是我尝试连接的API: http://developer.runkeeper.com /healthgraph/registration-authorization
This is the API I am trying to connect with: http://developer.runkeeper.com/healthgraph/registration-authorization
推荐答案
首先,阅读oauth.这与您正常的登录名/密码类型auth有点不同.
First, read up on oauth. it's a bit different from your normal login/pw type auth.
第二,您可以在 http://code.google.com/上使用Google的oauth库. p/gtm-oauth/
这篇关于如何在我的iPhone应用程序中使用OAuth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文