diff --git a/docs/api/push.rst b/docs/api/push.rst index c9c6a4b04..5210ad599 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -68,6 +68,23 @@ OctoPrint's SockJS socket also accepts two commands from the client to the serve "auth": "someuser:LGZ0trf8By" } + An example for an auth roundtrip with only an API key using the :ref:`JS Client Library ` + can be found :ref:`here `. + + .. 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/development/environment.rst b/docs/development/environment.rst index f53227f03..93756517b 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -1,14 +1,15 @@ .. _sec-development-environment: +************************************ Setting up a Development environment -==================================== +************************************ .. _sec-development-environment-source: Obtaining, building and running the source ------------------------------------------- +========================================== -This describes the general steps in obtaining, building and running. OS specific instructions can be found +This describes the **general, platform agnostic** steps in obtaining, building and running. OS specific instructions can be found below. * Prerequisites: @@ -80,10 +81,11 @@ Go to the directory `docs` and you can then build the documentation: * ``sphinx-build -b html . _build`` The documentation will be available in the newly created ``_build`` directory. You can simply browse it locally by opening ``index.html`` + .. _sec-development-environment-source-linux: Linux -..... +----- This assumes you'll host your OctoPrint development checkout at ``~/devel/OctoPrint``. If you want to use a different location, please substitute accordingly. @@ -126,7 +128,7 @@ You can then start OctoPrint via ``octoprint`` after activating one of the two v .. _sec-development-environment-windows: Windows -....... +------- This assumes you'll host your OctoPrint development checkout at ``C:\Devel\OctoPrint``. If you want to use a different location, please substitute accordingly. @@ -135,17 +137,18 @@ First download & install: * `Git for Windows `_ * `Latest *stable* Python 2.7 and Python 3.8 releases from python.org `_ - (at the time of writing those are ``2.7.18`` and ``3.8.4``) + (at the time of writing those are ``2.7.18`` and ``3.8.7``) * make sure to have the installer add Python to the ``PATH`` and have it install ``pip`` too * it's recommended to install Python 2.7 into ``C:\Python27`` and Python 3 into ``C:\Python38`` - if you select different install locations please substitute accordingly + * it's also recommended to have both versions get installed for all users * `Microsoft Visual C++ Compiler for Python 2.7 `_ * `Build Tools For Visual Studio 2019 `_ * install "C++ build tools" and ensure the latest versions of "MSVCv142 - VS 2019 C++ x64/x86 build tools" and - "Windows 10 SDK" are checked. + "Windows 10 SDK" are checked under individual components. Open the Git Bash you just installed and in that: @@ -158,18 +161,43 @@ Open the Git Bash you just installed and in that: virtualenv --python=C:\Python27\python.exe venv2 virtualenv --python=C:\Python38\python.exe venv3 source ./venv2/Scripts/activate - pip install --upgrade pip + python -m pip install --upgrade pip pip install -e .[develop,plugins] source ./venv3/Scripts/activate pip install --upgrade pip - pip install -e .[develop,plugins,docs] + python -m pip install -e .[develop,plugins,docs] pre-commit install git config blame.ignoreRevsFile .git-blame-ignore-revs +.. _sec-development-environment-windows-optional: + +Optional but recommended tools +.............................. + +These are some tools that are recommended but not required to have on hand: + + * `Visual Studio Code `_ + * `Windows Terminal `_ + + Add the following profile to ``profiles.list`` in the settings, that will allow you to + easily start Git Bash from the terminal: + + .. code-block:: js + + { + "guid": "{3df4550c-eebd-496c-a189-e55f2f8b01ce}", + "hidden": false, + "name": "Git Bash", + "commandline": "C:\\Program Files\\Git\\bin\\bash.exe --login -i", + "startingDirectory": "C:\\Devel", + "tabTitle": "Git Bash", + "suppressApplicationTitle": true + }, + .. _sec-development-environment-mac: Mac OS X -........ +-------- .. note:: @@ -220,7 +248,7 @@ You'll need a user account with administrator privileges. .. _sec-development-environment-ides: IDE Setup ---------- +========= .. todo:: @@ -231,7 +259,7 @@ IDE Setup .. _sec-development-environment-ides-pycharm: PyCharm -....... +------- - "File" > "Open ...", select OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) - Register virtual environments: 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/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/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 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