2014-09-02 48 views
0

我想通過iOS上的OAuth身份驗證連接到Magento REST。我已經有:consumer_key,consumer_secret,token,token_secret和url。使用Chrome Rest客戶端,我可以無問題地連接,但在使用OAUthiOS庫的iOS中,我無法連接。這個庫有一些例子來驗證Facebook和Twitter,但我需要的是連接到我的休息服務。iOS使用OAuth連接到Magento

我迄今爲止嘗試:

NSString *key = @"Authorization"; 
NSString *value = @"OAuth realm="http://www.myweb.com/",oauth_consumer_key="xxxx",oauth_token="yyyyy",oauth_nonce="zzzz",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1111111",oauth_version="1.0",oauth_signature="wwwwww""; 

request = [[OAuthIORequest alloc] init];  
[request addHeaderWithKey:key andValue:value]; 

[request get:PRODUCTS_SERVICE success:^(NSDictionary *output, NSString *body, NSHTTPURLResponse *httpResponse) 
{ 
    NSLog(@"body %@", body); 
}]; 

但沒有happend。我該怎麼辦?有更好的框架嗎?

謝謝!

+0

什麼都沒發生?你能否將其他參數記錄到塊中? – danh 2014-09-02 14:07:50

+0

不,我不能。塊內的代碼永遠不會被調用。 – esteban 2014-09-02 14:10:38

回答

1

我已經解決了這個問題,使用另一個框架:AFNetworking和AFOAuth1Client,而不是OAUthiOS。

AFOAuth1Client * client = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL] key:CONSUMER_KEY secret:CONSUMER_SECRET]; 
[client setOauthAccessMethod:@"GET"]; 
[client setSignatureMethod:AFHMACSHA1SignatureMethod]; 
[client setDefaultHeader:@"Accept" value:@"application/json"]; 
[client setAccessToken:[[AFOAuth1Token alloc] initWithKey:TOKEN secret:TOKEN_SECRET session:nil expiration:nil renewable:FALSE]]; 

NSMutableURLRequest * request =[client requestWithMethod:@"GET" path:PRODUCTS_SERVICE parameters:nil]; 
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 
[client registerHTTPOperationClass:[AFHTTPRequestOperation class]]; 
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 

    NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]); 

} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

    NSLog(@"Error: %@", error); 
}]; 
[operation start]; 
+0

我也遇到了登錄Magento的問題,您能否提供更多詳細的源代碼! – QViet 2015-01-28 14:56:12