"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
jottacloud: add device registration
Oliver Heyme0d4a3520ad78
diff --git a/backend/jottacloud/api/types.go b/backend/jottacloud/api/types.goindex 292e4208c..8f2339939 100644--- a/backend/jottacloud/api/types.go+++ b/backend/jottacloud/api/types.go@@ -314,3 +314,9 @@ type UploadResponse struct {Deleted interface{} `json:"deleted"`Mime string `json:"mime"`}++// DeviceRegistrationResponse is the response to registering a device+type DeviceRegistrationResponse struct {+ ClientID string `json:"client_id"`+ ClientSecret string `json:"client_secret"`+}diff --git a/backend/jottacloud/jottacloud.go b/backend/jottacloud/jottacloud.goindex 4bbc705da..7015bc8a9 100644--- a/backend/jottacloud/jottacloud.go+++ b/backend/jottacloud/jottacloud.go@@ -8,6 +8,7 @@ import ("io""io/ioutil""log"+ "math/rand""net/http""net/url""os"@@ -45,10 +46,14 @@ const (apiURL = "https://api.jottacloud.com/files/v1/"baseURL = "https://www.jottacloud.com/"tokenURL = "https://api.jottacloud.com/auth/v1/token"+ registerURL = "https://api.jottacloud.com/auth/v1/register"cachePrefix = "rclone-jcmd5-"rcloneClientID = "nibfk8biu12ju7hpqomr8b1e40"rcloneEncryptedClientSecret = "Vp8eAv7eVElMnQwN-kgU9cbhgApNDaMqWdlDi5qFydlQoji4JBxrGMF2"configUsername = "user"+ configClientID = "client_id"+ configClientSecret = "client_secret"+ charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")var (@@ -58,9 +63,7 @@ var (AuthURL: tokenURL,TokenURL: tokenURL,},- ClientID: rcloneClientID,- ClientSecret: obscure.MustReveal(rcloneEncryptedClientSecret),- RedirectURL: oauthutil.RedirectLocalhostURL,+ RedirectURL: oauthutil.RedirectLocalhostURL,})@@ -79,6 +82,55 @@ func init() {}}+ srv := rest.NewClient(fshttp.NewClient(fs.Config))++ // ask if we should create a device specifc token: https://github.com/ncw/rclone/issues/2995+ fmt.Printf("\nDo you want to create a machine specific API key?\n\nRclone has it's own Jottacloud API KEY which works fine as long as one only uses rclone on a single machine. When you want to use rclone with this account on more than one machine it's recommended to create a machine specific API key. These keys can NOT be shared between machines.\n\n")+ if config.Confirm() {+ // random generator to generate random device names+ seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))+ randonDeviceNamePartLength := 21+ randomDeviceNamePart := make([]byte, randonDeviceNamePartLength)+ for i := range randomDeviceNamePart {+ randomDeviceNamePart[i] = charset[seededRand.Intn(len(charset))]+ }+ randomDeviceName := "rclone-" + string(randomDeviceNamePart)+ fs.Debugf(nil, "Trying to register device '%s'", randomDeviceName)++ values := url.Values{}+ values.Set("device_id", randomDeviceName)++ // all information comes from https://github.com/ttyridal/aiojotta/wiki/Jotta-protocol-3.-Authentication#token-authentication+ opts := rest.Opts{+ Method: "POST",+ RootURL: registerURL,+ ContentType: "application/x-www-form-urlencoded",+ ExtraHeaders: map[string]string{"Authorization": "Bearer c2xrZmpoYWRsZmFramhkc2xma2phaHNkbGZramhhc2xkZmtqaGFzZGxrZmpobGtq"},+ Parameters: values,+ }++ var deviceRegistration api.DeviceRegistrationResponse+ _, err := srv.CallJSON(&opts, nil, &deviceRegistration)+ if err != nil {+ log.Fatalf("Failed to register device: %v", err)+ }++ m.Set(configClientID, deviceRegistration.ClientID)+ m.Set(configClientSecret, obscure.MustObscure(deviceRegistration.ClientSecret))+ fs.Debugf(nil, "Got clientID '%s' and clientSecret '%s'", deviceRegistration.ClientID, deviceRegistration.ClientSecret)+ }++ clientID, ok := m.Get(configClientID)+ if !ok {+ clientID = rcloneClientID+ }+ clientSecret, ok := m.Get(configClientSecret)+ if !ok {+ clientSecret = rcloneEncryptedClientSecret+ }+ oauthConfig.ClientID = clientID+ oauthConfig.ClientSecret = obscure.MustReveal(clientSecret)+username, ok := m.Get(configUsername)if !ok {log.Fatalf("No username defined")@@ -86,7 +138,6 @@ func init() {password := config.GetPassword("Your Jottacloud password is only required during config and will not be stored.")// prepare out token request with username and password- srv := rest.NewClient(fshttp.NewClient(fs.Config))values := url.Values{}values.Set("grant_type", "PASSWORD")values.Set("password", password)@@ -381,6 +432,17 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {rootIsDir := strings.HasSuffix(root, "/")root = parsePath(root)+ clientID, ok := m.Get(configClientID)+ if !ok {+ clientID = rcloneClientID+ }+ clientSecret, ok := m.Get(configClientSecret)+ if !ok {+ clientSecret = rcloneEncryptedClientSecret+ }+ oauthConfig.ClientID = clientID+ oauthConfig.ClientSecret = obscure.MustReveal(clientSecret)+// add jottacloud to the long list of sites that don't follow the oauth spec correctlyoauth2.RegisterBrokenAuthHeaderProvider("https://www.jottacloud.com/")diff --git a/docs/content/jottacloud.md b/docs/content/jottacloud.mdindex c62a2ebab..7e886cd38 100644--- a/docs/content/jottacloud.md+++ b/docs/content/jottacloud.md@@ -37,15 +37,6 @@ Storage> jottacloudUser NameEnter a string value. Press Enter for the default ("").user> user-Password.-y) Yes type in my own password-g) Generate random password-n) No leave this optional password blank-y/g/n> y-Enter the password:-password:-Confirm the password:-password:The mountpoint to use.Enter a string value. Press Enter for the default ("").Choose a number from below, or type in your own value@@ -54,13 +45,29 @@ Choose a number from below, or type in your own value2 / Archive\ "Archive"mountpoint> Archive+Edit advanced config? (y/n)+y) Yes+n) No+y/n> nRemote config++Do you want to create a machine specific API key?++Rclone has it's own Jottacloud API KEY which works fine as long as one only uses rclone on a single machine. When you want to use rclone with this account on more than one machine it's recommended to create a machine specific API key. These keys can NOT be shared between machines.++y) Yes+n) No+y/n> y+Your Jottacloud password is only required during config and will not be stored.+password:--------------------[remote]type = jottacloud-user = user-pass = *** ENCRYPTED ***+user = oliheymountpoint = Archive+client_id = .....+client_secret = ........+token = {........}--------------------y) Yes this is OKe) Edit this remote@@ -124,6 +131,10 @@ To view your current quota you can use the `rclone about remote:`command which will display your usage limit (unless it is unlimited)and the current usage.+### Device IDs ###++Jottacloud requires each 'device' to be registered. Rclone brings such a registration to easily access your account but if you want to use Jottacloud together with rclone on multiple machines you NEED to create a seperate deviceID/deviceSecrect on each machine. You will asked during setting up the remote. Please be aware that this also means that copying the rclone config from one machine to another does NOT work with Jottacloud accounts. You have to create it on each machine.+<!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/jottacloud/jottacloud.go then run make backenddocs -->### Standard Options