From 6555d3eb33b6c3418fb8ff13f9a2ea5f776b4654 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 17 May 2021 10:00:54 +0100 Subject: [PATCH] onedrive: fix failed to configure: empty token found error #3455 This bug was caused as part of the config rework --- backend/onedrive/onedrive.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index 31a707239..16c1225fe 100755 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -371,15 +371,9 @@ func chooseDrive(ctx context.Context, name string, m configmap.Mapper, srv *rest // Config the backend func Config(ctx context.Context, name string, m configmap.Mapper, config fs.ConfigIn) (*fs.ConfigOut, error) { - oAuthClient, _, err := oauthutil.NewClient(ctx, name, m, oauthConfig) - if err != nil { - return nil, errors.Wrap(err, "failed to configure OneDrive") - } - srv := rest.NewClient(oAuthClient) region, graphURL := getRegionURL(m) - switch config.State { - case "": + if config.State == "" { oauthConfig.Endpoint = oauth2.Endpoint{ AuthURL: authEndpoint[region] + authPath, TokenURL: authEndpoint[region] + tokenPath, @@ -387,6 +381,15 @@ func Config(ctx context.Context, name string, m configmap.Mapper, config fs.Conf return oauthutil.ConfigOut("choose_type", &oauthutil.Options{ OAuth2Config: oauthConfig, }) + } + + oAuthClient, _, err := oauthutil.NewClient(ctx, name, m, oauthConfig) + if err != nil { + return nil, errors.Wrap(err, "failed to configure OneDrive") + } + srv := rest.NewClient(oAuthClient) + + switch config.State { case "choose_type": return fs.ConfigChooseFixed("choose_type_done", "config_type", "Type of connection", []fs.OptionExample{{ Value: "onedrive",