diff --git a/docs/api/general.rst b/docs/api/general.rst index cc1cd0a72..7600cc80c 100644 --- a/docs/api/general.rst +++ b/docs/api/general.rst @@ -120,3 +120,94 @@ If CORS is not enabled you will get errors like the following:: XMLHttpRequest cannot load http://localhost:8081/api/files. No 'Access-Control-Allow-Origin' header is present on the requested resource. +.. _sec-api-general-login: + +Login +===== + +.. http:post:: /api/login + + Creates a login session or retrieves information about the currently existing session ("passive login"). + + Can be used in one of two ways: to login a user via username and password and create a persistent session (usually + from a UI in the browser), or to retrieve information about the active user (from an existing session or an API key) + via the ``passive`` flag. + + Will return a :http:statuscode:`200` with a :ref:`login response ` on successful + login, whether active or passive. The active (username/password) login may also return a :http:statuscode:`401` in + case of a username/password mismatch or unknown user and a :http:statuscode:`403` in case of a deactivated account. + + :json passive: If present, performs a passive login only, returning information about the current user that's + active either through an existing session or the used API key + :json user: (active login only) Username + :json pass: (active login only) Password + :json remember: (active login only) Whether to set a "remember me" cookie on the session + :status 200: Successful login + :status 401: Username/password mismatch or unknown user + :status 403: Deactivated account + +.. _sec-api-general-logout: + +Logout +====== + +.. http:post:: /api/logout + + Ends the current login session of the current user. + + Only makes sense in the context of browser based workflows. + + Will return a :http:statuscode:`204`. + + :status 204: No error + +.. _sec-api-general-datamodel: + +Data model +========== + +.. _sec-api-general-datamodel-login: + +Login response +-------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``name`` + - 1 + - string + - the user's name + * - ``active`` + - 1 + - boolean + - Whether the user's account is active or not + * - ``admin`` + - 1 + - boolean + - Whether the user has admin rights or not + * - ``user`` + - 1 + - boolean + - Whether the user has user rights or not (always ``true``) + * - ``apikey`` + - 1 + - string or None + - The user's API key, if set + * - ``settings`` + - 1 + - dict + - The user's settings, if any + * - ``session`` + - 1 + - string + - The session key, can be used to authenticate with the ``auth`` message on the :ref:`push API `. + * - ``_is_external_client`` + - 1 + - boolean + - Whether the client that made the request got detected as external from the local network or not. diff --git a/docs/api/push.rst b/docs/api/push.rst index 7d8813867..83fe2a486 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -47,23 +47,41 @@ Clients must ignore any unknown messages. The data model of the attached payloads is described further below. -OctoPrint's SockJS socket also accepts one command from the client to the server, -the ``throttle`` command. Usually, OctoPrint will push the general state update -in the ``current`` message twice per second. For some clients that might still -be too fast, so they can signal a different factor to OctoPrint utilizing the -``throttle`` message. OctoPrint expects a single integer here which represents -the multiplier for the base rate limit of one message every 500ms. A value of -1 hence will produce the default behaviour of getting every update. A value of -2 will set the rate limit to maximally one message every 1s, 3 to maximally one -message every 1.5s and so on. +OctoPrint's SockJS socket also accepts two commands from the client to the server. -Example for a ``throttle`` client-server-message: + * ``auth`` (since 1.3.10): With the ``auth`` message, clients may associate an + existing user session with the socket. That is of special importance to receive + any kind of messages if the bundled :ref:`Forcelogin Plugin ` is enabled + (as it is by default), since it will prevent any kind of status messages to be sent to connected unauthenticated + clients. -.. sourcecode:: javascript + The ``auth`` message expects a session key to be obtained from the successful payload of a + :ref:`(passive or active) login via the API `. - { - "throttle": 2 - } + Example for a ``auth`` client-server-message: + + .. sourcecode:: javascript + + { + "auth": "LGZ0trf8By" + } + + * ``throttle``: Usually, OctoPrint will push the general state update + in the ``current`` message twice per second. For some clients that might still + be too fast, so they can signal a different factor to OctoPrint utilizing the + ``throttle`` message. OctoPrint expects a single integer here which represents + the multiplier for the base rate limit of one message every 500ms. A value of + 1 hence will produce the default behaviour of getting every update. A value of + 2 will set the rate limit to maximally one message every 1s, 3 to maximally one + message every 1.5s and so on. + + Example for a ``throttle`` client-server-message: + + .. sourcecode:: javascript + + { + "throttle": 2 + } .. _sec-api-push-datamodel: diff --git a/docs/bundledplugins/forcelogin.rst b/docs/bundledplugins/forcelogin.rst new file mode 100644 index 000000000..bb69c35c9 --- /dev/null +++ b/docs/bundledplugins/forcelogin.rst @@ -0,0 +1,35 @@ +.. _sec-bundledplugins-forcelogin: + +Forcelogin Plugin +================= + +The Forcelogin Plugin comes bundled with OctoPrint (starting with version 1.3.10). It removes the anonymous +read-only access that up until 1.3.10 was standard when accessing OctoPrint instances without being logged in and +instead forces users to log in if they want to get any kind of information from OctoPrint. + +.. _fig-bundledplugins-forcelogin: +.. figure:: ../images/bundledplugins-forcelogin-dialog.png + :align: center + :alt: Forced login dialog + + OctoPrint's new forced login dialog. + +.. warning:: + + Keep in mind that **OctoPrint does not manage your webcam**, it merely embeds it. If you have a webcam, + it will still be accessible to users who are not logged in under its (guessable) URL. If you need to restrict + access to your webcam, you'll need to find a way to do so directly on the webcam server which - again - + is not OctoPrint itself. + +.. note:: + + If you want back the old behaviour of allowing anonymous read-only access to your OctoPrint instance, disable + the Forcelogin Plugin in OctoPrint's plugin manager. + +.. _sec-bundledplugins-forcelogin-sourcecode: + +Source code +----------- + +The source of the Backup plugin is bundled with OctoPrint and can be found in +its source repository under ``src/octoprint/plugins/forcelogin``. diff --git a/docs/bundledplugins/index.rst b/docs/bundledplugins/index.rst index ec90f709c..a1683a800 100644 --- a/docs/bundledplugins/index.rst +++ b/docs/bundledplugins/index.rst @@ -12,6 +12,7 @@ Bundled Plugins backup.rst cura.rst discovery.rst + forcelogin.rst logging.rst pluginmanager.rst printer_safety_check.rst diff --git a/docs/images/bundledplugins-forcelogin-dialog.png b/docs/images/bundledplugins-forcelogin-dialog.png new file mode 100644 index 000000000..8508cb6d4 Binary files /dev/null and b/docs/images/bundledplugins-forcelogin-dialog.png differ diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index b97d8ff8f..4d20367da 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -1238,6 +1238,45 @@ octoprint.server.http.routes :return: a list of 3-tuples with additional routes as defined above :rtype: list +.. _sec-plugins-hook-server-sockjs-register: + +octoprint.server.sockjs.register +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. py:function:: socket_registration_hook(socket, user, *args, **kwargs): + + Allows plugins to prevent a new :ref:`push socket client ` to be registered to the system. + + Handlers should return either ``True`` or ``False``. ``True`` signals to proceed with normal registration. ``False`` + signals to not register the client. + + See the bundled :ref:`Forcelogin Plugin ` for an example on how to utilize this. + + :param object socket: the socket object which is about to be registered + :param object user: the user currently authenticated on the socket - might be None + :return: whether to proceed with registration (``True``) or not (``False``) + :rtype: boolean + +.. _sec-plugins-hook-server-sockjs-emit: + +octoprint.server.sockjs.emit +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. py:function:: socket_emit_hook(socket, user, message, payload, *args, **kwargs): + + Allows plugins to prevent any messages to be emitted on an existing :ref:`push connection `. + + Handlers should return either ``True`` to allow the message to be emitted, or ``False`` to prevent it. + + See the bundled :ref:`Forcelogin Plugin ` for an example on how to utilize this. + + :param object socket: the socket object on which a message is about to be emitted + :param object user: the user currently authenticated on the socket - might be None + :param string message: the message type about to be emitted + :param dict payload: the payload of the message about to be emitted (may be None) + :return: whether to proceed with sending the message (``True``) or not (``False``) + :rtype: boolean + .. _sec-plugins-hook-timelapse-extensions: octoprint.timelapse.extensions