Skip to main content

Seafile

Self-hosted Seafile Web API requests authenticated with an account token or repository API token.

Authorization: Token header✓ header signing— query / presign✓ WASMdocs.rs/reqsign-seafile ↗

Inserts a sensitive Authorization: Token header. Configuration-discovered and account-exchange credentials are bound to the deployment scheme, host, effective port, and base path; static credentials remain caller-scoped. Seafile has no query authentication, so expires_in is rejected.

Get started​

cargo add reqsign --features seafile
use reqsign::{default_context, seafile};

// Reads the [account] server and token from ~/.seafile.conf.
let ctx = default_context();
let signer = seafile::default_signer(ctx);

let mut req = http::Request::builder()
.method(http::Method::GET)
.uri("https://files.example.com/api2/repos/")
.body(())?
.into_parts()
.0;

// Sign in place, then send with the HTTP client you already use.
signer.sign(&mut req, None).await?;

The default chain reads server and token from the [account] section of ~/.seafile.conf, the user configuration file read by Seafile's first-party seaf-cli, and binds the credential to that deployment. The server value is required. ConfigFileCredentialProvider::with_account_user can require the [account] user value to match an explicitly selected account. Duplicate [account] sections or repeated parsed keys are rejected. Seafile does not document a standard credential environment variable or login command, so the default chain does not invent one.

Account token exchange​

Use AccountTokenCredentialProvider when the caller has a username and password and wants Reqsign to obtain the account token:

use reqsign::{Context, Signer};
use reqsign_http_send_reqwest::ReqwestHttpSend;
use reqsign_seafile::{AccountTokenCredentialProvider, RequestSigner};
use reqwest::redirect::Policy;

let client = reqwest::Client::builder()
.redirect(Policy::none())
.build()
.expect("client must build");
let ctx = Context::new().with_http_send(ReqwestHttpSend::new(client));
let signer = Signer::new(
ctx,
AccountTokenCredentialProvider::new(
"https://files.example.com/seafile",
"user@example.com",
"password",
),
RequestSigner,
);

This example needs direct dependencies on reqsign (with the seafile feature), reqsign-http-send-reqwest, reqsign-seafile, and reqwest.

The provider posts form-encoded username and password fields to {server}/api2/auth-token/ and reads the token field from the JSON response. The current OpenAPI document describes a JSON request body, but Seafile's server-side example, seaf-cli, and the Python SDK post form fields; this crate follows those executable clients. The server value may include a reverse-proxy base path, which is preserved.

The provider constructs only the initial request to the configured server. The HttpSend adapter owns redirect policy: ReqwestHttpSend::default() follows redirects, so the credential-bearing exchange should use a client with redirects disabled as shown above. Use HTTPS in production; an explicit http:// endpoint sends the login secret in cleartext. Two-factor authentication is not part of this exchange, so use a token obtained separately when the server requires it.

Scope and compatibility​

RequestSigner adds a sensitive Authorization: Token <token> header and leaves the URI and other headers unchanged. Seafile 11 and newer also accept Bearer, but Token works with older self-hosted servers and matches existing OpenDAL behavior. Seafile has no query authentication, so expires_in is rejected.

Credentials discovered from seaf-cli configuration or obtained through the account exchange are bound to the deployment that supplied them. Before adding the header, the signer checks the request scheme, host, effective port, and deployment base path on a segment boundary. A /seafile deployment accepts /seafile and /seafile/... but not /seafile-other; a mismatch fails without changing the request. Scoped signing also rejects a duplicate or conflicting Host header and ambiguous path forms that the HTTP adapter would normalize. Static caller-supplied credentials carry no deployment scope and keep the explicit caller contract. Credential caching preserves the deployment, so every signing call rechecks it.

Repository id discovery, repository-scoped upload and download links, and business request construction remain with the caller. Account and repository API tokens have no documented expiration; Signer caches the token until the signer is recreated or its provider is replaced. Redirect policy after signing remains the caller's adapter responsibility.

Credentials

Default credential chain

The default signer tries these sources in order and uses the first one that yields a credential — no configuration needed when any of them is present:

  1. Seafile CLI user configuration (~/.seafile.conf)

Credential providers

Available ProvideCredential implementations. Construct any of them directly, reorder them, or compose them into your own chain — see Loading credentials: