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
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,14 +15,15 @@ import (
|
|||||||
func CreateNextcloudUser(nextcloudBaseURL, adminUser, adminPass, username, password string) error {
|
func CreateNextcloudUser(nextcloudBaseURL, adminUser, adminPass, username, password string) error {
|
||||||
// Remove any path from base URL, we need just the scheme://host:port
|
// Remove any path from base URL, we need just the scheme://host:port
|
||||||
baseURL := strings.Split(nextcloudBaseURL, "/remote.php")[0]
|
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
|
// OCS API expects form-encoded data with proper URL encoding
|
||||||
formData := fmt.Sprintf("userid=%s&password=%s",
|
formData := url.Values{
|
||||||
strings.ReplaceAll(username, " ", "+"),
|
"userid": {username},
|
||||||
strings.ReplaceAll(password, " ", "+"))
|
"password": {password},
|
||||||
|
}.Encode()
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBufferString(formData))
|
req, err := http.NewRequest("POST", urlStr, bytes.NewBufferString(formData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create request: %w", err)
|
return fmt.Errorf("failed to create request: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user