some atrium oauth stuff

+104 -7
+1
Cargo.lock
··· 3398 3398 "atrium-xrpc", 3399 3399 "atrium-xrpc-client", 3400 3400 "esquema-codegen", 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 - atrium-api = "0.25.2" 14 + http = "1.3.1" 15 + 16 + atrium-xrpc = "0.12.3" 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 + serde_html_form = "0.2.7" 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 + hickory-resolver = "0.24.1" 43 49 44 - http = "1.3.1" 45 - serde_html_form = "0.2.7" 46 - serde_bytes = "0.11.17" 47 - atrium-xrpc = "0.12.3" 50 + 48 51 49 52 50 53 [dev-dependencies]
+36 -2
crates/weaver-common/src/lib.rs
··· 1 - pub use merde::CowStr; 2 - 3 1 pub mod error; 4 2 pub mod lexicons; 3 + pub mod oauth; 5 4 pub use lexicons::*; 5 + 6 + use atrium_identity::handle::DnsTxtResolver; 6 7 7 8 pub use crate::error::{Error, IoError, ParseError, SerDeError}; 9 + 10 + /// Canonical Cow for us, thanks Amos 11 + pub use merde::CowStr; 12 + 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 + 40 + pub struct HickoryDnsTxtResolver { 41 + resolver: TokioAsyncResolver, 42 + } 43 + 44 + impl Default for HickoryDnsTxtResolver { 45 + fn default() -> Self { 46 + Self { 47 + resolver: TokioAsyncResolver::tokio_from_system_conf() 48 + .expect("failed to create resolver"), 49 + } 50 + } 51 + } 52 + 53 + impl DnsTxtResolver for HickoryDnsTxtResolver { 54 + async fn resolve( 55 + &self, 56 + query: &str, 57 + ) -> core::result::Result<Vec<String>, Box<dyn std::error::Error + Send + Sync + 'static>> { 58 + Ok(self 59 + .resolver 60 + .txt_lookup(query) 61 + .await? 62 + .iter() 63 + .map(|txt| txt.to_string()) 64 + .collect()) 65 + } 66 + }
+59
crates/weaver-common/src/oauth.rs
··· 1 + use atrium_api::types::string::Did; 2 + use atrium_common::store::memory::MemoryStore; 3 + use atrium_identity::{ 4 + did::{CommonDidResolver, CommonDidResolverConfig, DEFAULT_PLC_DIRECTORY_URL}, 5 + handle::{AtprotoHandleResolver, AtprotoHandleResolverConfig}, 6 + }; 7 + use atrium_oauth::{ 8 + AtprotoLocalhostClientMetadata, DefaultHttpClient, KnownScope, OAuthClient, OAuthClientConfig, 9 + OAuthResolverConfig, Scope, 10 + store::{ 11 + session::{MemorySessionStore, Session}, 12 + state::{InternalStateData, MemoryStateStore}, 13 + }, 14 + }; 15 + 16 + use std::sync::Arc; 17 + 18 + use crate::HickoryDnsTxtResolver; 19 + 20 + pub fn default_oauth_client( 21 + url: impl AsRef<str>, 22 + ) -> Result< 23 + atrium_oauth::OAuthClient< 24 + MemoryStore<String, InternalStateData>, 25 + MemoryStore<Did, Session>, 26 + CommonDidResolver<DefaultHttpClient>, 27 + AtprotoHandleResolver<HickoryDnsTxtResolver, DefaultHttpClient>, 28 + DefaultHttpClient, 29 + >, 30 + atrium_oauth::Error, 31 + > { 32 + let http_client = Arc::new(atrium_oauth::DefaultHttpClient::default()); 33 + let config = OAuthClientConfig { 34 + client_metadata: AtprotoLocalhostClientMetadata { 35 + redirect_uris: Some(vec![url.as_ref().to_string()]), 36 + scopes: Some(vec![ 37 + Scope::Known(KnownScope::Atproto), 38 + Scope::Known(KnownScope::TransitionGeneric), 39 + ]), 40 + }, 41 + keys: None, 42 + resolver: OAuthResolverConfig { 43 + did_resolver: CommonDidResolver::new(CommonDidResolverConfig { 44 + plc_directory_url: DEFAULT_PLC_DIRECTORY_URL.to_string(), 45 + http_client: Arc::clone(&http_client), 46 + }), 47 + handle_resolver: AtprotoHandleResolver::new(AtprotoHandleResolverConfig { 48 + dns_txt_resolver: HickoryDnsTxtResolver::default(), 49 + http_client: Arc::clone(&http_client), 50 + }), 51 + authorization_server_metadata: Default::default(), 52 + protected_resource_metadata: Default::default(), 53 + }, 54 + state_store: MemoryStateStore::default(), 55 + session_store: MemorySessionStore::default(), 56 + }; 57 + let client = OAuthClient::new(config)?; 58 + Ok(client) 59 + }