Add support for SASL EXTERNAL
Can be useful when the server is using e.g. a cookie for authentication purposes.
This commit is contained in:
parent
a890665775
commit
21a4a71542
4 changed files with 22 additions and 7 deletions
|
@ -69,6 +69,7 @@ export default class Client extends EventTarget {
|
|||
nick: null,
|
||||
pass: null,
|
||||
saslPlain: null,
|
||||
saslExternal: false,
|
||||
bouncerNetwork: null,
|
||||
};
|
||||
batches = new Map();
|
||||
|
@ -498,7 +499,7 @@ export default class Client extends EventTarget {
|
|||
|
||||
let reqCaps = [];
|
||||
let capEnd = true;
|
||||
if (this.params.saslPlain && this.supportsSASL("PLAIN")) {
|
||||
if ((this.params.saslPlain && this.supportsSASL("PLAIN")) || (this.params.saslExternal && this.supportsSASL("EXTERNAL"))) {
|
||||
// CAP END is deferred after authentication finishes
|
||||
reqCaps.push("sasl");
|
||||
capEnd = false;
|
||||
|
@ -537,6 +538,9 @@ export default class Client extends EventTarget {
|
|||
if (cap == "sasl" && this.params.saslPlain) {
|
||||
console.log("Starting SASL PLAIN authentication");
|
||||
this.send({ command: "AUTHENTICATE", params: ["PLAIN"] });
|
||||
} else if (cap == "sasl" && this.params.saslExternal) {
|
||||
console.log("Starting SASL EXTERNAL authentication");
|
||||
this.send({ command: "AUTHENTICATE", params: ["EXTERNAL"] });
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -552,15 +556,20 @@ export default class Client extends EventTarget {
|
|||
handleAuthenticate(msg) {
|
||||
let challengeStr = msg.params[0];
|
||||
|
||||
// For now only PLAIN is supported
|
||||
if (challengeStr != "+") {
|
||||
this.dispatchEvent(new CustomEvent("error", { detail: "Expected an empty challenge, got: " + challengeStr }));
|
||||
this.send({ command: "AUTHENTICATE", params: ["*"] });
|
||||
return;
|
||||
}
|
||||
|
||||
let respStr = btoa("\0" + this.params.saslPlain.username + "\0" + this.params.saslPlain.password);
|
||||
this.send({ command: "AUTHENTICATE", params: [respStr] });
|
||||
if (this.params.saslPlain) {
|
||||
let respStr = btoa("\0" + this.params.saslPlain.username + "\0" + this.params.saslPlain.password);
|
||||
this.send({ command: "AUTHENTICATE", params: [respStr] });
|
||||
} else if (this.params.saslExternal) {
|
||||
this.send({ command: "AUTHENTICATE", params: [btoa("")] });
|
||||
} else {
|
||||
throw new Error("Received AUTHENTICATE for unknown mechanism");
|
||||
}
|
||||
}
|
||||
|
||||
send(msg) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue