diff --git a/backend/webdav/odrvcookie/fetch.go b/backend/webdav/odrvcookie/fetch.go
index f6b25d29e..c3ade04e5 100644
--- a/backend/webdav/odrvcookie/fetch.go
+++ b/backend/webdav/odrvcookie/fetch.go
@@ -74,7 +74,7 @@ xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-util
http://www.w3.org/2005/08/addressing/anonymous
-https://login.microsoftonline.com/extSTS.srf
+{{ .SPTokenURL }}
@@ -159,11 +159,37 @@ func (ca *CookieAuth) getSPCookie(conf *SharepointSuccessResponse) (*CookieRespo
return &cookieResponse, nil
}
+var spTokenURLMap = map[string]string{
+ "com": "https://login.microsoftonline.com",
+ "cn": "https://login.chinacloudapi.cn",
+ "us": "https://login.microsoftonline.us",
+ "de": "https://login.microsoftonline.de",
+}
+
+func getSPTokenURL(endpoint string) (string, error) {
+ spRoot, err := url.Parse(endpoint)
+ if err != nil {
+ return "", fmt.Errorf("error while parse endpoint: %w", err)
+ }
+ domains := strings.Split(spRoot.Host, ".")
+ tld := domains[len(domains)-1]
+ spTokenURL, ok := spTokenURLMap[tld]
+ if !ok {
+ return "", fmt.Errorf("error while get SPToken url, unsupported tld: %s", tld)
+ }
+ return spTokenURL + "/extSTS.srf", nil
+}
+
func (ca *CookieAuth) getSPToken(ctx context.Context) (conf *SharepointSuccessResponse, err error) {
+ spTokenURL, err := getSPTokenURL(ca.endpoint)
+ if err != nil {
+ return nil, err
+ }
reqData := map[string]interface{}{
- "Username": ca.user,
- "Password": ca.pass,
- "Address": ca.endpoint,
+ "Username": ca.user,
+ "Password": ca.pass,
+ "Address": ca.endpoint,
+ "SPTokenURL": spTokenURL,
}
t := template.Must(template.New("authXML").Parse(reqString))
@@ -175,7 +201,7 @@ func (ca *CookieAuth) getSPToken(ctx context.Context) (conf *SharepointSuccessRe
// Create and execute the first request which returns an auth token for the sharepoint service
// With this token we can authenticate on the login page and save the returned cookies
- req, err := http.NewRequestWithContext(ctx, "POST", "https://login.microsoftonline.com/extSTS.srf", buf)
+ req, err := http.NewRequestWithContext(ctx, "POST", spTokenURL, buf)
if err != nil {
return nil, err
}