C# Oauth 问题
我正在尝试创建 oauth 签名。但我不知道我做错了什么,因为该网站给出了未经授权的错误。我使用的是oauth 1.0版本。方法是 HMAC-SHA1,它是基于 google 的 oauth。我的基本字符串是正确的,因为它使用示例输出对其进行了检查。 我的代码:
string oauthSig = "";
string baseString = HttpUtility.UrlEncode(httpMethod.ToUpper()) + "&" +
HttpUtility.UrlEncode(url) + "&" +
HttpUtility.UrlEncode("oauth_callback="+callback+"&"+
"oauth_consumer_key="+consumerKey+"&"+
"oauth_nonce="+nounce+"&"+
"oauth_signature_method="+sigMethod+"&"+
"oauth_timestamp=" + timestamp + "&" +
"oauth_version=" + version
);
HMACSHA1 myhmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(HttpUtility.UrlEncode(consumeSecret)),true);
byte[] hashValue = myhmacsha1.ComputeHash(Encoding.UTF8.GetBytes(baseString));
oauthSig = Convert.ToBase64String(hashValue);
如果我做错了什么,请告诉我。
谢谢
I am trying to create oauth signature. But I dont know what I am doing wrong because the site giving unauthorize error. I am using oauth version 1.0. Method is HMAC-SHA1 and it is google based oauth. My base string is correct because it checked it with sample output.
My code :
string oauthSig = "";
string baseString = HttpUtility.UrlEncode(httpMethod.ToUpper()) + "&" +
HttpUtility.UrlEncode(url) + "&" +
HttpUtility.UrlEncode("oauth_callback="+callback+"&"+
"oauth_consumer_key="+consumerKey+"&"+
"oauth_nonce="+nounce+"&"+
"oauth_signature_method="+sigMethod+"&"+
"oauth_timestamp=" + timestamp + "&" +
"oauth_version=" + version
);
HMACSHA1 myhmacsha1 = new HMACSHA1(Encoding.UTF8.GetBytes(HttpUtility.UrlEncode(consumeSecret)),true);
byte[] hashValue = myhmacsha1.ComputeHash(Encoding.UTF8.GetBytes(baseString));
oauthSig = Convert.ToBase64String(hashValue);
Please tell me if I am doing anything wrong.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
签名的关键应该是:
CONSUMER_SECRET + '&' + TOKEN_SECRET
由于您还没有令牌机密,因此您应该使用 CONSUMER_SECRET 和与号 (&) 作为签名的密钥。
编辑,进一步说明:
我尚未测试该代码,但它是从 oauth.googlecode.com - OAuthBase.cs。我强烈建议您检查一下,它应该可以满足您想要的一切。
The key to the signature should be:
CONSUMER_SECRET + '&' + TOKEN_SECRET
And since you do not have a token secret yet, you should use CONSUMER_SECRET and an ampersand (&) as the key to the signature.
Edit, further clarification:
I've not tested the code but i've taken it from from oauth.googlecode.com - OAuthBase.cs. I highly recommend checking it out, it should do everything you want.