Skip to content
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

Support X-OAuth2.0 #635

Open
hkrainko opened this issue Feb 21, 2019 · 3 comments
Open

Support X-OAuth2.0 #635

hkrainko opened this issue Feb 21, 2019 · 3 comments

Comments

@hkrainko
Copy link

hkrainko commented Feb 21, 2019

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')
})
@sonnyp
Copy link
Member

sonnyp commented Sep 21, 2019

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

@yuanchieh-cheng
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants