I want to use a REST service, I need OAuth 1 to allow secure authorization. I have the consumer key, the consumer secret, the token and the token secret. In PHP I'm using this:
$apiUrl = 'http://www.web.com/api/rest';
$consumerKey = 'xxxx';
$consumerSecret = 'yyyyyy';
$token = 'zzzzz';
$tokenSecret = 'wwwww';
session_start();
$authType = OAUTH_AUTH_TYPE_AUTHORIZATION;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
$oauthClient->setToken($token, $tokenSecret);
$resourceUrl = "$apiUrl";
$headers = array('Content-Type' => 'application/json');
$oauthClient->fetch($resourceUrl.'/category/2681', array(), OAUTH_HTTP_METHOD_GET, $headers);
$productsList = $oauthClient->getLastResponse();
In Objective C I'm using AFOAuth1Client, but I don't know when and how to set the token in the AFOAuth1Client object like $oauthClient->setToken($token, $tokenSecret);
AFOAuth1Client *oAuth1Client = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:kUrlPre] key:@"consumerKey" secret:@"consumerSecret"];
oAuth1Client.signatureMethod = AFHMACSHA1SignatureMethod;
oAuth1Client.accessToken = [[AFOAuth1Token alloc] initWithKey:@"consumerKey" secret:@"consumerSecret" session:nil expiration:nil renewable:YES]; //I have tried this, but when I add this line I'm getting this error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: oauth_token)' in authorizeUsingOAuthWithRequestTokenPath
[oAuth1Client authorizeUsingOAuthWithRequestTokenPath:@"http://www.web.com/api/rest/category/2681"
userAuthorizationPath:nil //??
callbackURL:nil //I don't need it
accessTokenPath:nil //I don't need it
accessMethod:@"GET"
scope:nil
success:^(AFOAuth1Token *accessToken, id responseObject) {
NSLog(@"Success: %@", accessToken);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
I think I'm using bad uthorizeUsingOAuthWithRequestTokenPath. How can I parse my PHP code to Objective C. I'm opened to use other OAuth frameworks.