diff --git a/backend/icloud/api/client.go b/backend/icloud/api/client.go index 7e6056e1e61e0..4da598a8633b3 100644 --- a/backend/icloud/api/client.go +++ b/backend/icloud/api/client.go @@ -43,7 +43,7 @@ type Client struct { // - trustToken: the trust token for the session. // - cookies: the cookies for the session. // - sessionSaveCallback: the callback function to save the session. -func New(appleID, password, trustToken string, cookies []*http.Cookie, sessionSaveCallback sessionSave) (*Client, error) { +func New(appleID, password, trustToken string, clientID string, cookies []*http.Cookie, sessionSaveCallback sessionSave) (*Client, error) { icloud := &Client{ appleID: appleID, password: password, @@ -54,6 +54,7 @@ func New(appleID, password, trustToken string, cookies []*http.Cookie, sessionSa icloud.Session.TrustToken = trustToken icloud.Session.Cookies = cookies + icloud.Session.ClientID = clientID return icloud, nil } diff --git a/backend/icloud/api/session.go b/backend/icloud/api/session.go index 53d60d940fb4c..1d67868fce7bb 100644 --- a/backend/icloud/api/session.go +++ b/backend/icloud/api/session.go @@ -9,7 +9,6 @@ import ( "slices" "strings" - "github.com/google/uuid" "github.com/oracle/oci-go-sdk/v65/common" "github.com/rclone/rclone/fs/fshttp" @@ -201,14 +200,14 @@ func (s *Session) GetAuthHeaders(overwrite map[string]string) map[string]string headers := map[string]string{ "Accept": "application/json", "Content-Type": "application/json", - "X-Apple-OAuth-Client-Id": "d39ba9916b7251055b22c7f910e2ea796ee65e98b2ddecea8f5dde8d9d1a815d", + "X-Apple-OAuth-Client-Id": s.ClientID, "X-Apple-OAuth-Client-Type": "firstPartyAuth", "X-Apple-OAuth-Redirect-URI": "https://www.icloud.com", "X-Apple-OAuth-Require-Grant-Code": "true", "X-Apple-OAuth-Response-Mode": "web_message", "X-Apple-OAuth-Response-Type": "code", "X-Apple-OAuth-State": s.ClientID, - "X-Apple-Widget-Key": "d39ba9916b7251055b22c7f910e2ea796ee65e98b2ddecea8f5dde8d9d1a815d", + "X-Apple-Widget-Key": s.ClientID, "Origin": homeEndpoint, "Referer": fmt.Sprintf("%s/", homeEndpoint), "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0", @@ -282,7 +281,7 @@ func GetCookiesForDomain(url *url.URL, cookies []*http.Cookie) ([]*http.Cookie, func NewSession() *Session { session := &Session{} session.srv = rest.NewClient(fshttp.NewClient(context.Background())).SetRoot(baseEndpoint) - session.ClientID = "auth-" + uuid.New().String() + //session.ClientID = "auth-" + uuid.New().String() return session } diff --git a/backend/icloud/icloud.go b/backend/icloud/icloud.go index 6b1b90e872795..aaf22d2516395 100644 --- a/backend/icloud/icloud.go +++ b/backend/icloud/icloud.go @@ -41,6 +41,7 @@ const ( configAppleID = "apple_id" configPassword = "password" configCookies = "cookies" + configClientID = "client_id" configTrustToken = "trust_token" minSleep = 10 * time.Millisecond @@ -80,6 +81,12 @@ func init() { Advanced: false, Sensitive: true, Hide: fs.OptionHideBoth, + }, { + Name: configClientID, + Help: "client id", + Required: false, + Advanced: true, + Default: "d39ba9916b7251055b22c7f910e2ea796ee65e98b2ddecea8f5dde8d9d1a815d", }, { Name: config.ConfigEncoding, @@ -100,6 +107,7 @@ type Options struct { Photos bool `config:"photos"` TrustToken string `config:"trust_token"` Cookies string `config:"cookies"` + ClientID string `config:"client_id"` Enc encoder.MultiEncoder `config:"encoding"` } @@ -144,11 +152,12 @@ func Config(ctx context.Context, name string, m configmap.Mapper, config fs.Conf trustToken, _ := m.Get(configTrustToken) cookieRaw, _ := m.Get(configCookies) + clientID, _ := m.Get(configClientID) cookies := ReadCookies(cookieRaw) switch config.State { case "": - icloud, _ := api.New(appleid, password, trustToken, cookies, nil) + icloud, _ := api.New(appleid, password, trustToken, clientID, cookies, nil) if err := icloud.Authenticate(ctx); err != nil { return nil, err } @@ -163,7 +172,7 @@ func Config(ctx context.Context, name string, m configmap.Mapper, config fs.Conf return fs.ConfigError("authenticate", "2FA codes can't be blank") } - icloud, _ := api.New(appleid, password, trustToken, cookies, nil) + icloud, _ := api.New(appleid, password, trustToken, clientID, cookies, nil) if err := icloud.SignIn(ctx); err != nil { return nil, err } @@ -802,6 +811,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e opt.AppleID, opt.Password, opt.TrustToken, + opt.ClientID, cookies, callback, ) @@ -1055,8 +1065,6 @@ func (o *Object) String() string { } // Update implements fs.Object. -// TODO: Implement restoring the old file when an errror occures during upload -// TODO: Implement removing old file from trash when upload is succesfull func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error { size := src.Size() if size < 0 {