繁体   English   中英

iOS使用OAuth连接到Magento

[英]iOS connect to Magento using OAuth

我正在尝试通过iOS上的OAuth身份验证连接到Magento REST。 我已经拥有:consumer_key,consumer_secret,token,token_secret和url。 使用Chrome Rest Client,我可以毫无问题地连接,但是在使用OAUthiOS库的iOS中,我无法连接。 该库提供了一些示例,可通过Facebook和Twitter进行身份验证,但是我需要连接到我的其余服务。

到目前为止我尝试过的是:

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);
 }];

但是什么也没发生。 我该怎么办? 有没有更好的框架?

谢谢!

我已经使用另一个框架解决了此问题: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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM