gpt4 book ai didi

javascript - XMPP in-band registration (XEP-0077) : Differs from simple jid/pw login, 步骤是什么?

转载 作者:行者123 更新时间:2023-11-30 12:36:53 25 4
gpt4 key购买 nike

所以我有一个连接到 ejabberd 服务器的小 JavaScript/Strophejs xmpp 客户端。到目前为止,我已经在 ejabberd 网络管理员中创建了用户,例如我创建了用户 a@testserver.p1.im 和用户 b@testserver.p1.im。

我的客户端支持登录这些现有帐户之一,并在这些帐户/用户之间发送消息。

不过,我也希望能够从 HTML 表单在服务器上创建用户,用户可以在其中输入他想要的 jid 和密码。

在 xmpp 中,这称为带内注册 ( http://xmpp.org/extensions/xep-0077.html )。

现在,这是用户登录现有帐户时的基本场景:

$(document).ready(function () {
$('#SignIn').bind('click', function () {
$(document).trigger('connect', {
jid: $('#LogineMail').val(), password: $('#LoginPassword_f').val()
}
);
});
});

所以,上面的代码触发了“connect”,看起来像这样:

$(document).bind('connect', function (ev, data) {
console.log('connect fired');
var conn = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind");
conn.connect(data.jid, data.password, function (status) {
console.log('callback being done');
if (status === Strophe.Status.CONNECTED) {
alert('connected!');
$(document).trigger('connected');
alert('Connected successfully');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
}
else
{
Hello.log("error");
console.log('error');
}
});

Hello.connection = conn;
});

也就是说,这会创建一个新的 Strophe.connection,并使用给定的 jid 和密码登录。然后我可以发送消息。

但是,带内注册的情况有点不同。 XEP-0077 指出:

3.1 Entity Registers with a Host

In order to determine which fields are required for registration with a host, an entity SHOULD first send an IQ get to the host. The entity SHOULD NOT attempt to guess at the required fields by first sending an IQ set, since the nature of the required data is subject to service provisioning.

Example 1. Entity Requests Registration Fields from Host

<iq type='get' id='reg1' to='shakespeare.lit'>
<query xmlns='jabber:iq:register'/>
</iq>

这意味着,在我作为用户登录到服务器之前,我需要能够发送 IQ 请求并接收响应,因为很明显,如果我是在服务器上请求帐户的用户,我可能在服务器上还没有帐户,因此无法使用 jid/密码组合登录。

如何解决这个问题?关于入站注册的连接和节发送,通常的步骤是什么?例如,我是否应该在服务器上有某种管理员帐户,然后在想要添加新用户时从代码登录,并使用此管理员帐户获取带内注册所需的要求/字段并注册新用户?或者好的/标准方法是什么?

谢谢和最好的问候,

克里斯

编辑:我刚刚找到了 strophe.register.js 插件,我现在正在尝试使用它。但是我在 strophe.register.js 代码中遇到错误,而不是在我自己的代码中。

这是我的注册代码:

$('#JoinSend').bind('click', function () {
var tempConn = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind");
tempConn.register.connect("testserver.host56.com", function (status) {
if (status === Strophe.Status.REGISTER) {
// fill out the fields
connection.register.fields.username = "juliet";
connection.register.fields.password = "R0m30";
// calling submit will continue the registration process
connection.register.submit();
} else if (status === Strophe.Status.REGISTERED) {
console.log("registered!");
// calling login will authenticate the registered JID.
connection.authenticate();
} else if (status === Strophe.Status.CONFLICT) {
console.log("Contact already existed!");
} else if (status === Strophe.Status.NOTACCEPTABLE) {
console.log("Registration form not properly filled out.")
} else if (status === Strophe.Status.REGIFAIL) {
console.log("The Server does not support In-Band Registration")
} else if (status === Strophe.Status.CONNECTED) {
// do something after successful authentication
} else {
// Do other stuff
}
});
});

我在 chrome JS 控制台中收到以下错误:

未捕获的类型错误:无法读取未定义的属性“绑定(bind)”:strophe.register.js:90。

不确定我是否遗漏了什么,或者 strophe.register.js 是否有额外的依赖项?

我从这里使用 strophe.register.js:https://github.com/strophe/strophejs-plugins/blob/master/register/strophe.register.js

最佳答案

“连接”到服务器和“验证”连接是有区别的。为了执行带内注册,您只需要连接,不执行身份验证步骤,然后简单地发送节来执行注册。如果服务器支持带内注册,他将允许(同时他应该在连接未通过身份验证时阻止与其他 XMPP 实体的任何通信)。

关于javascript - XMPP in-band registration (XEP-0077) : Differs from simple jid/pw login, 步骤是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25798626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com