连接到 XMPP 服务器时 SASL 授权失败
我正在尝试通过 XMPP 服务器使用 SMACK API 连接到 gmail。但得到
错误:使用 PLAIN 机制 SASL 身份验证失败
您可以查看代码。我只是从网上得到的,只是
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(connConfig);
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
在调试窗口中检查过。它用 XML 表示:
<无效的authzid />
我已经有 Gmail 帐户,并且我的 gtalk 也在运行。
I am trying to connect to gmail using SMACK API through XMPP server. but getting the
error : SASL authentication failed using mechanism PLAIN
you can check a glimpse of code. I got it from net only
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(connConfig);
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
I checked in the smack debug window. it says in XML :
< invalid-authzid />
I am already having account on gmail and my gtalk is also running.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也犯了这个错误,但我无法工作。
I also get this mistake, but i can not work.
对于在最初提出并回答此问题多年后寻找可能解决方案的任何人来说,我最近能够通过在
XMPPTCPConnectionConfiguration
上显式设置authzid
值来解决此身份验证错误>。我遇到了一个问题,我的连接配置对于某些客户端 XMPP 服务器工作正常,但对于其他服务器则不然,即使它们都使用 SASL PLAIN 身份验证。经过一些故障排除后,我了解到失败的那些需要
authzid
值。调整我的代码以进行设置后,它可以在之前工作的环境以及失败的环境中工作。以下是我构建连接配置的方式:
具体来说,我需要添加这一行:
.setAuthzid(JidCreate.entityBareFrom(String.format("%s@%s", XMPP_USER, XMPP_DOMAIN)))
For anyone looking for possible solutions to this many years after this was originally asked and answered, I recently was able to get past this authentication error by explicitly setting the
authzid
value on theXMPPTCPConnectionConfiguration
.I was running into an issue where my connection configuration worked fine for some client XMPP servers, but not for others, even though they were all using SASL PLAIN authentication. After some troubleshooting, I learned that the ones that were failing were expecting an
authzid
value. After adjusting my code to set this, it works in both the environments that were working before, as well as the environments that were failing.Here is how I am building my connection configuration:
Specifically I needed to add this line:
.setAuthzid(JidCreate.entityBareFrom(String.format("%s@%s", XMPP_USER, XMPP_DOMAIN)))
您需要在连接之前设置身份验证,即
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
必须出现在
connection.connect()
之前。请参阅我的博客。
You need to set the authentication before you connect viz
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
must appear before
connection.connect()
.See my blog.