CLI tool for migrating PDS
1use atrium_api::{
2 agent::SessionManager,
3 types::string::Did,
4 xrpc::{
5 http::{Request, Response},
6 types::AuthorizationToken,
7 HttpClient, XrpcClient,
8 },
9};
10use atrium_xrpc_client::reqwest::ReqwestClient;
11
12pub struct JwtSessionManager {
13 did: Did,
14 token: String,
15 inner: ReqwestClient,
16}
17
18impl JwtSessionManager {
19 pub fn new(did: Did, token: String, base_uri: impl AsRef<str>) -> Self {
20 Self {
21 did,
22 token,
23 inner: ReqwestClient::new(base_uri),
24 }
25 }
26}
27
28impl HttpClient for JwtSessionManager {
29 async fn send_http(
30 &self,
31 request: Request<Vec<u8>>,
32 ) -> Result<Response<Vec<u8>>, Box<dyn std::error::Error + Send + Sync + 'static>> {
33 self.inner.send_http(request).await
34 }
35}
36
37impl XrpcClient for JwtSessionManager {
38 fn base_uri(&self) -> String {
39 self.inner.base_uri()
40 }
41
42 async fn authorization_token(&self, _: bool) -> Option<AuthorizationToken> {
43 Some(AuthorizationToken::Bearer(self.token.clone()))
44 }
45}
46
47impl SessionManager for JwtSessionManager {
48 async fn did(&self) -> Option<Did> {
49 Some(self.did.clone())
50 }
51}