3

I am trying to connect to ejabberd server from strophe.js. I have enabled OAuth in ejabberd and due to which I am able to get OAuth token successfully for the user, once user have been authenticated. Workflow is something like above :-

  1. When user registers with my web app, I create ejabberd account for user, with the same credentials.
  2. User logs into my web app
  3. On successful login, I log the user into ejabberd with the help of OAuth mechanism.
  4. OAuth token is passed to the client
  5. Now client using strophe.js makes connection with ejabberd to perform all other operations, like obtain roster list, sending presence, sending message, etc.

I am facing issue in step 4, since I am not able to find suitable way to send OAuth token to ejabberd, while making connection. Btw, I am new to strophe.js. All the example on the internet uses, username and password. I don't want to ask again user for the password, neither I want to hard code in the file.

Thanks in advance.

Mangu Singh Rajpurohit
  • 10,806
  • 4
  • 68
  • 97

1 Answers1

0

You can use OAuth token to connect ejabberd server from strophe.

  1. OAuth token generated from api must have scope sasl_auth
  2. While creating strophe instance pass option mechanisms as [Strophe.SASLXOAuth2]
  3. While connecting replace password with your oauth token eg. connection.connect(jid, ejabberd_oauth_token)
  • I am using strophe.js and openfire . is it possible to make connection with a token ?. my current code is : this.xmppConnection = new Strophe.Connection(this.connectionString, { keepalive: true, protocol: 'wss' }); this.xmppConnection.connect(userJID, userPass, this.onXmppServerConnect); – Sahal Jan 02 '20 at 06:06
  • Hi, you need to pass default mechanism for connection to Strophe. this.xmppConnection = new Strophe.Connection(this.connectionString, { keepalive: true, protocol: 'wss', mechanisms: [Strophe.SASLXOAuth2] }); – Anish Lushte Jan 14 '20 at 04:54
  • Hi Anish , i am using strophe.js npm type . and it is saying that Strophe.SASLXOAuth2 is not exists – Sahal Jan 14 '20 at 06:46
  • I hope you are using (https://github.com/strophe/strophejs) strophe package. You can find this definition at [https://github.com/strophe/strophejs/blob/24e427db500550799cf1a08ec12aaa03d3ac3fae/src/core.js#L2279] – Anish Lushte Jan 17 '20 at 04:40