我已经设法了解了Magento实现的OAuth协议的第三部分
http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html
首先,请求令牌调用返回一个令牌,我在UIWebView中向用户显示授权对话框,并在用户按下"Authorize“后提取令牌/验证器。
我使用以下参数调用access_token url
OAuth realm="",
oauth_timestamp="1339756083",
oauth_nonce="d1dc184d236756c42210b746a887edb5bd69cf44",
oauth_signature_method="HMAC-SHA1",
oauth_consumer_key="{censored}",
oauth_version="1.0",
oauth_token="912i72lcu6vzlwk6a3vdj4a3sstbdzqp",
oauth_token_secret="t5cg9qlykkk9411iv0rbul0gnw9fsa0m",
oauth_verifier="9vu02kbymodo63pve091otffvy53rhlf",
oauth_signature="fDwWGeJhatIX6kK4nb%2Bagp4C%2FxU%3D"这是我的Obj-C代码的一部分
NSMutableArray* values = [[NSMutableArray alloc]initWithObjects:self.requestToken,self.requestSecret,verifier, nil];
NSMutableArray* keys = [[NSMutableArray alloc]initWithObjects:@"oauth_token", @"oauth_token_secret", @"oauth_verifier", nil];
NSDictionary* extraParams = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
OAuth* oauth = [[OAuth alloc] initWithConsumerKey:OAUTH_CONSUMER_KEY andConsumerSecret:OAUTH_CONSUMER_SECRET];
NSString* authHeader = [oauth oAuthHeaderForMethod:@"POST" andUrl:ACCESS_TOKEN_URL andParams:extraParams];
NSLog(@"%@", authHeader);
ASIHTTPRequest* request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:ACCESS_TOKEN_URL]];
[request addRequestHeader:@"Authorization" value:authHeader];这就是洋红对我说的话
2012-06-15 12:28:06.052 Versmissen[2175:707] 401 3-> HTTP/1.1 401 Authorization Required -> (null) -> http://{censored}/oauth/token但是,4013不在接口中解释的OAuth错误列表中。我无论如何也找不出哪里出了问题!
发布于 2012-06-15 20:29:01
已修复。需要使用request_secret对身份验证头进行签名
NSString* authHeader = self.oauth oAuthHeaderForMethod:@"POST“andUrl:ACCESS_TOKEN_URL和andParams:extraParams andTokenSecret:self.requestSecret;
:)
https://stackoverflow.com/questions/11049097
复制相似问题