diff --git a/backend/webdav/odrvcookie/fetch.go b/backend/webdav/odrvcookie/fetch.go index 960eb3b52..657971fad 100644 --- a/backend/webdav/odrvcookie/fetch.go +++ b/backend/webdav/odrvcookie/fetch.go @@ -5,6 +5,7 @@ import ( "bytes" "context" "encoding/xml" + "fmt" "html/template" "net/http" "net/http/cookiejar" @@ -32,13 +33,13 @@ type CookieResponse struct { FedAuth http.Cookie } -// SuccessResponse hold a response from the sharepoint webdav -type SuccessResponse struct { +// SharepointSuccessResponse holds a response from a successful microsoft login +type SharepointSuccessResponse struct { XMLName xml.Name `xml:"Envelope"` - Succ SuccessResponseBody `xml:"Body"` + Body SuccessResponseBody `xml:"Body"` } -// SuccessResponseBody is the body of a success response, it holds the token +// SuccessResponseBody is the body of a successful response, it holds the token type SuccessResponseBody struct { XMLName xml.Name Type string `xml:"RequestSecurityTokenResponse>TokenType"` @@ -47,6 +48,24 @@ type SuccessResponseBody struct { Token string `xml:"RequestSecurityTokenResponse>RequestedSecurityToken>BinarySecurityToken"` } +// SharepointError holds a error response microsoft login +type SharepointError struct { + XMLName xml.Name `xml:"Envelope"` + Body ErrorResponseBody `xml:"Body"` +} + +func (e *SharepointError) Error() string { + return fmt.Sprintf("%s: %s (%s)", e.Body.FaultCode, e.Body.Reason, e.Body.Detail) +} + +// ErrorResponseBody contains the body of a erroneous repsonse +type ErrorResponseBody struct { + XMLName xml.Name + FaultCode string `xml:"Fault>Code>Subcode>Value"` + Reason string `xml:"Fault>Reason>Text"` + Detail string `xml:"Fault>Detail>error>internalerror>text"` +} + // reqString is a template that gets populated with the user data in order to retrieve a "BinarySecurityToken" const reqString = `