Add support for OAuth 2.0 authentication

This commit is contained in:
Simon Ser
2022-09-12 11:38:43 +02:00
parent bbc94c88c0
commit e815295503
5 changed files with 228 additions and 4 deletions

View File

@@ -122,6 +122,7 @@ export default class Client extends EventTarget {
pass: null,
saslPlain: null,
saslExternal: false,
saslOauthBearer: null,
bouncerNetwork: null,
ping: 0,
eventPlayback: true,
@@ -467,6 +468,10 @@ export default class Client extends EventTarget {
case "EXTERNAL":
initialResp = { command: "AUTHENTICATE", params: [base64.encode("")] };
break;
case "OAUTHBEARER":
let raw = "n,,\x01auth=Bearer " + params.token + "\x01\x01";
initialResp = { command: "AUTHENTICATE", params: [base64.encode(raw)] };
break;
default:
throw new Error(`Unknown authentication mechanism '${mechanism}'`);
}
@@ -658,6 +663,8 @@ export default class Client extends EventTarget {
promise = this.authenticate("PLAIN", this.params.saslPlain);
} else if (this.params.saslExternal) {
promise = this.authenticate("EXTERNAL");
} else if (this.params.saslOauthBearer) {
promise = this.authenticate("OAUTHBEARER", this.params.saslOauthBearer);
}
(promise || Promise.resolve()).catch((err) => {
this.dispatchError(err);