📝 Add some more examples for socket auth

Also fix a problem with a config example's markup
This commit is contained in:
Gina Häußge committed 2021-02-16 17:10:50 +01:00
1 parent 85a6144de9
commit 47eeb0eb00
3 files changed
+46

No files matched your search

+26
View File
@@ -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 <sec-jsclientlib-base>`:
.. 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
+1
View File
@@ -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
+19
View File
@@ -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 <http://api.jquery.com/Types/#Promise>`_ for the request's response