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