Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add saslUsername and saslPassword options #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/irc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface IrcClientOpts {
floodProtectionDelay?: number;
sasl?: boolean;
saslType?: 'PLAIN'|'EXTERNAL';
saslUsername?: string|null;
saslPassword?: string|null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think this is great, but I'd actually turn sasl into an object and make it include the type,username and password as keys. Just to make this a bit less messy. It's a breaking change, but worthwhile I feel.

stripColors?: boolean;
channelPrefixes?: string;
messageSplit?: number;
Expand Down Expand Up @@ -129,6 +131,8 @@ interface IrcClientOptInternal extends IrcClientOpts {
floodProtectionDelay: number;
sasl: boolean;
saslType: 'PLAIN'|'EXTERNAL';
saslUsername: string|null;
saslPassword: string|null;
stripColors: boolean;
channelPrefixes: string;
messageSplit: number;
Expand Down Expand Up @@ -249,6 +253,8 @@ export class Client extends EventEmitter {
floodProtectionDelay: 1000,
sasl: false,
saslType: 'PLAIN',
saslUsername: null,
saslPassword: null,
stripColors: false,
channelPrefixes: '&#',
messageSplit: 512,
Expand Down Expand Up @@ -310,7 +316,7 @@ export class Client extends EventEmitter {

private onCapsList() {
const requiredCapabilites = [];
if (this.opt.sasl) {
if ((this.opt.sasl) && this.opt.saslUsername !== null && this.opt.saslPassword !== null) {
requiredCapabilites.push('sasl');
}

Expand Down Expand Up @@ -843,13 +849,16 @@ export class Client extends EventEmitter {
if (message.args[0] !== '+') {
return;
}
if (!this.opt.saslUsername || !this.opt.saslPassword) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I worry this might be a silent error. If we've missed the username or password but expect to use SASL, that feels like a fail. Perhaps we should add this check to the PLAIN case statement and throw?

return;
}
switch (this.opt.saslType) {
case 'PLAIN':
this._send('AUTHENTICATE',
Buffer.from(
this.opt.userName + '\x00' +
this.opt.userName + '\x00' +
this.opt.password
this.opt.saslUsername + '\x00' +
this.opt.saslUsername + '\x00' +
this.opt.saslPassword
).toString('base64'));
break;
case 'EXTERNAL':
Expand Down