简体   繁体   English

使用Gloox的Facebook聊天XMPP身份验证?

[英]Facebook chat XMPP authentication with Gloox?

Well, I'm probably doing something silly, but I've been beating my head against the wall with this for the past few hours, and so far I have no idea what I've been doing wrong. 好吧,我可能在做一些愚蠢的事情,但是在过去的几个小时中,我一直在用这种方法将自己的头靠在墙上,到目前为止,我还不知道自己在做错什么。

At the moment I'm trying to make this work with PLAIN SASL because it seems like Facebook actively makes OAuth2 a pain for non-Web apps, but it really makes no difference to me as long as I can get this to work somehow. 目前,我正在尝试使用PLAIN SASL进行这项工作,因为Facebook似乎在积极主动地使OAuth2成为非Web应用程序的痛苦,但是只要我能以某种方式使它起作用,这对我来说实际上没有任何区别。

Current code: 当前代码:

_client = new Client(JID(username /* no @chat.facebook.com */), password);

_client->setServer("chat.facebook.com");
_client->setPort(5222);

_client->setSASLMechanisms(gloox::SaslMechPlain);
_client->setTls(gloox::TLSPolicy::TLSRequired);

_client->connect(false);
_client->login(); // not necessary?

QThread::sleep(10); // arbitrary sleep; should be sufficient

std::cout << _client->authed() << std::endl; // false
std::cout << _client->authError() << std::endl; // AuthErrorUndefined

_client->rosterManager()->fill();

// neither one has any effect
MessageSession(_client, JID("friend@chat.facebook.com")).send("balls");
MessageSession(_client, JID("friend")).send("balls");

std::cout << _client->rosterManager()->roster()->size() << std::endl; // 0

Edit: For that matter, I can't get Gloox working with Gmail either (haven't tried any other XMPP servers). 编辑:就此而言,我也无法让Gloox与Gmail一起使用(没有尝试过任何其他XMPP服务器)。

  1. Your JID is indeed username@chat.facebook.com , not only username - and it is very important to SASL authentication, it will not work with wrong JID. 您的JID确实是username@chat.facebook.com ,不仅是username -这对SASL身份验证非常重要,它不适用于错误的JID。
  2. Facebook chat supports SASL PLAIN authentication over SSL/TLS connection, as well as DIGEST-MD5 Facebook聊天支持通过SSL / TLS连接以及DIGEST-MD5的SASL PLAIN身份验证
  3. Google talk supports SASL PLAIN over TLS too Google Talk也支持基于TLS的SASL PLAIN
  4. You can see supported SASL mechanisms in the first <stream:features>...</stream:features> packet from the server 您可以在服务器的第一个<stream:features>...</stream:features>数据包中看到受支持的SASL机制
  5. It will be much better if your show error logs 如果您显示错误日志会更好

Well, I'm still not 100% sure what the problem with Gloox was, but the following roughly equivalent Swiften code works with no issues. 好吧,我仍然不是100%地确定Gloox的问题是什么,但是下面大致等效的Swiften代码没有问题。

SimpleEventLoop* eventLoop = new SimpleEventLoop();
BoostNetworkFactories networkFactories(eventLoop);

_client = new Client
(
    username.append("@chat.facebook.com").toStdString(),
    password.toStdString(),
    &networkFactories
);
_client->setAlwaysTrustCertificates();

_client->onConnected.connect([&] () { signInStatus = SignInStatus::Success; });
_client->onDisconnected.connect([&] (const boost::optional<ClientError>& e) {
    signInStatus = SignInStatus::InvalidCredentials;
});

_client->connect();
std::thread([&] () { eventLoop->run(); }).detach();

while (signInStatus == SignInStatus::NotSignedIn)
{
    QThread::sleep(1);
}

if (signInStatus == SignInStatus::InvalidCredentials)
{
    return signInStatus;
}

_client->requestRoster();
QThread::sleep(5);
std::cout << _client->getRoster()->getItems()[0].getName() << std::endl;

Message::ref message(new Message());
message->setTo(_client->getRoster()->getItems()[0].getJID());
message->setFrom(JID());
message->setBody("balls");
_client->sendMessage(message);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM