Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Aug 3, 2024
1 parent a3d130d commit 99cef0b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion backend/icloud/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -74,9 +75,12 @@ func (c *Client) Request(ctx context.Context, opts rest.Opts, request interface{
resp, err = c.Session.Request(ctx, opts, request, response)
if err != nil && resp != nil {
// try to reauth
if resp.StatusCode == 401 && c.Session.TrustToken != "" {
if resp.StatusCode == 401 || resp.StatusCode == 401 {
err = c.Authenticate(ctx)
if err != nil {
if c.Session.Requires2FA() {
return nil, errors.New("Trust token expired, please reauth")
}
return nil, err
}
return c.RequestNoReAuth(ctx, opts, request, response)
Expand Down
8 changes: 2 additions & 6 deletions backend/icloud/api/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/google/uuid"
"github.com/oracle/oci-go-sdk/v65/common"

//"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs"

"github.com/rclone/rclone/fs/fshttp"
"github.com/rclone/rclone/lib/rest"
Expand Down Expand Up @@ -43,10 +43,7 @@ func (s *Session) Request(ctx context.Context, opts rest.Opts, request interface
resp, err := s.srv.CallJSON(ctx, &opts, &request, &response)

if err != nil {
//fs.PrettyPrint(opts, "opts", fs.LogLevelDebug)
//fs.PrettyPrint(resp, "resp", fs.LogLevelDebug)
return resp, err
//return resp, fmt.Errorf("%s %s failed, status %d, err: %s", opts.Method, resp.Request.URL, resp.StatusCode, err)
}

if val := resp.Header.Get("X-Apple-ID-Account-Country"); val != "" {
Expand Down Expand Up @@ -125,9 +122,8 @@ func (s *Session) AuthWithToken(ctx context.Context) error {
RootURL: setupEndpoint,
Body: body,
}
// X-APPLE-WEBAUTH-TOKEN
resp, err := s.Request(ctx, opts, nil, &s.AccountInfo)

resp, err := s.Request(ctx, opts, nil, &s.AccountInfo)
if err == nil {
s.Cookies = resp.Cookies()
}
Expand Down
4 changes: 4 additions & 0 deletions backend/icloud/icloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,10 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
return nil, err
}

if icloud.Session.Requires2FA() {
return nil, errors.New("Trust token expired, please reauth")
}

root = strings.Trim(root, "/")
f := &Fs{
name: name,
Expand Down
4 changes: 2 additions & 2 deletions docs/content/iclouddrive.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ versionIntroduced: "v1.66"

## Configuration

The initial setup for an iCloud Drive backend involves getting a session.
`rclone config` walks you through it.
The initial setup for an iCloud Drive backend involves getting a trust token/session.
`rclone config` walks you through it. The trust token is valid for 30 days. After which you will have to reauthenticate with rclone config.

Here is an example of how to make a remote called `iclouddrive`. First run:

Expand Down

0 comments on commit 99cef0b

Please sign in to comment.