{"record":{"id":"4088b52eadda1493","repo":"AlistGo/alist","slug":"cannot-login-to-get-refresh-token-error-s","errorCode":null,"errorMessage":"cannot login to get refresh token, error: %s","messagePattern":"cannot login to get refresh token, error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/cloudreve_v4/util.go","lineNumber":183,"sourceCode":"\tvar token TokenResponse\n\terr = d.request(http.MethodPost, \"/session/token\", func(req *resty.Request) {\n\t\treq.SetBody(loginBody)\n\t}, &token)\n\tif err != nil {\n\t\treturn err\n\t}\n\td.AccessToken, d.RefreshToken = token.Token.AccessToken, token.Token.RefreshToken\n\top.MustSaveDriverStorage(d)\n\treturn nil\n}\n\nfunc (d *CloudreveV4) refreshToken() error {\n\tvar token Token\n\tif token.RefreshToken == \"\" {\n\t\tif d.Username != \"\" {\n\t\t\terr := d.login()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot login to get refresh token, error: %s\", err)\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\terr := d.request(http.MethodPost, \"/session/token/refresh\", func(req *resty.Request) {\n\t\treq.SetBody(base.Json{\n\t\t\t\"refresh_token\": d.RefreshToken,\n\t\t})\n\t}, &token)\n\tif err != nil {\n\t\treturn err\n\t}\n\td.AccessToken, d.RefreshToken = token.AccessToken, token.RefreshToken\n\top.MustSaveDriverStorage(d)\n\treturn nil\n}\n\nfunc (d *CloudreveV4) upLocal(ctx context.Context, file model.FileStreamer, u FileUploadResp, up driver.UpdateProgress) error {","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/cloudreve_v4/util.go#L165-L201","documentation":"Thrown by CloudreveV4.refreshToken when there is no stored refresh token and the fallback login() attempt failed. The driver then refuses to proceed because it has no way to obtain credentials. The underlying login error (network failure, wrong password, captcha requirement, 4xx from /session) is embedded in the message.","triggerScenarios":"First use of a Cloudreve v4 storage with username/password configured but wrong credentials; the instance requires a captcha the driver cannot solve; the server is unreachable or returns an error to POST /session; refresh token empty because a previous login never succeeded.","commonSituations":"Typo'd password in the storage config; changed password on the Cloudreve account; Cloudreve instance behind a firewall or with changed URL; site enabled captcha/2FA after initial setup so silent login fails.","solutions":["Verify username/password and the site URL in the storage configuration (the embedded error identifies which step failed)","If the site needs a non-normal captcha, change it in Cloudreve admin or supply a valid token directly","Check network reachability and TLS of the Cloudreve v4 endpoint from the alist host","Re-save the storage to trigger a fresh login after fixing the cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: verify credentials fields are set and endpoint reachable\nif d.Username == \"\" || d.Password == \"\" {\n    return errors.New(\"cloudreve_v4 requires username/password or a refresh token\")\n}","typeGuard":null,"tryCatchPattern":"if err := d.refreshToken(); err != nil {\n    if strings.Contains(err.Error(), \"cannot login to get refresh token\") {\n        // credential/config problem: surface to user, no retry\n        return fmt.Errorf(\"cloudreve login failed, check username/password/url: %w\", err)\n    }\n}","preventionTips":["Store a refresh token alongside credentials to bypass the login path","Alert on login failures immediately rather than retrying silently","Keep the Cloudvre URL and account credentials in sync with the target instance"],"tags":["alist","cloudreve-v4","login","auth","token"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}