2011-06-21 38 views
0

我正試圖在silverlight中實現Xmpp協議並嘗試連接到Facebook,在這裏我得到的一切正確,直到<挑戰.. >從服務器獲得。 我使用X Facebook平臺認證。 我曾與下面的代碼這樣做:Silverlight身份驗證中的XMPP實現返回失敗

byte[] ch = Convert.FromBase64String(message.challenge); 
string challenge = System.Text.Encoding.UTF8.GetString(ch, 0, ch.Length); 
string response = ""; 
long callId = DateTime.UtcNow.Ticks; 
MD5 md = new MD5(); 

String signature1 = "api_key=203366556348506" 
+ "call_id=" + callId 
+ "method=auth.xmpp_login" 
+ param[2] 
+ "session_key=" + messageClient.SessionKey 
+ "v=1.0" 
+ messageClient.AppSecret; 
md.Value = signature1; 

response = "method=auth.xmpp_login&api_key=203366556348506&session_key=bc6d6e00462cc2bb73a824bd.4-100001565408667&call_id=" + callId + "&sig=c47d741cb8f18c4e78b990f48e2f63aa&v=1.0&" + param[2]; 


message.Request = "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(response)) + "</response>"; 
this.messageClient.SendMessageAsync(message); 

但我從服務器獲取以下信息:

<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure> 

請讓我知道我錯了。

+0

歡迎來到SO,請花幾分鐘時間閱讀常見問題解答和Markdown文檔(在編輯問題時可以在右側空白處找到有用的synposis)。 – AnthonyWJones

回答

1

嘗試以下代碼:

String signature1 = "api_key=" + messageClient.ApiKey 
    + "call_id=" + callId 
    + "method=auth.xmpp_login" 
    + param[2] 
    + "session_key=" + messageClient.SessionKey 
    + "v=1.0" 
    + messageClient.AppSecret; 

md.Value = signature1; 

response = "method=auth.xmpp_login&api_key=" + messageClient.ApiKey + "&session_key=" + messageClient.SessionKey + "&call_id=" + callId + "&sig=" + md.FingerPrint.ToLower() + "&v=1.0&" + param[2]; 

我已經改變響應字符串上述之一。

這對我來說已經成功了。希望這會幫助你。

+0

非常感謝。這個對我有用。 –