carddav: add current-user-principal to server

This commit is contained in:
Simon Ser
2020-01-20 10:56:25 +01:00
parent d8ce7d353d
commit 3a61646ab4
4 changed files with 28 additions and 23 deletions

View File

@@ -1,8 +1,8 @@
package webdav
import (
"encoding/xml"
"net/http"
"fmt"
"github.com/emersion/go-webdav/internal"
)
@@ -24,18 +24,20 @@ func (c *Client) SetBasicAuth(username, password string) {
}
func (c *Client) FindCurrentUserPrincipal() (string, error) {
name := xml.Name{"DAV:", "current-user-principal"}
propfind := internal.NewPropNamePropfind(name)
propfind := internal.NewPropNamePropfind(internal.CurrentUserPrincipalName)
resp, err := c.c.PropfindFlat("/", propfind)
if err != nil {
return "", err
}
var prop currentUserPrincipal
var prop internal.CurrentUserPrincipal
if err := resp.DecodeProp(&prop); err != nil {
return "", err
}
if prop.Unauthenticated != nil {
return "", fmt.Errorf("webdav: unauthenticated")
}
return prop.Href, nil
}