A library for ATProtocol identities.

feature: post_dpop_bytes_with_headers

Changed files
+54
crates
atproto-client
src
+54
crates/atproto-client/src/client.rs
··· 397 397 Ok(value) 398 398 } 399 399 400 + 401 + pub async fn post_dpop_bytes_with_headers( 402 + http_client: &reqwest::Client, 403 + dpop_auth: &DPoPAuth, 404 + url: &str, 405 + payload: Bytes, 406 + additional_headers: &HeaderMap, 407 + ) -> Result<serde_json::Value> { 408 + let (dpop_proof_token, dpop_proof_header, dpop_proof_claim) = request_dpop( 409 + &dpop_auth.dpop_private_key_data, 410 + "POST", 411 + url, 412 + &dpop_auth.oauth_access_token, 413 + ) 414 + .map_err(|error| DPoPError::ProofGenerationFailed { error })?; 415 + 416 + let dpop_retry = DpopRetry::new( 417 + dpop_proof_header.clone(), 418 + dpop_proof_claim.clone(), 419 + dpop_auth.dpop_private_key_data.clone(), 420 + true, 421 + ); 422 + 423 + let dpop_retry_client = ClientBuilder::new(http_client.clone()) 424 + .with(ChainMiddleware::new(dpop_retry.clone())) 425 + .build(); 426 + 427 + let http_response = dpop_retry_client 428 + .post(url) 429 + .headers(additional_headers.clone()) 430 + .header( 431 + "Authorization", 432 + &format!("DPoP {}", dpop_auth.oauth_access_token), 433 + ) 434 + .header("DPoP", &dpop_proof_token) 435 + .body(payload) 436 + .send() 437 + .await 438 + .map_err(|error| DPoPError::HttpRequestFailed { 439 + url: url.to_string(), 440 + error, 441 + })?; 442 + 443 + let value = http_response 444 + .json::<serde_json::Value>() 445 + .await 446 + .map_err(|error| DPoPError::JsonParseFailed { 447 + url: url.to_string(), 448 + error, 449 + })?; 450 + 451 + Ok(value) 452 + } 453 + 400 454 /// Performs an unauthenticated HTTP POST request with JSON body and parses the response as JSON. 401 455 /// 402 456 /// # Arguments