-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
offer in-band registration #783
Comments
Hi! I would like to know if it is possible to register users through in-band registration with this lib. I've tried to use this lib by starting a connection anonymously:
This is the debug code:
As you can see, I receive a bad-request error, but I do not understand why since the xml is right. Can you help me? |
Does the registration work now or not? Could you please provide an example? Thanks! |
Hmm this is not straightforward because by default Here's a very rough but working example I came up with (you could replace websocket with whatever else you want, I think): const { client, xml, jid } = require('@xmpp/client')
const debug = require("@xmpp/debug")
let xmpp = client({
service:"wss://jabber.example:443/xmpp-websocket",
domain:"jabber.example",
credentials: authenticate,
})
debug(xmpp, true)
const {iqCaller} = xmpp
async function authenticate(auth, mechanism) {
console.debug("authenticate", mechanism)
console.debug("...or not, because we'll sign up here instead hehe")
// get signup form
let response1 = await iqCaller.get(
xml("query", {xmlns: "jabber:iq:register"})
)
console.log(`They responded with: ${response1}`)
/*
* in practice, at this point you should parse the signup form
* and see which fields are required, etc. For example, my
* metronome setup requires you to provide the email address
* as well.
*/
// try an actual signup!
let response2 = await iqCaller.set(
xml("query", {xmlns: "jabber:iq:register"},
xml("x",
{type: "submit", xmlns: "jabber:x:data"},
xml("field", {type:"hidden", var: "FORM_TYPE"},
xml("value", {}, "jabber:iq:register")),
xml("field", {label:"Username", type: "text-single", var: "username"},
xml("required"),
xml("value", {}, "somebody")),
xml("field", {label:"Password", type: "text-private", var: "password"},
xml("required"),
xml("value", {}, "s3kr1t")),
)
)
)
console.log(`They responded with: ${response2}`)
xmpp.stop()
process.exit()
} The problem with this is that xmpp.js expects authentication to happen at this point, so it fails with a timeout after a point. In fact, to implement this I had to override the authentication function so that it sent custom stanzas to create an account rather than actually authenticating. To prevent a timeout I had to call @sonnyp, not sure if I'm missing something in the documentation, but is there a recommended way to do any of the following?
I think just one of the above two options would work; of course having both would make it that much less hacky 🙂 |
Goals:
Simple API to allow user registration and documentation "How do I - user registration".
Non goals:
Implement registration within
xmpp.js
.References:
The text was updated successfully, but these errors were encountered: