+6
-54
core/src/main.rs
+6
-54
core/src/main.rs
···
1
1
use std::sync::Arc;
2
-
use tokio::sync::Mutex;
3
2
4
3
use atrium_api::{
5
4
agent::{AtpAgent, store::MemorySessionStore},
6
-
client::AtpServiceClient,
7
5
did_doc::DidDocument,
8
6
types::string::AtIdentifier,
9
-
xrpc::types::AuthorizationToken,
10
7
};
11
8
use atrium_common::resolver::Resolver;
12
9
use atrium_identity::{
13
10
did::{CommonDidResolver, CommonDidResolverConfig, DEFAULT_PLC_DIRECTORY_URL},
14
11
handle::{AtprotoHandleResolver, AtprotoHandleResolverConfig, DnsTxtResolver},
15
12
};
16
-
use atrium_oauth_client::{
17
-
AtprotoClientMetadata, AtprotoLocalhostClientMetadata, AuthorizeOptionPrompt, AuthorizeOptions,
18
-
DefaultHttpClient, DpopClient, KnownScope, OAuthClient, OAuthClientConfig, OAuthResolverConfig,
19
-
Scope, store::state::MemoryStateStore,
20
-
};
13
+
use atrium_oauth_client::DefaultHttpClient;
21
14
use atrium_xrpc::HttpClient;
22
-
use atrium_xrpc_client::isahc::{IsahcClient, IsahcClientBuilder};
15
+
use atrium_xrpc_client::isahc::IsahcClient;
23
16
use axum::{Router, routing};
24
17
use hickory_resolver::TokioAsyncResolver;
25
18
···
45
38
46
39
#[derive(Clone)]
47
40
struct AppState {
48
-
inner: Arc<Mutex<AppStateInner>>,
49
41
did_resolver: Arc<CommonDidResolver<DefaultHttpClient>>,
50
42
handle_resolver: Arc<AtprotoHandleResolver<HickoryDnsTxtResolver, DefaultHttpClient>>,
51
43
}
···
54
46
fn new() -> Self {
55
47
let client = Arc::new(DefaultHttpClient::default());
56
48
Self {
57
-
inner: Arc::new(Mutex::new(AppStateInner::new(client.clone()))),
58
49
did_resolver: Arc::new(did_resolver(client.clone())),
59
50
handle_resolver: Arc::new(handle_resolver(client.clone())),
60
51
}
···
90
81
})
91
82
}
92
83
93
-
struct AppStateInner {
94
-
agent: Option<AtpAgent<MemorySessionStore, IsahcClient>>,
95
-
}
96
-
97
-
impl AppStateInner {
98
-
fn new(http_client: Arc<DefaultHttpClient>) -> Self {
99
-
// let config = OAuthClientConfig {
100
-
// client_metadata: AtprotoLocalhostClientMetadata {
101
-
// // TODO: change this
102
-
// redirect_uris: Some(vec![String::from("http://127.0.0.1:3000/callback")]),
103
-
// scopes: Some(vec![
104
-
// Scope::Known(KnownScope::Atproto),
105
-
// Scope::Known(KnownScope::TransitionGeneric),
106
-
// ]),
107
-
// },
108
-
// keys: None,
109
-
// resolver: OAuthResolverConfig {
110
-
// did_resolver: did_resolver(http_client.clone()),
111
-
// handle_resolver: handle_resolver(http_client.clone()),
112
-
// authorization_server_metadata: Default::default(),
113
-
// protected_resource_metadata: Default::default(),
114
-
// },
115
-
// state_store: MemoryStateStore::default(),
116
-
// };
117
-
// let oauth_client = OAuthClient::new(config).unwrap();
118
-
Self { agent: None }
119
-
}
120
-
}
121
-
122
84
mod login {
123
-
use axum::{
124
-
extract::{Form, State},
125
-
http::StatusCode,
126
-
response::IntoResponse,
127
-
};
85
+
use axum::{extract::Form, http::StatusCode, response::IntoResponse};
128
86
use serde::Deserialize;
129
87
130
88
use super::*;
···
139
97
app_password: String,
140
98
}
141
99
142
-
pub async fn post(
143
-
State(state): State<AppState>,
144
-
session: tower_sessions::Session,
145
-
Form(req): Form<Req>,
146
-
) -> impl IntoResponse {
147
-
let did_document = state.resolve_did_document(&req.handle).await.unwrap();
100
+
pub async fn post(session: tower_sessions::Session, Form(req): Form<Req>) -> impl IntoResponse {
148
101
let agent = AtpAgent::new(
149
-
IsahcClient::new(did_document.get_pds_endpoint().unwrap()),
102
+
IsahcClient::new("https://dummy.example"),
150
103
MemorySessionStore::default(),
151
104
);
152
105
let res = agent.login(req.handle, req.app_password).await.unwrap();
···
169
122
{
170
123
None => "no session",
171
124
Some(s) => {
172
-
// let did_doc = s.did_doc.unwrap();
173
125
let agent = AtpAgent::new(
174
-
IsahcClient::new("https://bsky.social"),
126
+
IsahcClient::new("https://dummy.example"),
175
127
MemorySessionStore::default(),
176
128
);
177
129
println!("resuming session of {:?} ({:?})", s.handle, s.did);