xmpp.js
xmpp.js copied to clipboard
Support X-OAuth2.0
I would like to use x-OAuth2.0 as the SASL mechanism but seem that it is not possible now.
What do you think if allowing developer passing mechanism into Client object(example) instead of using default SASL order matters?
const {client, xml} = require('@xmpp/client')
const {saslxoauth2} = require('sasl-x-oauth2')
const xmpp = client({
service: 'ws://localhost:5280/xmpp-websocket',
domain: 'localhost',
username: 'username',
token: 'token',
mech: saslxoauth2,
})
xmpp.on('error', err => {
console.error('❌', err.toString())
})
xmpp.on('offline', () => {
console.log('⏹', 'offline')
})
Hey, sorry for the late reply.
const xmpp = client({
// ...
credentials: {
domain: 'localhost',
username: 'username',
token: 'token',
}
})
xmpp.sasl.use(require('sasl-x-oauth2'))
Is the correct way to add an sasl mechanism compatible with https://github.com/jaredhanson/js-sasl
related
https://docs.ejabberd.im/developer/ejabberd-api/oauth/ https://blog.process-one.net/understanding-ejabberd-oauth-support-roadmap/
It works for me. Thanks @sonnyp
However I would like to ask that is it possible to support a parameter to set preferred mech instead of using first one server response ?
I digged into @xmpp/sasl file and found this code .
streamFeatures.use('mechanisms', NS, async ({stanza, entity}) => {
const offered = getMechanismNames(stanza)
const supported = SASL._mechs.map(({name}) => name)
const intersection = supported.filter(mech => {
return offered.includes(mech)
})
let mech = intersection[0]
.....