Skip to content

Commit

Permalink
store WAMP authextra received (#1541)
Browse files Browse the repository at this point in the history
* store WAMP authextra received
* implement proxy authenticator setup for Component API
  • Loading branch information
oberstet committed Apr 2, 2022
1 parent 5890ca3 commit 4f9216d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion autobahn/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#
###############################################################################

__version__ = '22.3.2'
__version__ = '22.4.1.dev1'

__build__ = '00000000-0000000'
11 changes: 7 additions & 4 deletions autobahn/twisted/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
###############################################################################

import hashlib
from typing import Optional
from typing import Optional, Union

from twisted.internet.defer import Deferred
from twisted.internet.address import IPv4Address, UNIXAddress
Expand All @@ -40,6 +40,7 @@
_HAS_IPV6 = True
except ImportError:
_HAS_IPV6 = False
IPv6Address = type(None)

__all = (
'sleep',
Expand Down Expand Up @@ -68,19 +69,21 @@ def sleep(delay, reactor=None):
return d


def peer2str(addr):
def peer2str(addr: Union[IPv4Address, IPv6Address, UNIXAddress, PipeAddress]) -> str:
"""
Convert a Twisted address as returned from ``self.transport.getPeer()`` to a string.
:returns: Returns a string representation of the peer on a Twisted transport.
:rtype: unicode
"""
if isinstance(addr, IPv4Address):
res = "tcp4:{0}:{1}".format(addr.host, addr.port)
elif _HAS_IPV6 and isinstance(addr, IPv6Address):
res = "tcp6:{0}:{1}".format(addr.host, addr.port)
elif isinstance(addr, UNIXAddress):
res = "unix:{0}".format(addr.name)
if addr.name:
res = "unix:{0}".format(addr.name)
else:
res = "unix"
elif isinstance(addr, PipeAddress):
res = "<pipe>"
else:
Expand Down
16 changes: 16 additions & 0 deletions autobahn/wamp/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def create_authenticator(name, **kwargs):
klass = {
AuthScram.name: AuthScram,
AuthCryptoSign.name: AuthCryptoSign,
AuthCryptoSignProxy.name: AuthCryptoSignProxy,
AuthWampCra.name: AuthWampCra,
AuthAnonymous.name: AuthAnonymous,
AuthAnonymousProxy.name: AuthAnonymousProxy,
AuthTicket.name: AuthTicket,
}[name]
except KeyError:
Expand Down Expand Up @@ -121,6 +123,13 @@ def on_welcome(self, msg, authextra):
IAuthenticator.register(AuthAnonymous)


class AuthAnonymousProxy(AuthAnonymous):
name = 'anonymous-proxy'


IAuthenticator.register(AuthAnonymousProxy)


class AuthTicket(object):
name = 'ticket'

Expand Down Expand Up @@ -194,6 +203,13 @@ def on_welcome(self, msg, authextra):
IAuthenticator.register(AuthCryptoSign)


class AuthCryptoSignProxy(AuthCryptoSign):
name = 'cryptosign-proxy'


IAuthenticator.register(AuthCryptoSignProxy)


def _hash_argon2id13_secret(password, salt, iterations, memory):
"""
Internal helper. Returns the salted/hashed password using the
Expand Down
9 changes: 6 additions & 3 deletions autobahn/wamp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class BaseSession(ObservableMixin):
log = None

def __init__(self):
"""
"""
self.log = txaio.make_logger()

self.set_valid_events(
Expand Down Expand Up @@ -104,6 +101,7 @@ def __init__(self):
self._authrole = None
self._authmethod = None
self._authprovider = None
self._authextra = None

# payload transparency codec
self._payload_codec = None
Expand Down Expand Up @@ -135,6 +133,10 @@ def authmethod(self):
def authprovider(self):
return self._authprovider

@property
def authextra(self):
return self._authextra

def define(self, exception, error=None):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.define`
Expand Down Expand Up @@ -553,6 +555,7 @@ def success(res):
self._authrole = msg.authrole
self._authmethod = msg.authmethod
self._authprovider = msg.authprovider
self._authextra = msg.authextra
self._router_roles = msg.roles

details = SessionDetails(
Expand Down

0 comments on commit 4f9216d

Please sign in to comment.