连接到 XMPP 服务器时 SASL 授权失败

发布于 2024-09-19 08:39:25 字数 528 浏览 3 评论 0原文

我正在尝试通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满身野味 2024-09-26 08:39:26
    ConnectionConfiguration cc = new ConnectionConfiguration(
            "vietnam.agilemobile.com", 5222, vietnam.agilemobile.com");
    XMPPConnection connection = new XMPPConnection(cc);
    try {
        SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        connection.connect();
        Log.e("LOGIN", "" + 111);
        // You have to put this code before you login
        Log.e("LOGIN", "" + 222);
        // You have to specify your gmail addres WITH @gmail.com at the end
        connection.login("nemodo", "123456", "resource");
        Log.e("LOGIN", "" + 333);
        // See if you are authenticated
        System.out.println(connection.isAuthenticated());

    } catch (XMPPException e1) {
        e1.printStackTrace();
    }

我也犯了这个错误,但我无法工作。

    ConnectionConfiguration cc = new ConnectionConfiguration(
            "vietnam.agilemobile.com", 5222, vietnam.agilemobile.com");
    XMPPConnection connection = new XMPPConnection(cc);
    try {
        SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        connection.connect();
        Log.e("LOGIN", "" + 111);
        // You have to put this code before you login
        Log.e("LOGIN", "" + 222);
        // You have to specify your gmail addres WITH @gmail.com at the end
        connection.login("nemodo", "123456", "resource");
        Log.e("LOGIN", "" + 333);
        // See if you are authenticated
        System.out.println(connection.isAuthenticated());

    } catch (XMPPException e1) {
        e1.printStackTrace();
    }

I also get this mistake, but i can not work.

自由如风 2024-09-26 08:39:26

对于在最初提出并回答此问题多年后寻找可能解决方案的任何人来说,我最近能够通过在 XMPPTCPConnectionConfiguration 上显式设置 authzid 值来解决此身份验证错误>。

我遇到了一个问题,我的连接配置对于某些客户端 XMPP 服务器工作正常,但对于其他服务器则不然,即使它们都使用 SASL PLAIN 身份验证。经过一些故障排除后,我了解到失败的那些需要 authzid 值。调整我的代码以进行设置后,它可以在之前工作的环境以及失败的环境中工作。

以下是我构建连接配置的方式:

XMPPTCPConnectionConfiguration.builder()
                              .setHost(XMPP_DOMAIN)
                              .setXmppDomain(XMPP_DOMAIN)
                              .setPort(XMPP_PORT)
                              .setCompressionEnabled(true) // optional, not all servers will support this
                              .setUsernameAndPassword(XMPP_USER, XMPP_PASSWORD)
                              .setResource(XMPP_RESOURCE)
                              .setAuthzid(JidCreate.entityBareFrom(String.format("%s@%s", XMPP_USER, XMPP_DOMAIN))) // <-- this was the change I needed
                              .build();

具体来说,我需要添加这一行:

.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 the XMPPTCPConnectionConfiguration.

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:

XMPPTCPConnectionConfiguration.builder()
                              .setHost(XMPP_DOMAIN)
                              .setXmppDomain(XMPP_DOMAIN)
                              .setPort(XMPP_PORT)
                              .setCompressionEnabled(true) // optional, not all servers will support this
                              .setUsernameAndPassword(XMPP_USER, XMPP_PASSWORD)
                              .setResource(XMPP_RESOURCE)
                              .setAuthzid(JidCreate.entityBareFrom(String.format("%s@%s", XMPP_USER, XMPP_DOMAIN))) // <-- this was the change I needed
                              .build();

Specifically I needed to add this line:

.setAuthzid(JidCreate.entityBareFrom(String.format("%s@%s", XMPP_USER, XMPP_DOMAIN)))

粉红×色少女 2024-09-26 08:39:25

您需要在连接之前设置身份验证,即

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文