tangled
alpha
login
or
join now
nonbinary.computer
/
weaver
atproto blogging
24
fork
atom
overview
issues
2
pulls
pipelines
some atrium oauth stuff
nonbinary.computer
9 months ago
ed83a3b9
936b0c99
+104
-7
4 changed files
expand all
collapse all
unified
split
Cargo.lock
crates
weaver-common
Cargo.toml
src
lib.rs
oauth.rs
+1
Cargo.lock
···
3398
3398
"atrium-xrpc",
3399
3399
"atrium-xrpc-client",
3400
3400
"esquema-codegen",
3401
3401
+
"hickory-resolver",
3401
3402
"http",
3402
3403
"libsqlite3-sys",
3403
3404
"markdown-weaver",
+8
-5
crates/weaver-common/Cargo.toml
···
11
11
markdown-weaver = { workspace = true }
12
12
libsqlite3-sys = { version = "0.33.0", features = ["bundled"] }
13
13
14
14
-
atrium-api = "0.25.2"
14
14
+
http = "1.3.1"
15
15
+
16
16
+
atrium-xrpc = "0.12.3"
17
17
+
atrium-api = "0.25.3"
15
18
atrium-common = "0.1.1"
16
19
atrium-identity = "0.1.3"
17
20
atrium-oauth = "0.1.1"
···
23
26
serde_json = { version = "1.0.140", features = ["preserve_order", "raw_value"] }
24
27
serde_ipld_dagcbor = { version = "0.6.1", features = ["codec"] }
25
28
serde_cbor = "0.11.2"
29
29
+
serde_html_form = "0.2.7"
30
30
+
serde_bytes = "0.11.17"
26
31
27
32
minijinja = { workspace = true, features = [
28
33
"builtins",
···
40
45
owo-colors = { workspace = true }
41
46
thiserror = { workspace = true }
42
47
tracing = { workspace = true }
48
48
+
hickory-resolver = "0.24.1"
43
49
44
44
-
http = "1.3.1"
45
45
-
serde_html_form = "0.2.7"
46
46
-
serde_bytes = "0.11.17"
47
47
-
atrium-xrpc = "0.12.3"
50
50
+
48
51
49
52
50
53
[dev-dependencies]
+36
-2
crates/weaver-common/src/lib.rs
···
1
1
-
pub use merde::CowStr;
2
2
-
3
1
pub mod error;
4
2
pub mod lexicons;
3
3
+
pub mod oauth;
5
4
pub use lexicons::*;
5
5
+
6
6
+
use atrium_identity::handle::DnsTxtResolver;
6
7
7
8
pub use crate::error::{Error, IoError, ParseError, SerDeError};
9
9
+
10
10
+
/// Canonical Cow for us, thanks Amos
11
11
+
pub use merde::CowStr;
12
12
+
13
13
+
use hickory_resolver::TokioAsyncResolver;
8
14
9
15
/// too many cows, so we have conversions
10
16
pub fn mcow_to_cow(cow: CowStr<'_>) -> std::borrow::Cow<'_, str> {
···
30
36
markdown_weaver::CowStr::Inlined(s) => std::borrow::Cow::Owned(s.as_ref().to_owned()),
31
37
}
32
38
}
39
39
+
40
40
+
pub struct HickoryDnsTxtResolver {
41
41
+
resolver: TokioAsyncResolver,
42
42
+
}
43
43
+
44
44
+
impl Default for HickoryDnsTxtResolver {
45
45
+
fn default() -> Self {
46
46
+
Self {
47
47
+
resolver: TokioAsyncResolver::tokio_from_system_conf()
48
48
+
.expect("failed to create resolver"),
49
49
+
}
50
50
+
}
51
51
+
}
52
52
+
53
53
+
impl DnsTxtResolver for HickoryDnsTxtResolver {
54
54
+
async fn resolve(
55
55
+
&self,
56
56
+
query: &str,
57
57
+
) -> core::result::Result<Vec<String>, Box<dyn std::error::Error + Send + Sync + 'static>> {
58
58
+
Ok(self
59
59
+
.resolver
60
60
+
.txt_lookup(query)
61
61
+
.await?
62
62
+
.iter()
63
63
+
.map(|txt| txt.to_string())
64
64
+
.collect())
65
65
+
}
66
66
+
}
+59
crates/weaver-common/src/oauth.rs
···
1
1
+
use atrium_api::types::string::Did;
2
2
+
use atrium_common::store::memory::MemoryStore;
3
3
+
use atrium_identity::{
4
4
+
did::{CommonDidResolver, CommonDidResolverConfig, DEFAULT_PLC_DIRECTORY_URL},
5
5
+
handle::{AtprotoHandleResolver, AtprotoHandleResolverConfig},
6
6
+
};
7
7
+
use atrium_oauth::{
8
8
+
AtprotoLocalhostClientMetadata, DefaultHttpClient, KnownScope, OAuthClient, OAuthClientConfig,
9
9
+
OAuthResolverConfig, Scope,
10
10
+
store::{
11
11
+
session::{MemorySessionStore, Session},
12
12
+
state::{InternalStateData, MemoryStateStore},
13
13
+
},
14
14
+
};
15
15
+
16
16
+
use std::sync::Arc;
17
17
+
18
18
+
use crate::HickoryDnsTxtResolver;
19
19
+
20
20
+
pub fn default_oauth_client(
21
21
+
url: impl AsRef<str>,
22
22
+
) -> Result<
23
23
+
atrium_oauth::OAuthClient<
24
24
+
MemoryStore<String, InternalStateData>,
25
25
+
MemoryStore<Did, Session>,
26
26
+
CommonDidResolver<DefaultHttpClient>,
27
27
+
AtprotoHandleResolver<HickoryDnsTxtResolver, DefaultHttpClient>,
28
28
+
DefaultHttpClient,
29
29
+
>,
30
30
+
atrium_oauth::Error,
31
31
+
> {
32
32
+
let http_client = Arc::new(atrium_oauth::DefaultHttpClient::default());
33
33
+
let config = OAuthClientConfig {
34
34
+
client_metadata: AtprotoLocalhostClientMetadata {
35
35
+
redirect_uris: Some(vec![url.as_ref().to_string()]),
36
36
+
scopes: Some(vec![
37
37
+
Scope::Known(KnownScope::Atproto),
38
38
+
Scope::Known(KnownScope::TransitionGeneric),
39
39
+
]),
40
40
+
},
41
41
+
keys: None,
42
42
+
resolver: OAuthResolverConfig {
43
43
+
did_resolver: CommonDidResolver::new(CommonDidResolverConfig {
44
44
+
plc_directory_url: DEFAULT_PLC_DIRECTORY_URL.to_string(),
45
45
+
http_client: Arc::clone(&http_client),
46
46
+
}),
47
47
+
handle_resolver: AtprotoHandleResolver::new(AtprotoHandleResolverConfig {
48
48
+
dns_txt_resolver: HickoryDnsTxtResolver::default(),
49
49
+
http_client: Arc::clone(&http_client),
50
50
+
}),
51
51
+
authorization_server_metadata: Default::default(),
52
52
+
protected_resource_metadata: Default::default(),
53
53
+
},
54
54
+
state_store: MemoryStateStore::default(),
55
55
+
session_store: MemorySessionStore::default(),
56
56
+
};
57
57
+
let client = OAuthClient::new(config)?;
58
58
+
Ok(client)
59
59
+
}