From fd4224d1dac192dd9e6992d9926f636f2c7eea19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Sun, 11 Jan 2026 01:30:40 +0100 Subject: [PATCH] Fix Nextcloud user creation password encoding - Replace manual form encoding with url.Values.Encode() for proper URL encoding - Fixes issue where passwords with special characters were malformed - Ensures password sent to Nextcloud matches password stored in database - This fixes WebDAV authentication failures for auto-provisioned users --- go_cloud/internal/storage/nextcloud.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/go_cloud/internal/storage/nextcloud.go b/go_cloud/internal/storage/nextcloud.go index 89928c6..a0d4bb0 100644 --- a/go_cloud/internal/storage/nextcloud.go +++ b/go_cloud/internal/storage/nextcloud.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "net/url" "strings" ) @@ -14,14 +15,15 @@ import ( func CreateNextcloudUser(nextcloudBaseURL, adminUser, adminPass, username, password string) error { // Remove any path from base URL, we need just the scheme://host:port baseURL := strings.Split(nextcloudBaseURL, "/remote.php")[0] - url := fmt.Sprintf("%s/ocs/v1.php/cloud/users", baseURL) + urlStr := fmt.Sprintf("%s/ocs/v1.php/cloud/users", baseURL) - // OCS API expects form-encoded data, not JSON - formData := fmt.Sprintf("userid=%s&password=%s", - strings.ReplaceAll(username, " ", "+"), - strings.ReplaceAll(password, " ", "+")) + // OCS API expects form-encoded data with proper URL encoding + formData := url.Values{ + "userid": {username}, + "password": {password}, + }.Encode() - req, err := http.NewRequest("POST", url, bytes.NewBufferString(formData)) + req, err := http.NewRequest("POST", urlStr, bytes.NewBufferString(formData)) if err != nil { return fmt.Errorf("failed to create request: %w", err) }