401未授权使用OAuth的雅虎 [英] 401 Unauthorized using Yahoo OAuth

查看:195
本文介绍了401未授权使用OAuth的雅虎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的代码,每次返回一个401未经授权错误在这一点:

My below code returns a 401 Unauthorized error each time at the this point:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://query.yahooapis.com/v1/yql?q=select%20fields.value%20from%20social.contacts%20where%20guid%3Dme&diagnostics=false");
request.Headers.Add(
    "Authorization: OAuth " +
    "realm=\"" + "yahooapis.com" + "\"," +
    "oauth_consumer_key=\"" + ConfigurationManager.AppSettings["yahoo_oauth_consumer_key"] + "\"," +
    "oauth_nonce=\"" + Guid.NewGuid().ToString() + "\"," +
    "oauth_signature_method=\"" + "PLAINTEXT" + "\"," +
    "oauth_timestamp=\"" + ((DateTime.UtcNow.Ticks - new DateTime(1970, 1, 1).Ticks) / (1000 * 10000)).ToString() + "\"," +
    "oauth_token=\"" + accessToken.TokenValue + "\"," +
    "oauth_version=\"1.0" + "\"," +
    "oauth_signature=\"" + ConfigurationManager.AppSettings["yahoo_oauth_signature"] + "%26" + "\""
);
StreamReader streamReader = new StreamReader(request.GetResponse().GetResponseStream(), true);



当我踏进代码每次我看到所有的信息是存在的,雅虎要求的有头,但每次我得到这个401。

And when I step into the code everytime I see all the info is there that Yahoo requests to have in the header, yet everytime I get this 401.

推荐答案

正如我敢肯定你知道,401表示不认可。这可能意味着你的签名是无效的。

As I'm sure you know, 401 means not authorised. It probably means that your signature is not valid.

您不要张贴所有的代码,但我看不出它可能正确生成正确的签名,因为你的签名方法似乎没有采取任何的参数 - 最引人关注的时间戳和随机数 - 作为输入。如果您已经计算正确的签名,则需要使用授权头完全相同的时间戳和随机数;使用的不同的一个将意味着,签名是无效

You don't post all of your code but I can't see how it could possibly correctly generate the correct signature, since your signature method seems not to take any of the parameters -- most tellingly the timestamp and nonce -- as input. If you've already calculated the signature correctly, then you need to use the exact same timestamp and nonce in the Authorized header; using a different one will mean that the signature is not valid.

这篇关于401未授权使用OAuth的雅虎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆