Skip to content

Commit

Permalink
doc/source: Document authenticate function usage
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Dec 11, 2024
1 parent 9d485a4 commit 1153847
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion doc/source/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,23 @@ essentially meaning that the authentication has not yet occurred.
False
In order to authenticate the client, pass the LXD instance's trust
password or token to `Client.authenticate`
password or token to `Client.authenticate`.
The secret provided will be use as a token if it has the proper format
and the server accepts tokens, otherwise it will be used as a password.
To force password authentication, `use_token_auth` can be used.

.. code-block:: python
>>> client.authenticate('a-secret')
>>> client.trusted
>>> True
.. code-block:: python
>>> token = '{"client_name":"foo","fingerprint":"abcd","addresses":["192.0.2.1:8443"],"secret":"I-am-a-secret","expires_at":"0001-01-01T00:00:00Z","type":""}'
>>> client.authenticate(base64.b64encode(json.dumps(token).encode("utf-8")), use_token_auth=False) # Forces password authentication and fails
>>> client.trusted
>>> False
>>> client.authenticate(base64.b64encode(json.dumps(token).encode("utf-8"))) # Token used as token
>>> client.trusted
>>> True

0 comments on commit 1153847

Please sign in to comment.