From fcfacb725fd0ef8dc5ceb9cc4d67b7ae08041b7d Mon Sep 17 00:00:00 2001 From: Melissa Eckardt Date: Fri, 24 Apr 2026 10:57:35 +0200 Subject: [PATCH] Expose token in Share objects Some use cases require passing the token to external applications that access NextCloud shares via WebDAV. --- nc_py_api/files/__init__.py | 6 ++++++ tests/actual_tests/files_sharing_test.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/nc_py_api/files/__init__.py b/nc_py_api/files/__init__.py index 98854f8e..e6a986f3 100644 --- a/nc_py_api/files/__init__.py +++ b/nc_py_api/files/__init__.py @@ -442,6 +442,12 @@ def path(self) -> str: """Share path relative to the user's root directory.""" return self._raw_data.get("path", "").lstrip("/") + @property + def token(self) -> str: + """Token for the Shared object.""" + # Nextcloud pre-initializes token to null and overwrites it for types that have it. + return self._raw_data.get("token") or "" + @property def label(self) -> str: """Label for the Shared object.""" diff --git a/tests/actual_tests/files_sharing_test.py b/tests/actual_tests/files_sharing_test.py index b2fc482e..1e1dd44b 100644 --- a/tests/actual_tests/files_sharing_test.py +++ b/tests/actual_tests/files_sharing_test.py @@ -46,6 +46,8 @@ def _test_share_fields(new_share: Share, get_by_id: Share, shared_file: FsNode): assert new_share.permissions & FilePermissions.PERMISSION_READ assert new_share.url assert new_share.path == shared_file.user_path + assert new_share.token + assert get_by_id.token == new_share.token assert get_by_id.share_id == new_share.share_id assert get_by_id.path == new_share.path assert get_by_id.mimetype == new_share.mimetype