mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
Anonymous authentication
Implemented ANONYMOUS authentication on the ClientXMPP class. To use it, you just need to provide a domain (e.g 'anon.example.com') with an optional resource (e.g 'anon.example.com/resource') as the JID, with no password. The JID class has been improved to accept domains as fulljid. You can test this with echo_client.py python echo_client.py -j anon.louiz.org/ # anonymous with a resource # defined by the server python echo_client.py -j anon.louiz.org/resource # anonymous with given # resource The "normal" authentication method still works exactly like before.
This commit is contained in:
parent
4eb4d729ee
commit
2d18d905a5
2 changed files with 11 additions and 1 deletions
|
@ -304,7 +304,7 @@ class ClientXMPP(BaseXMPP):
|
||||||
if sasl_mechs:
|
if sasl_mechs:
|
||||||
for sasl_mech in sasl_mechs:
|
for sasl_mech in sasl_mechs:
|
||||||
self.features.append("sasl:%s" % sasl_mech.text)
|
self.features.append("sasl:%s" % sasl_mech.text)
|
||||||
if 'sasl:PLAIN' in self.features:
|
if 'sasl:PLAIN' in self.features and self.boundjid.user:
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
user = bytes(self.username)
|
user = bytes(self.username)
|
||||||
password = bytes(self.password)
|
password = bytes(self.password)
|
||||||
|
@ -318,6 +318,8 @@ class ClientXMPP(BaseXMPP):
|
||||||
self.send("<auth xmlns='%s' mechanism='PLAIN'>%s</auth>" % (
|
self.send("<auth xmlns='%s' mechanism='PLAIN'>%s</auth>" % (
|
||||||
sasl_ns,
|
sasl_ns,
|
||||||
auth))
|
auth))
|
||||||
|
elif 'sasl:ANONYMOUS' in self.features and not self.boundjid.user:
|
||||||
|
self.send("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS' />")
|
||||||
else:
|
else:
|
||||||
logging.error("No appropriate login method.")
|
logging.error("No appropriate login method.")
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
|
@ -94,6 +94,14 @@ class JID(object):
|
||||||
elif name in ('server', 'domain', 'host'):
|
elif name in ('server', 'domain', 'host'):
|
||||||
self.domain = value
|
self.domain = value
|
||||||
elif name in ('full', 'jid'):
|
elif name in ('full', 'jid'):
|
||||||
|
if '@' not in value:
|
||||||
|
if '/' in value:
|
||||||
|
d, r = value.split('/', 1)
|
||||||
|
object.__setattr__(self, "_resource", r)
|
||||||
|
else:
|
||||||
|
d = value
|
||||||
|
object.__setattr__(self, "_domain", d)
|
||||||
|
else:
|
||||||
self.reset(value)
|
self.reset(value)
|
||||||
elif name == 'bare':
|
elif name == 'bare':
|
||||||
if '@' in value:
|
if '@' in value:
|
||||||
|
|
Loading…
Reference in a new issue