🐛 Introduce ClientAuthed event

May act as entry point for any kind of push messages a plugin might
wish to send to the client after a connect happened. Since depending
on the current permission configuration this might only be possible
once the client has authenticated on the socket, this is required.

Should close #3400
This commit is contained in:
Gina Häußge committed 2020-01-21 15:53:52 +01:00
1 parent 8d31d6687e
commit 1d0829a1db
3 files changed
+21 -4

No files matched your search

+14 -4
View File
@@ -100,7 +100,7 @@ Shutdown
The server is shutting down.
ClientOpened
A client has connected to the web server.
A client has connected to the push socket.
Payload:
@@ -109,12 +109,22 @@ ClientOpened
**Note:** Name changed in version 1.1.0
ClientClosed
A client has disconnected from the webserver
ClientAuthed
A client has authenticated a user session on the push socket.
Payload:
* ``remoteAddress``: the remote address (IP) of the client that disconnected
* ``remoteAddress``: the remote address (IP) of the client that authed. On the push socket only available with a
valid login session.
* ``username``: the name of the user who authed. On the push socket only available with a valid login session.
ClientClosed
A client has disconnected from the push socket.
Payload:
* ``remoteAddress``: the remote address (IP) of the client that disconnected. On the push socket only available
with a valid login session.
UserLoggedIn
A user logged in. On the push socket only available with a valid login session with admin rights.
+2
View File
@@ -46,6 +46,8 @@ class Events(object):
# connect/disconnect by client
CLIENT_OPENED = "ClientOpened"
CLIENT_CLOSED = "ClientClosed"
CLIENT_AUTHED = "ClientAuthed"
CLIENT_DEAUTHED = "ClientDeauthed"
# user login/logout
USER_LOGGED_IN = "UserLoggedIn"
+5
View File
@@ -78,6 +78,7 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection,
"*": []}
_event_payload_processors = {Events.CLIENT_OPENED: [lambda user, payload: payload if user.has_permission(Permissions.ADMIN) else dict()],
Events.CLIENT_AUTHED: [lambda user, payload: payload if user.has_permission(Permissions.ADMIN) else dict()],
"*": []}
_emit_permissions = {"connected": [],
@@ -436,6 +437,10 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection,
self._logger.exception("Error processing authed hook handler for plugin {}".format(name),
extra=dict(plugin=name))
octoprint.events.eventManager().fire(octoprint.events.Events.CLIENT_AUTHED,
payload=dict(username=user.get_name(),
remoteAddress=self._remoteAddress))
def _on_logout(self):
self._user = self._userManager.anonymous_user_factory()