mirror of
https://github.com/rclone/rclone.git
synced 2025-01-10 16:28:30 +01:00
Revert "jottacloud: always store username in config and use it to avoid initial api request"
This reverts commit 9dbed02329
.
See: #6309
This commit is contained in:
parent
2f461f13e3
commit
9f40cb114a
@ -152,7 +152,7 @@ func Config(ctx context.Context, name string, m configmap.Mapper, config fs.Conf
|
|||||||
m.Set(configClientSecret, "")
|
m.Set(configClientSecret, "")
|
||||||
|
|
||||||
srv := rest.NewClient(fshttp.NewClient(ctx))
|
srv := rest.NewClient(fshttp.NewClient(ctx))
|
||||||
token, tokenEndpoint, username, err := doTokenAuth(ctx, srv, loginToken)
|
token, tokenEndpoint, err := doTokenAuth(ctx, srv, loginToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get oauth token: %w", err)
|
return nil, fmt.Errorf("failed to get oauth token: %w", err)
|
||||||
}
|
}
|
||||||
@ -161,7 +161,6 @@ func Config(ctx context.Context, name string, m configmap.Mapper, config fs.Conf
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error while saving token: %w", err)
|
return nil, fmt.Errorf("error while saving token: %w", err)
|
||||||
}
|
}
|
||||||
m.Set(configUsername, username)
|
|
||||||
return fs.ConfigGoto("choose_device")
|
return fs.ConfigGoto("choose_device")
|
||||||
case "legacy": // configure a jottacloud backend using legacy authentication
|
case "legacy": // configure a jottacloud backend using legacy authentication
|
||||||
m.Set("configVersion", fmt.Sprint(legacyConfigVersion))
|
m.Set("configVersion", fmt.Sprint(legacyConfigVersion))
|
||||||
@ -272,30 +271,22 @@ sync or the backup section, for example, you must choose yes.`)
|
|||||||
if config.Result != "true" {
|
if config.Result != "true" {
|
||||||
m.Set(configDevice, "")
|
m.Set(configDevice, "")
|
||||||
m.Set(configMountpoint, "")
|
m.Set(configMountpoint, "")
|
||||||
}
|
|
||||||
username, userOk := m.Get(configUsername)
|
|
||||||
if userOk && config.Result != "true" {
|
|
||||||
return fs.ConfigGoto("end")
|
return fs.ConfigGoto("end")
|
||||||
}
|
}
|
||||||
oAuthClient, _, err := getOAuthClient(ctx, name, m)
|
oAuthClient, _, err := getOAuthClient(ctx, name, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !userOk {
|
jfsSrv := rest.NewClient(oAuthClient).SetRoot(jfsURL)
|
||||||
apiSrv := rest.NewClient(oAuthClient).SetRoot(apiURL)
|
apiSrv := rest.NewClient(oAuthClient).SetRoot(apiURL)
|
||||||
|
|
||||||
cust, err := getCustomerInfo(ctx, apiSrv)
|
cust, err := getCustomerInfo(ctx, apiSrv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
username = cust.Username
|
m.Set(configUsername, cust.Username)
|
||||||
m.Set(configUsername, username)
|
|
||||||
if config.Result != "true" {
|
|
||||||
return fs.ConfigGoto("end")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jfsSrv := rest.NewClient(oAuthClient).SetRoot(jfsURL)
|
acc, err := getDriveInfo(ctx, jfsSrv, cust.Username)
|
||||||
acc, err := getDriveInfo(ctx, jfsSrv, username)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -591,10 +582,10 @@ func doLegacyAuth(ctx context.Context, srv *rest.Client, oauthConfig *oauth2.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doTokenAuth runs the actual token request for V2 authentication
|
// doTokenAuth runs the actual token request for V2 authentication
|
||||||
func doTokenAuth(ctx context.Context, apiSrv *rest.Client, loginTokenBase64 string) (token oauth2.Token, tokenEndpoint string, username string, err error) {
|
func doTokenAuth(ctx context.Context, apiSrv *rest.Client, loginTokenBase64 string) (token oauth2.Token, tokenEndpoint string, err error) {
|
||||||
loginTokenBytes, err := base64.RawURLEncoding.DecodeString(loginTokenBase64)
|
loginTokenBytes, err := base64.RawURLEncoding.DecodeString(loginTokenBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return token, "", "", err
|
return token, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode login token
|
// decode login token
|
||||||
@ -602,7 +593,7 @@ func doTokenAuth(ctx context.Context, apiSrv *rest.Client, loginTokenBase64 stri
|
|||||||
decoder := json.NewDecoder(bytes.NewReader(loginTokenBytes))
|
decoder := json.NewDecoder(bytes.NewReader(loginTokenBytes))
|
||||||
err = decoder.Decode(&loginToken)
|
err = decoder.Decode(&loginToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return token, "", "", err
|
return token, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieve endpoint urls
|
// retrieve endpoint urls
|
||||||
@ -613,7 +604,7 @@ func doTokenAuth(ctx context.Context, apiSrv *rest.Client, loginTokenBase64 stri
|
|||||||
var wellKnown api.WellKnown
|
var wellKnown api.WellKnown
|
||||||
_, err = apiSrv.CallJSON(ctx, &opts, nil, &wellKnown)
|
_, err = apiSrv.CallJSON(ctx, &opts, nil, &wellKnown)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return token, "", "", err
|
return token, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare out token request with username and password
|
// prepare out token request with username and password
|
||||||
@ -635,14 +626,14 @@ func doTokenAuth(ctx context.Context, apiSrv *rest.Client, loginTokenBase64 stri
|
|||||||
var jsonToken api.TokenJSON
|
var jsonToken api.TokenJSON
|
||||||
_, err = apiSrv.CallJSON(ctx, &opts, nil, &jsonToken)
|
_, err = apiSrv.CallJSON(ctx, &opts, nil, &jsonToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return token, "", "", err
|
return token, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
token.AccessToken = jsonToken.AccessToken
|
token.AccessToken = jsonToken.AccessToken
|
||||||
token.RefreshToken = jsonToken.RefreshToken
|
token.RefreshToken = jsonToken.RefreshToken
|
||||||
token.TokenType = jsonToken.TokenType
|
token.TokenType = jsonToken.TokenType
|
||||||
token.Expiry = time.Now().Add(time.Duration(jsonToken.ExpiresIn) * time.Second)
|
token.Expiry = time.Now().Add(time.Duration(jsonToken.ExpiresIn) * time.Second)
|
||||||
return token, wellKnown.TokenEndpoint, loginToken.Username, err
|
return token, wellKnown.TokenEndpoint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// getCustomerInfo queries general information about the account
|
// getCustomerInfo queries general information about the account
|
||||||
@ -944,17 +935,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
|
|||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
user, userOk := m.Get(configUsername)
|
|
||||||
if userOk {
|
|
||||||
f.user = user
|
|
||||||
} else {
|
|
||||||
fs.Infof(nil, "Username not found in config and must be looked up, reconfigure to avoid the extra request")
|
|
||||||
cust, err := getCustomerInfo(ctx, f.apiSrv)
|
cust, err := getCustomerInfo(ctx, f.apiSrv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f.user = cust.Username
|
f.user = cust.Username
|
||||||
}
|
|
||||||
f.setEndpoints()
|
f.setEndpoints()
|
||||||
|
|
||||||
if root != "" && !rootIsDir {
|
if root != "" && !rootIsDir {
|
||||||
|
Loading…
Reference in New Issue
Block a user