NextcloudClient constructor

NextcloudClient(
  1. Uri baseURL, {
  2. String? loginName,
  3. String? password,
  4. String? appPassword,
  5. String? userAgent,
  6. Client? httpClient,
  7. CookieJar? cookieJar,
})

Creates a new Nextcloud API client.

baseURL has to point to the Nextcloud server webroot.

To access authenticated endpoints loginName and one of password or appPassword have to be set. Note that not all endpoints can be access by using only the password, so it is preferred to set the appPassword instead. loginName can be any user identifier like the username or the e-mail.

It is good practice to set the userAgent to allow server admins to identify clients. A custom HTTP client can be provided through httpClient. Additionally a cookieJar can be specified to save cookies across requests. Some endpoints require the use of a cookies persistence.

Implementation

NextcloudClient(
  super.baseURL, {
  String? loginName,
  String? password,
  String? appPassword,
  String? userAgent,
  http.Client? httpClient,
  cookie_jar.CookieJar? cookieJar,
}) : super(
        httpClient: CookieJarClient(
          httpClient: httpClient,
          cookieJar: cookieJar,
          baseHeaders: {
            if (userAgent != null) HttpHeaders.userAgentHeader: userAgent,
          },
        ),
        authentications: [
          if (appPassword != null)
            DynamiteHttpBearerAuthentication(
              token: appPassword,
            ),
          if (loginName != null && (password ?? appPassword) != null)
            DynamiteHttpBasicAuthentication(
              username: loginName,
              password: (password ?? appPassword)!,
            ),
        ],
      );