From 74a0800a4c8bd62ae8e0c120f1cdb8ca1c3ea91b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 6 Aug 2022 17:16:05 +0100 Subject: [PATCH] oauthutil: add scopes to token exchange for onedrive See: https://forum.rclone.org/t/onedrive-config-auth-failure-body-must-contain-scope/32230/7 --- lib/oauthutil/oauthutil.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/oauthutil/oauthutil.go b/lib/oauthutil/oauthutil.go index 350fe1671..6ad890c45 100644 --- a/lib/oauthutil/oauthutil.go +++ b/lib/oauthutil/oauthutil.go @@ -677,7 +677,11 @@ func configSetup(ctx context.Context, id, name string, m configmap.Mapper, oauth // Exchange the code for a token func configExchange(ctx context.Context, name string, m configmap.Mapper, oauthConfig *oauth2.Config, code string) error { ctx = Context(ctx, fshttp.NewClient(ctx)) - token, err := oauthConfig.Exchange(ctx, code) + var opts []oauth2.AuthCodeOption + if len(oauthConfig.Scopes) > 0 { + opts = append(opts, oauth2.SetAuthURLParam("scope", strings.Join(oauthConfig.Scopes, " "))) + } + token, err := oauthConfig.Exchange(ctx, code, opts...) if err != nil { return fmt.Errorf("failed to get token: %w", err) }