Source code for crossbar.edge.worker.auth

###############################################################################
#
# Crossbar.io Master
# Copyright (c) typedef int GmbH. Licensed under EUPLv1.2.
#
###############################################################################

from pprint import pformat

from autobahn.twisted.wamp import ApplicationSession
from autobahn.util import hl, hlid, hltype
from autobahn.wamp.exception import ApplicationError
from twisted.internet.defer import inlineCallbacks
from txaio import make_logger

# a simple principals database. in real world use, this likey would be
# replaced by some persistent database used to store principals.
[docs] PRINCIPALS = [ { # when a session is authenticating use one of the authorized_keys, # then assign it all the data below "authid": "client01@example.com", "realm": "devices_nonexist1", "role": "frontend", "extra": {"foo": 23}, "authorized_keys": ["545efb0a2192db8d43f118e9bf9aee081466e1ef36c708b96ee6f62dddad9122"], }, { "authid": "client02@example.com", "realm": "devices_nonexist2", "role": "frontend", "extra": {"foo": 42, "bar": "baz"}, "authorized_keys": ["585df51991780ee8dce4766324058a04ecae429dffd786ee80839c9467468c28"], }, { "authid": "cosmotron-authenticator", "realm": "cosmotron-auth", "role": "authenticator", "authorized_keys": ["9c194391af3bf566fc11a619e8df200ba02efb35b91bdd98b424f20f4163875e"], }, ]
[docs] log = make_logger()
[docs] class AuthenticatorSession(ApplicationSession): @inlineCallbacks
[docs] def onJoin(self, details): def authenticate(realm, authid, details): self.log.info( '{func}(realm="{realm}", authid="{authid}", details=details)', func=authenticate, realm=hlid(realm), authid=hlid(authid), details=details, ) return "anonymous" yield self.register(authenticate, "crossbarfabriccenter.mrealm.arealm.authenticate") self.log.info("{func}() Application realm authenticator ready!", func=hltype(self.onJoin))