From 281c4b698c0e3cea31b4bcfdb13e60d45ec44ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 16 Feb 2021 17:21:19 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Merge=20auth=20example=20with=20?= =?UTF-8?q?existing=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/push.rst | 13 ++----------- docs/jsclientlib/base.rst | 8 ++++---- docs/jsclientlib/socket.rst | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/docs/api/push.rst b/docs/api/push.rst index 36f6f1820..f316ba70c 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -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 `: - - .. 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 ` + can be found :ref:`here `. .. mermaid:: diff --git a/docs/jsclientlib/base.rst b/docs/jsclientlib/base.rst index 63833f0dc..37416fd10 100644 --- a/docs/jsclientlib/base.rst +++ b/docs/jsclientlib/base.rst @@ -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. diff --git a/docs/jsclientlib/socket.rst b/docs/jsclientlib/socket.rst index 70b9bc5dc..fc4223546 100644 --- a/docs/jsclientlib/socket.rst +++ b/docs/jsclientlib/socket.rst @@ -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