1
- use crate :: error:: Error ;
2
- use crate :: error:: { XrpcError , XrpcErrorKind } ;
3
- use crate :: types:: { Header , NSID_REFRESH_SESSION } ;
1
+ use crate :: error:: { Error , XrpcError , XrpcErrorKind } ;
2
+ use crate :: types:: { AuthorizationToken , Header , NSID_REFRESH_SESSION } ;
4
3
use crate :: { InputDataOrBytes , OutputDataOrBytes , XrpcRequest } ;
5
4
use http:: { Method , Request , Response } ;
6
5
use serde:: { de:: DeserializeOwned , Serialize } ;
7
- use std:: fmt:: Debug ;
8
- use std:: future:: Future ;
6
+ use std:: { fmt:: Debug , future:: Future } ;
9
7
10
8
/// An abstract HTTP client.
11
9
#[ cfg_attr( not( target_arch = "wasm32" ) , trait_variant:: make( Send ) ) ]
@@ -32,9 +30,12 @@ type XrpcResult<O, E> = core::result::Result<OutputDataOrBytes<O>, self::Error<E
32
30
pub trait XrpcClient : HttpClient {
33
31
/// The base URI of the XRPC server.
34
32
fn base_uri ( & self ) -> String ;
35
- /// Get the authentication token to use `Authorization` header.
33
+ /// Get the authorization token to use `Authorization` header.
36
34
#[ allow( unused_variables) ]
37
- fn authentication_token ( & self , is_refresh : bool ) -> impl Future < Output = Option < String > > {
35
+ fn authorization_token (
36
+ & self ,
37
+ is_refresh : bool ,
38
+ ) -> impl Future < Output = Option < AuthorizationToken > > {
38
39
async { None }
39
40
}
40
41
/// Get the `atproto-proxy` header.
@@ -102,12 +103,10 @@ where
102
103
builder = builder. header ( Header :: ContentType , encoding) ;
103
104
}
104
105
if let Some ( token) = client
105
- . authentication_token (
106
- request. method == Method :: POST && request. nsid == NSID_REFRESH_SESSION ,
107
- )
106
+ . authorization_token ( request. method == Method :: POST && request. nsid == NSID_REFRESH_SESSION )
108
107
. await
109
108
{
110
- builder = builder. header ( Header :: Authorization , format ! ( "Bearer {}" , token) ) ;
109
+ builder = builder. header ( Header :: Authorization , token) ;
111
110
}
112
111
if let Some ( proxy) = client. atproto_proxy_header ( ) . await {
113
112
builder = builder. header ( Header :: AtprotoProxy , proxy) ;
0 commit comments