【问题标题】:SASL authorization failing while connecting to XMPP server连接到 XMPP 服务器时 SASL 授权失败
【发布时间】:2010-09-17 09:20:24
【问题描述】:

我正在尝试通过 XMPP 服务器使用 SMACK API 连接到 gmail。但得到 ​​p>

错误:使用 PLAIN 机制的 SASL 身份验证失败

你可以看一眼代码。我只是从网上得到的

ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(connConfig);
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);

我检查了 smack 调试窗口。它用 XML 表示:

我已经在 gmail 上拥有帐户,并且我的 gtalk 也在运行。

【问题讨论】:

    标签: xmpp smack google-talk


    【解决方案1】:

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

    SASLAuthentication.supportSASLMechanism("PLAIN", 0);

    必须出现在connection.connect()之前。

    见我的blog

    【讨论】:

    • 我在该类中找不到该方法。有什么选择吗?
    • 这个方法不属于我的smack版本
    【解决方案2】:
        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();
        }
    

    我也遇到这个错误,但是我不能工作。

    【讨论】:

    • 解释错误并更正用户提供的代码。
    • SASLAuthentication.supportSASLMechanism("PLAIN", 0);不再可用。
    【解决方案3】:

    对于在最初询问和回答此问题多年后寻找可能解决方案的任何人,我最近能够通过在 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)))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-22
      • 2013-07-15
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 2020-12-07
      相关资源
      最近更新 更多