Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Sep 23, 2024
1 parent cb4884d commit 18500da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion backend/icloud/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
7 changes: 3 additions & 4 deletions backend/icloud/api/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 12 additions & 4 deletions backend/icloud/icloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
configAppleID = "apple_id"
configPassword = "password"
configCookies = "cookies"
configClientID = "client_id"
configTrustToken = "trust_token"

minSleep = 10 * time.Millisecond
Expand Down Expand Up @@ -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,
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 18500da

Please sign in to comment.