我尝试从我的 C# 应用程序运行用户授权 https://api.quickblox.com/auth.json 。我收到响应错误代码 **422 意外签名。有谁知道这意味着什么或如何调试错误?
我发送了以下字符串作为参数:
{ "application_id": "MYAPPID",
"auth_key": "MYAUTHKEY",
"timestamp": "1394632995",
"nonce": "487",
"signature": "6bf130657ee04e68ff41a08ace44480f90b49f11",
"user": {
"login": "mylogin",
"password": "mypassword"
}
}
最佳答案
这意味着您的签名值错误;
有关签名生成的更多信息请参见 http://quickblox.com/developers/Authentication_and_Authorization#Signature_generation
您可以在此处找到一些 C# 示例 https://github.com/QuickBlox/SimpleSample-BackgroundMode-WindowsPhone7/blob/master/QuickBloxSDK-Silverlight/QuickBlox.cs
StringBuilder signature = new StringBuilder();
signature.Append("application_id");
signature.Append("=");
signature.Append(this.ApplicationId.ToString());
signature.Append("&");
signature.Append("auth_key");
signature.Append("=");
signature.Append(this.AuthenticationKey);
signature.Append("&");
signature.Append("nonce");
signature.Append("=");
signature.Append(randomResult);
signature.Append("&");
signature.Append("timestamp");
signature.Append("=");
signature.Append(ts.ToString());
byte[] key = Encoding.UTF8.GetBytes(this.AuthenticationSecret);
this.Encode(signature.ToString(),key)
private string Encode(string input, byte[] key)
{
HMACSHA1 myhmacsha1 = new HMACSHA1(key);
byte[] byteArray = Encoding.UTF8.GetBytes(input);
MemoryStream stream = new MemoryStream(byteArray);
return myhmacsha1.ComputeHash(stream).Aggregate("", (s, e) => s + String.Format("{0:x2}", e), s => s);
}
关于http - 用户授权错误 422 "Unexpected signature",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22353097/