Reputation: 4732
I'm trying to configure OAuth into my iPhone app to connect to another web service but I'm having problems with it.
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];
}
This is the API I am trying to connect with: http://developer.runkeeper.com/healthgraph/registration-authorization
Upvotes: 1
Views: 2062
Reputation: 10065
First, read up on oauth. it's a bit different from your normal login/pw type auth.
Second, you can use Google's oauth library at http://code.google.com/p/gtm-oauth/
Upvotes: 2