From 47eeb0eb00e0f3983015d3e344a350548ca30799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 16 Feb 2021 17:10:50 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20some=20more=20examples=20f?= =?UTF-8?q?or=20socket=20auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix a problem with a config example's markup --- docs/api/push.rst | 26 ++++++++++++++++++++++++++ docs/features/accesscontrol.rst | 1 + docs/jsclientlib/browser.rst | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/docs/api/push.rst b/docs/api/push.rst index c9c6a4b04..36f6f1820 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -68,6 +68,32 @@ OctoPrint's SockJS socket also accepts two commands from the client to the serve "auth": "someuser:LGZ0trf8By" } + Example for a auth roundtrip with only an API key, using the :ref:`JS Client Library `: + + .. sourcecode:: javascript + + var client = new OctoPrintClient({baseurl: "http://example.com/octoprint1/", apikey: "apikey1"}); + client.socket.connect(); + client.browser.passiveLogin().done(function(response) { + client.socket.sendAuth(response.name, response.session).done(function() { + // the socket is now authenticated + }) + }) + + .. mermaid:: + + sequenceDiagram + participant Client + participant API + participant Websocket + + Client->>API: GET /api/login?passive=true&apikey=... + API->>Client: { name: ..., session: ..., ... } + + note over Client auth = name + ":" + session + + Client->>Websocket: { "auth": auth } + * ``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 diff --git a/docs/features/accesscontrol.rst b/docs/features/accesscontrol.rst index 23bf90b75..62a548768 100644 --- a/docs/features/accesscontrol.rst +++ b/docs/features/accesscontrol.rst @@ -177,6 +177,7 @@ further down there's also a dedicated list of steps for OctoPi specifically. salt line): .. code-block:: yaml + accessControl: salt: aabbccddee1234523452345 autologinLocal: true diff --git a/docs/jsclientlib/browser.rst b/docs/jsclientlib/browser.rst index d44ba08bf..e71c26a60 100644 --- a/docs/jsclientlib/browser.rst +++ b/docs/jsclientlib/browser.rst @@ -29,6 +29,25 @@ Tries to perform a passive login into OctoPrint, using existing session data stored in the browser's cookies. + .. code-block:: javascript + + OctoPrint.browser.passiveLogin() + .done(function(response) { + // do something with the response + }) + + .. code-block:: javascript + + var client = new OctoPrintClient({ + baseurl: "https://example.com/", + apikey: "..." + }); + client.browser.passiveLogin() + .done(function(response) { + // do something with the response, e.g. authenticate with the socket + // via response.name and response.session + }) + :param object opts: Additional request options :returns Promise: A `jQuery Promise `_ for the request's response