Skip to content

Commit

Permalink
Use SASL2 from client
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Nov 21, 2023
1 parent 95e8f61 commit 516e372
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ const _resolve = require("@xmpp/resolve");

// Stream features - order matters and define priority
const _starttls = require("@xmpp/starttls/client");
const _sasl2 = require("@xmpp/sasl2");
const _sasl = require("@xmpp/sasl");
const _resourceBinding = require("@xmpp/resource-binding");
const _sessionEstablishment = require("@xmpp/session-establishment");
const _streamManagement = require("@xmpp/stream-management");

// SASL mechanisms - order matters and define priority
const scramsha1 = require("@xmpp/sasl-scram-sha-1");
const htsha256 = require("@xmpp/sasl-ht-sha-256-none");
const plain = require("@xmpp/sasl-plain");
const anonymous = require("@xmpp/sasl-anonymous");

function client(options = {}) {
const { resource, credentials, username, password, ...params } = options;
const { clientId, software, device } = params;

const { domain, service } = params;
if (!domain && service) {
Expand All @@ -47,6 +50,11 @@ function client(options = {}) {
const resolve = _resolve({ entity });
// Stream features - order matters and define priority
const starttls = _starttls({ streamFeatures });
const sasl2 = _sasl2(
{ streamFeatures },
credentials || { username, password },
{ clientId, software, device },
);
const sasl = _sasl({ streamFeatures }, credentials || { username, password });
const streamManagement = _streamManagement({
streamFeatures,
Expand All @@ -64,9 +72,10 @@ function client(options = {}) {
// SASL mechanisms - order matters and define priority
const mechanisms = Object.entries({
scramsha1,
htsha256,
plain,
anonymous,
}).map(([k, v]) => ({ [k]: v(sasl) }));
}).map(([k, v]) => ({ [k]: [v(sasl2), v(sasl)] }));

return Object.assign(entity, {
entity,
Expand All @@ -80,6 +89,7 @@ function client(options = {}) {
iqCallee,
resolve,
starttls,
sasl2,
sasl,
resourceBinding,
sessionEstablishment,
Expand Down
2 changes: 2 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"@xmpp/reconnect": "^0.13.0",
"@xmpp/resolve": "^0.13.1",
"@xmpp/resource-binding": "^0.13.0",
"@xmpp/sasl2": "^0.13.0",
"@xmpp/sasl": "^0.13.0",
"@xmpp/sasl-anonymous": "^0.13.0",
"@xmpp/sasl-plain": "^0.13.0",
"@xmpp/sasl-scram-sha-1": "^0.13.0",
"@xmpp/sasl-ht-sha-256-none": "^0.13.0",
"@xmpp/session-establishment": "^0.13.0",
"@xmpp/starttls": "^0.13.1",
"@xmpp/stream-features": "^0.13.0",
Expand Down

0 comments on commit 516e372

Please sign in to comment.