xmpp.js icon indicating copy to clipboard operation
xmpp.js copied to clipboard

Support X-OAuth2.0

Open hkrainko opened this issue 5 years ago • 3 comments

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')
})

hkrainko avatar Feb 21 '19 04:02 hkrainko

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

sonnyp avatar Sep 21 '19 10:09 sonnyp

related

https://docs.ejabberd.im/developer/ejabberd-api/oauth/ https://blog.process-one.net/understanding-ejabberd-oauth-support-roadmap/

sonnyp avatar Dec 11 '19 13:12 sonnyp

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]
    .....

yuanchieh-cheng avatar Jan 14 '20 03:01 yuanchieh-cheng