我正在查看'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