📝 Merge auth example with existing one

This commit is contained in:
Gina Häußge committed 2021-02-16 17:21:19 +01:00
1 parent 47eeb0eb00
commit 281c4b698c
3 files changed
+24 -15

No files matched your search

+2 -11
View File
@@ -68,17 +68,8 @@ 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
})
})
An example for an auth roundtrip with only an API key using the :ref:`JS Client Library <sec-jsclientlib-base>`
can be found :ref:`here <sec-jsclient-socket-authsample>`.
.. mermaid::
+4 -4
View File
@@ -14,13 +14,13 @@
The client library instance's options. The following keys are currently supported:
``apikey``
The API Key to use for requests against the OctoPrint API. Should usually be
the anonymous UI API Key provided on the socket.
``baseurl``
The base URL of the OctoPrint API
``apikey``
The API Key to use for requests against the OctoPrint API. If left unset, you'll
need to authenticate your session through a login.
``locale``
The locale to set in ``X-Locale`` headers on API requests. Useful for API
endpoints that might return localized content.
+18
View File
@@ -114,9 +114,13 @@
Instructs the server to decrease the message rate by 500ms.
.. _sec-jsclient-socket-authsample:
Sample to setup an authed socket
================================
If you have a username and a password:
.. code-block:: javascript
OctoPrint.socket.connect();
@@ -125,6 +129,20 @@ Sample to setup an authed socket
OctoPrint.socket.sendAuth("myusername", response.session);
});
If you have an API key:
.. code-block:: javascript
var client = new OctoPrintClient({
baseurl: "http://example.com/",
apikey: "abcdef"
});
client.socket.connect();
client.browser.passiveLogin()
.done(function(response) {
client.socket.sendAuth(response.name, response.session);
});
.. _sec-jsclient-socket-throttling:
Communication Throttling