From 682b4d54c5a22c0032359cf26ec94797ab1c5aa8 Mon Sep 17 00:00:00 2001 From: Oliver Heyme Date: Sat, 28 Oct 2017 18:48:39 +0200 Subject: [PATCH] onedrive: Add option to choose resourceURL during setup of OneDrive Business account if more than one is avauilable for user --- onedrive/onedrive.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/onedrive/onedrive.go b/onedrive/onedrive.go index 8859a8106..d9d613490 100644 --- a/onedrive/onedrive.go +++ b/onedrive/onedrive.go @@ -135,25 +135,31 @@ func init() { return } - foundService := "" + var resourcesURL []string + var resourcesID []string + for _, service := range services.Services { if service.ServiceAPIVersion == "v2.0" { - foundService = service.ServiceResourceID - fs.ConfigFileSet(name, configResourceURL, foundService) - oauthBusinessResource = oauth2.SetAuthURLParam("resource", foundService) - - fs.Logf(nil, "Found API %s endpoint %s", service.ServiceAPIVersion, service.ServiceEndpointURI) - break + resourcesID = append(resourcesID, service.ServiceResourceID) + resourcesURL = append(resourcesURL, service.ServiceEndpointURI) } // we only support 2.0 API fs.Infof(nil, "Skipping API %s endpoint %s", service.ServiceAPIVersion, service.ServiceEndpointURI) } - if foundService == "" { + var foundService string + if len(resourcesID) == 0 { fs.Errorf(nil, "No Service found") return + } else if len(resourcesID) == 1 { + foundService = resourcesID[0] + } else { + foundService = fs.Choose("Choose resource URL", resourcesID, resourcesURL, false) } + fs.ConfigFileSet(name, configResourceURL, foundService) + oauthBusinessResource = oauth2.SetAuthURLParam("resource", foundService) + // get the token from the inital config // we need to update the token with a resource // specific token we will query now