oauthutil: add scopes to token exchange for onedrive

See: https://forum.rclone.org/t/onedrive-config-auth-failure-body-must-contain-scope/32230/7
This commit is contained in:
Nick Craig-Wood 2022-08-06 17:16:05 +01:00
parent df513ca90a
commit 74a0800a4c
1 changed files with 5 additions and 1 deletions

View File

@ -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)
}