Skip to content

Commit 7cc3ee4

Browse files
committed
auth: Fix SASL event mapping for irc>=v20.3.0
The irc library added support for SASL authentication in their v20.3.0 release. That implementation also added named events for 903 RPL_SASLSUCCESS and 908 RPL_SASLMECHS. Our code must check for the named events and use them when registering handlers if present.
1 parent 7d0cb43 commit 7cc3ee4

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/ib3/auth.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import base64
2020
import logging
2121

22+
import irc.events
23+
2224
from .mixins import JoinChannels
2325

2426
logger = logging.getLogger(__name__)
@@ -96,12 +98,21 @@ class SASL(AbstractAuth):
9698
"""Authenticate using SASL before joining channels."""
9799
def __init__(self, *args, **kwargs):
98100
super(SASL, self).__init__(*args, **kwargs)
101+
102+
listen = {
103+
'cap': 'cap',
104+
'authenticate': 'authenticate',
105+
'saslsuccess': irc.events.numeric.get('903', '903'),
106+
'saslmechs': irc.events.numeric.get('908', '908'),
107+
'welcome': 'welcome',
108+
}
109+
99110
self.reactor._on_connect = self._handle_connect
100111

101-
for event in ['cap', 'authenticate', '903', '908', 'welcome']:
112+
for handler, event in listen.items():
102113
logger.debug('Registering for %s', event)
103114
self.connection.add_global_handler(
104-
event, getattr(self, '_handle_%s' % event))
115+
event, getattr(self, '_handle_%s' % handler))
105116

106117
def _handle_connect(self, sock):
107118
"""Send CAP REQ :sasl on connect."""
@@ -112,7 +123,7 @@ def _handle_cap(self, conn, event):
112123
if event.arguments and event.arguments[0] == 'ACK':
113124
conn.send_raw('AUTHENTICATE PLAIN')
114125
else:
115-
logger.warning('Unexpcted CAP response: %s', event)
126+
logger.warning('Unexpected CAP response: %s', event)
116127
conn.disconnect()
117128

118129
def _handle_authenticate(self, conn, event):
@@ -124,14 +135,14 @@ def _handle_authenticate(self, conn, event):
124135
conn.send_raw('AUTHENTICATE {}'.format(
125136
base64.b64encode(creds.encode('utf8')).decode('utf8')))
126137
else:
127-
logger.warning('Unexpcted AUTHENTICATE response: %s', event)
138+
logger.warning('Unexpected AUTHENTICATE response: %s', event)
128139
conn.disconnect()
129140

130-
def _handle_903(self, conn, event):
141+
def _handle_saslsuccess(self, conn, event):
131142
"""Handle 903 RPL_SASLSUCCESS responses."""
132143
self.connection.cap('END')
133144

134-
def _handle_908(self, conn, event):
145+
def _handle_saslmechs(self, conn, event):
135146
"""Handle 908 RPL_SASLMECHS responses."""
136147
logger.warning('SASL PLAIN not supported: %s', event)
137148
self.die()

0 commit comments

Comments
 (0)