Skip to content

Commit

Permalink
Enable sasl2 in react-native
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 20, 2024
1 parent 07f4250 commit 069d0f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 10 additions & 2 deletions packages/client/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ const anonymous = require("@xmpp/sasl-anonymous");
const plain = require("@xmpp/sasl-plain");

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

const { domain, service } = params;
if (!domain && service) {
Expand Down
26 changes: 22 additions & 4 deletions packages/client/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const _iqCallee = require("@xmpp/iq/callee");
const _resolve = require("@xmpp/resolve");

// Stream features - order matters and define priority
const _sasl2 = require("@xmpp/sasl2");
const _sasl = require("@xmpp/sasl");
const _resourceBinding = require("@xmpp/resource-binding");
const _sessionEstablishment = require("@xmpp/session-establishment");
Expand All @@ -22,7 +23,16 @@ const anonymous = require("@xmpp/sasl-anonymous");
const plain = require("@xmpp/sasl-plain");

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

const { domain, service } = params;
if (!domain && service) {
Expand All @@ -40,11 +50,17 @@ function client(options = {}) {
const iqCallee = _iqCallee({ middleware, entity });
const resolve = _resolve({ entity });
// Stream features - order matters and define priority
const sasl2 = _sasl2(
{ streamFeatures },
credentials || { username, password },
{ clientId, software, device },
);
const sasl = _sasl({ streamFeatures }, credentials || { username, password });
const streamManagement = _streamManagement({
streamFeatures,
entity,
middleware,
sasl2,
});
const resourceBinding = _resourceBinding(
{ iqCaller, streamFeatures },
Expand All @@ -55,9 +71,10 @@ function client(options = {}) {
streamFeatures,
});
// SASL mechanisms - order matters and define priority
const mechanisms = Object.entries({ plain, anonymous }).map(([k, v]) => ({
[k]: v(sasl),
}));
const mechanisms = Object.entries({
plain,
anonymous,
}).map(([k, v]) => ({ [k]: [v(sasl2), v(sasl)] }));

return Object.assign(entity, {
entity,
Expand All @@ -68,6 +85,7 @@ function client(options = {}) {
iqCaller,
iqCallee,
resolve,
sasl2,
sasl,
resourceBinding,
sessionEstablishment,
Expand Down

0 comments on commit 069d0f6

Please sign in to comment.