AlistGo/alist · error

cannot login to get refresh token, error: %s

Error message

cannot login to get refresh token, error: %s

What it means

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.

Source

Thrown at drivers/cloudreve_v4/util.go:183

	var token TokenResponse
	err = d.request(http.MethodPost, "/session/token", func(req *resty.Request) {
		req.SetBody(loginBody)
	}, &token)
	if err != nil {
		return err
	}
	d.AccessToken, d.RefreshToken = token.Token.AccessToken, token.Token.RefreshToken
	op.MustSaveDriverStorage(d)
	return nil
}

func (d *CloudreveV4) refreshToken() error {
	var token Token
	if token.RefreshToken == "" {
		if d.Username != "" {
			err := d.login()
			if err != nil {
				return fmt.Errorf("cannot login to get refresh token, error: %s", err)
			}
		}
		return nil
	}
	err := d.request(http.MethodPost, "/session/token/refresh", func(req *resty.Request) {
		req.SetBody(base.Json{
			"refresh_token": d.RefreshToken,
		})
	}, &token)
	if err != nil {
		return err
	}
	d.AccessToken, d.RefreshToken = token.AccessToken, token.RefreshToken
	op.MustSaveDriverStorage(d)
	return nil
}

func (d *CloudreveV4) upLocal(ctx context.Context, file model.FileStreamer, u FileUploadResp, up driver.UpdateProgress) error {

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Verify username/password and the site URL in the storage configuration (the embedded error identifies which step failed)
  2. If the site needs a non-normal captcha, change it in Cloudreve admin or supply a valid token directly
  3. Check network reachability and TLS of the Cloudreve v4 endpoint from the alist host
  4. Re-save the storage to trigger a fresh login after fixing the cause
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: verify credentials fields are set and endpoint reachable
if d.Username == "" || d.Password == "" {
    return errors.New("cloudreve_v4 requires username/password or a refresh token")
}

Try / catch

if err := d.refreshToken(); err != nil {
    if strings.Contains(err.Error(), "cannot login to get refresh token") {
        // credential/config problem: surface to user, no retry
        return fmt.Errorf("cloudreve login failed, check username/password/url: %w", err)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/4088b52eadda1493. Report an issue: GitHub.