Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added SASL support #125

Merged
merged 4 commits into from

4 participants

@gsf

Set sasl: true in options, along with nick, userName, and password,
for SASL login (required for some IP ranges for connecting to
Freenode, etc.).

No docs or tests, sorry. Happy to provide if you give some guidance.

gsf added some commits
@gsf gsf Added SASL support
Set sasl: true in options, along with nick, userName, and password,
for SASL login (required for some IP ranges for connecting to
Freenode, etc.).
cb827f7
@gsf gsf Missed a colon d9e32de
@qsheets

While I applaud your effort, you may want to rework your code a bit as CAP is/ can be used for more than SASL. Other than that, documentation is as easy as updating docs/API.rst to reflect your changes to the library.

@gsf

Yes, I was kind of greedy with the CAP signals since nothing else in the library is using them yet. The third commit makes it more specific. When a use case comes up for other CAP functionality it can be accommodated then.

The last commit adds the option to the docs.

If these additions don't hinder other uses, I would really appreciate their inclusion. I can't connect to Freenode via my phone without them (anything on the T-Mobile network is subject to SASL).

@gsf

I could also move those listeners into the if ( self.opt.sasl ) block so that they only exist when SASL is enabled.

@martynsmith martynsmith merged commit bafa696 into from
@martynsmith
Owner

This looks fine, I notice that we get fairly wildly varying coding styles, I think I might get some jshint config set up and try to get everyone to conform to that :-)

@gsf

Thanks for merging this in!

@gsf gsf deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 27, 2012
  1. @gsf

    Added SASL support

    gsf authored
    Set sasl: true in options, along with nick, userName, and password,
    for SASL login (required for some IP ranges for connecting to
    Freenode, etc.).
  2. @gsf

    Missed a colon

    gsf authored
Commits on Dec 28, 2012
  1. @gsf

    Be more specific with CAP event

    gsf authored
  2. @gsf
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 3 deletions.
  1. +6 −2 docs/API.rst
  2. +25 −1 lib/irc.js
View
8 docs/API.rst
@@ -29,6 +29,7 @@ Client
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
+ sasl: false,
stripColors: false,
channelPrefixes: "&#",
messageSplit: 512
@@ -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::
View
26 lib/irc.js
@@ -48,6 +48,7 @@ function Client(server, nick, opt) {
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
+ sasl: false,
stripColors: false,
channelPrefixes: "&#",
messageSplit: 512
@@ -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");
@@ -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);
Something went wrong with that request. Please try again.