mirror of
https://github.com/rclone/rclone.git
synced 2024-11-29 03:48:27 +08:00
webdav: add SharePoint in other specific regions support
This commit is contained in:
parent
e3d44612c1
commit
ef089dd867
|
@ -74,7 +74,7 @@ xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-util
|
||||||
<a:ReplyTo>
|
<a:ReplyTo>
|
||||||
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
|
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
|
||||||
</a:ReplyTo>
|
</a:ReplyTo>
|
||||||
<a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>
|
<a:To s:mustUnderstand="1">{{ .SPTokenURL }}</a:To>
|
||||||
<o:Security s:mustUnderstand="1"
|
<o:Security s:mustUnderstand="1"
|
||||||
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
||||||
<o:UsernameToken>
|
<o:UsernameToken>
|
||||||
|
@ -159,11 +159,37 @@ func (ca *CookieAuth) getSPCookie(conf *SharepointSuccessResponse) (*CookieRespo
|
||||||
return &cookieResponse, nil
|
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) {
|
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{}{
|
reqData := map[string]interface{}{
|
||||||
"Username": ca.user,
|
"Username": ca.user,
|
||||||
"Password": ca.pass,
|
"Password": ca.pass,
|
||||||
"Address": ca.endpoint,
|
"Address": ca.endpoint,
|
||||||
|
"SPTokenURL": spTokenURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
t := template.Must(template.New("authXML").Parse(reqString))
|
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
|
// 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
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user