Skip to content

Commit

Permalink
feat: Make XrpcClient::auth asynchronous (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan authored Nov 12, 2023
1 parent 43f7d81 commit 675a614
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions atrium-xrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub type XrpcResult<O, E> = Result<OutputDataOrBytes<O>, self::Error<E>>;
pub trait XrpcClient: HttpClient {
fn base_uri(&self) -> &str;
#[allow(unused_variables)]
fn auth(&self, is_refresh: bool) -> Option<String> {
async fn auth(&self, is_refresh: bool) -> Option<String> {
None
}
async fn send_xrpc<P, I, O, E>(&self, request: &XrpcRequest<P, I>) -> XrpcResult<O, E>
Expand All @@ -80,9 +80,13 @@ pub trait XrpcClient: HttpClient {
if let Some(encoding) = &request.encoding {
builder = builder.header(http::header::CONTENT_TYPE, encoding);
}
if let Some(token) = self.auth(
request.method == Method::POST && request.path == "com.atproto.server.refreshSession",
) {
if let Some(token) = self
.auth(
request.method == Method::POST
&& request.path == "com.atproto.server.refreshSession",
)
.await
{
builder = builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token));
}
let body = if let Some(input) = &request.input {
Expand Down

0 comments on commit 675a614

Please sign in to comment.