Backblaze B2
Backblaze B2 Native API requests authorized by an account authorization token. S3-compatible requests, bucket and file upload URL creation, download authorization, and storage operations remain the caller's responsibility.
Inserts the native account authorization token as a sensitive Authorization header. expires_in raises the required credential validity but does not presign URLs; upload URL and download authorization calls stay with the caller.
Get started
cargo add reqsign --features b2
use reqsign::{b2, default_context};
// B2_APPLICATION_KEY_ID and B2_APPLICATION_KEY — resolved by the default chain.
let ctx = default_context();
let signer = b2::default_signer(ctx);
let mut req = http::Request::builder()
.method(http::Method::GET)
.uri("https://api001.backblazeb2.com/b2api/v4/b2_list_buckets?accountId=account-id")
.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 exchanges B2_APPLICATION_KEY_ID and B2_APPLICATION_KEY
for a Native API authorization token with the documented v4
b2_authorize_account endpoint. The credential carries the authorization token,
the Native API and download base URLs, and the earlier of the 24-hour token limit
and the application key expiration timestamp. Signer caches and refreshes it.
Use AccountAuthorizationCredentialProvider for an explicit application key, or
StaticCredentialProvider when the caller already obtained the token and base
URLs. Key capabilities and bucket or prefix restrictions are enforced by B2 and
remain server-side.
The signer covers Native API requests authorized by the account token. Creating upload URLs, requesting download authorization, and using the S3-compatible API remain the caller's 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:
- B2_APPLICATION_KEY_ID and B2_APPLICATION_KEY
Credential providers
Available ProvideCredential implementations. Construct any of them directly, reorder them, or compose them into your own chain — see Loading credentials:
EnvCredentialProvider— B2_APPLICATION_KEY_ID and B2_APPLICATION_KEYStaticCredentialProvider— Static authorization token and Native API endpointsAccountAuthorizationCredentialProvider— Explicit application key