我正在查看'XEP-0077 in-band registration'关于如何注册一个新的XMPP帐户。这是我的代码。我使用node-xmpp将我的node.js应用程序连接到ejabberd服务器。注册新的xmpp帐户与节点xmpp(node.js)
var net = require('net');
var xmpp = require('node-xmpp');
var cache = new Object();
net.createServer(function(socket) {
socket.setEncoding('utf8');
socket.addListener('data',function(data) {
data = data.substr(0,data.length-2);
if(cache.admin==undefined && data=='login') {
var ejabberd =new xmpp.Client({jid:"[email protected]",password:'12345',host:'192.168.7.202',port:'5222'});
cache.admin = ejabberd;
cache.admin.addListener('online',function() {
cache.admin.send(new xmpp.Element('presence',{type:'chat'}).c('show').c('status').t('mine status'));
cache.admin.send(new xmpp.Element('iq',{type:'get',id:'reg1'}).c('query',{xmlns:'jabber:iq:register'}));
})
cache.admin.addListener('stanza',function(stanza) {
if(stanza.is('iq')) {
console.log(stanza.children[1]);
}
})
cache.admin.addListener('end',function() {
cache.admin.end();
cache.admin = undefined;
})
}
if(cache.admin!=undefined && data=='logout') {
cache.admin.end();
cache.admin = undefined;
} else if(cache.admin!=undefined && data=='register') {
cache.admin.send(new xmpp.Element('iq',{type:'set',id:'reg1'}).c('query',{xmlns:'jabber:iq:register'}).c('username').t('alow').up().c('password').t('test'));
}
});
}).listen(5000);
如果我运行这段代码,我得到这个错误:
{ name: 'error',
parent:
{ name: 'iq',
parent: null,
attrs:
{ from: '[email protected]',
to: '[email protected]/20108892991316770090454637',
id: 'reg1',
type: 'error',
xmlns: 'jabber:client',
'xmlns:stream': 'http://etherx.jabber.org/streams' },
children: [ [Object], [Circular] ] },
attrs: { code: '403', type: 'auth' },
children:
[ { name: '**forbidden**',
parent: [Circular],
attrs: [Object],
children: [] } ] }
在“XEP-0077:带内注册”它说,forbidden
原因意味着“发件人没有足够的权限来取消注册“。
我该如何获得这样的权限?
你可以发布你的ejabberd配置文件的'mod_register'部分吗? – legoscia
我遇到了同样的问题...你解决了这个问题吗? – Canastro