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

Added SASL support #125

Merged
merged 4 commits into from
Sep 6, 2013
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions docs/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Client
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
sasl: false,
stripColors: false,
channelPrefixes: "&#",
messageSplit: 512
Expand All @@ -47,14 +48,17 @@ Client
`floodProtectionDelay` sets the amount of time that the client will wait
between sending subsequent messages when `floodProtection` is enabled.

`messageSplit` will split up large messages sent with the `say` method
into multiple messages of length fewer than `messageSplit` characters.
Set `sasl` to true to enable SASL support. You'll also want to set `nick`,
`userName`, and `password` for authentication.

`stripColors` removes mirc colors (0x03 followed by one or two ascii
numbers for foreground,background) and ircII "effect" codes (0x02
bold, 0x1f underline, 0x16 reverse, 0x0f reset) from the entire
message before parsing it and passing it along.

`messageSplit` will split up large messages sent with the `say` method
into multiple messages of length fewer than `messageSplit` characters.

Setting `autoConnect` to false prevents the Client from connecting on
instantiation. You will need to call `connect()` on the client instance::

Expand Down
26 changes: 25 additions & 1 deletion lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function Client(server, nick, opt) {
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
sasl: false,
stripColors: false,
channelPrefixes: "&#",
messageSplit: 512
Expand Down Expand Up @@ -510,6 +511,26 @@ function Client(server, nick, opt) {
// who, reason, channels
self.emit('quit', message.nick, message.args[0], channels, message);
break;

// for sasl
case "CAP":
if ( message.args[0] === '*' &&
message.args[1] === 'ACK' &&
message.args[2] === 'sasl ' ) // there's a space after sasl
self.send("AUTHENTICATE", "PLAIN");
break;
case "AUTHENTICATE":
if ( message.args[0] === '+' ) self.send("AUTHENTICATE",
new Buffer(
self.opt.nick + '\0' +
self.opt.userName + '\0' +
self.opt.password
).toString('base64'));
break;
case "903":
self.send("CAP", "END");
break;

case "err_umodeunknownflag":
if ( self.opt.showErrors )
util.log("\033[01;31mERROR: " + util.inspect(message) + "\033[0m");
Expand Down Expand Up @@ -614,7 +635,10 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
self.conn.setTimeout(0);
self.conn.setEncoding('utf8');
self.conn.addListener("connect", function () {
if ( self.opt.password !== null ) {
if ( self.opt.sasl ) {
// see http://ircv3.atheme.org/extensions/sasl-3.1
self.send("CAP REQ", ":sasl");
} else if ( self.opt.password !== null ) {
self.send( "PASS", self.opt.password );
}
self.send("NICK", self.opt.nick);
Expand Down