From 324d08130ca7932ab4b9240f2b3e69a2b70ad27c Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Sat, 26 Aug 2023 07:53:06 +0000 Subject: [PATCH] Support bearer token for non-webdav requests --- Changelog.md | 2 ++ .../java/org/aarboard/nextcloud/api/utils/ConnectorCommon.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Changelog.md b/Changelog.md index 1a3aa14..df42e56 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,6 @@ # Changelog for nextcloud api +- 2023-08-26 + - Allow bearer token authentication for non-WebDav requests - 2022-11-29 - Release 12.0.4, upgraded indirect commons-codec dependency - Release 12.0.3, upgraded jackson dependencies diff --git a/src/main/java/org/aarboard/nextcloud/api/utils/ConnectorCommon.java b/src/main/java/org/aarboard/nextcloud/api/utils/ConnectorCommon.java index 1a50850..4875035 100644 --- a/src/main/java/org/aarboard/nextcloud/api/utils/ConnectorCommon.java +++ b/src/main/java/org/aarboard/nextcloud/api/utils/ConnectorCommon.java @@ -154,6 +154,9 @@ private CompletableFuture executeRequest(final ResponseParser parser, // https://docs.nextcloud.com/server/14/developer_manual/core/ocs-share-api.html request.addHeader("OCS-APIRequest", "true"); request.addHeader("Content-Type", "application/x-www-form-urlencoded"); + if (serverConfig.getAuthenticationConfig().usesBearerTokenAuthentication()) { + request.addHeader("Authorization", serverConfig.getAuthenticationConfig().getBearerToken()); + } request.setProtocolVersion(HttpVersion.HTTP_1_1); HttpClientContext context = prepareContext();