From 78ca08ba8ae686df7178ebb61679564a8bd3a48a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 25 May 2020 15:12:25 +0100 Subject: [PATCH] pcloud: fix initial config "Auth state doesn't match" message #4210 pCloud should be passing back the state parameter that rclone passed in on config but it seems to have got lost somewhere. This sets a work-around for the pCloud backend allowing an empty state parameter. See: https://forum.rclone.org/t/cannot-connect-to-pcloud/16592 See: https://forum.rclone.org/t/cannot-create-pcloud-config-file-on-osx/16583 --- backend/pcloud/pcloud.go | 5 ++++- lib/oauthutil/oauthutil.go | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/pcloud/pcloud.go b/backend/pcloud/pcloud.go index 61fe271c2..35386dfd7 100644 --- a/backend/pcloud/pcloud.go +++ b/backend/pcloud/pcloud.go @@ -67,7 +67,10 @@ func init() { Description: "Pcloud", NewFs: NewFs, Config: func(name string, m configmap.Mapper) { - err := oauthutil.Config("pcloud", name, m, oauthConfig, nil) + opt := oauthutil.Options{ + StateBlankOK: true, // pCloud seems to drop the state parameter now - see #4210 + } + err := oauthutil.Config("pcloud", name, m, oauthConfig, &opt) if err != nil { log.Fatalf("Failed to configure token: %v", err) } diff --git a/lib/oauthutil/oauthutil.go b/lib/oauthutil/oauthutil.go index ff9a9c0f6..2ea4f8a32 100644 --- a/lib/oauthutil/oauthutil.go +++ b/lib/oauthutil/oauthutil.go @@ -362,9 +362,10 @@ type CheckAuthFn func(*oauth2.Config, *AuthResult) error // Options for the oauth config type Options struct { - NoOffline bool // If set then "access_type=offline" parameter is not passed - CheckAuth CheckAuthFn // When the AuthResult is known the checkAuth function is called if set - OAuth2Opts []oauth2.AuthCodeOption // extra oauth2 options + NoOffline bool // If set then "access_type=offline" parameter is not passed + CheckAuth CheckAuthFn // When the AuthResult is known the checkAuth function is called if set + OAuth2Opts []oauth2.AuthCodeOption // extra oauth2 options + StateBlankOK bool // If set, state returned as "" is deemed to be OK } // Config does the initial creation of the token @@ -580,7 +581,7 @@ func (s *authServer) handleAuth(w http.ResponseWriter, req *http.Request) { // check state state := req.Form.Get("state") - if state != s.state { + if state != s.state && !(state == "" && s.opt.StateBlankOK) { reply(http.StatusBadRequest, &AuthResult{ Name: "Auth state doesn't match", Description: fmt.Sprintf("Expecting %q got %q", s.state, state),