Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan committed Jan 15, 2025
1 parent f00b866 commit 26f1d04
Show file tree
Hide file tree
Showing 12 changed files with 588 additions and 79 deletions.
22 changes: 12 additions & 10 deletions atrium-api/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ pub trait AuthorizationProvider {
}

pub trait Configure {
/// Set the current endpoint.
fn configure_endpoint(&self, endpoint: String);
/// Configures the moderation services to be applied on requests.
fn configure_labelers_header(&self, labeler_dids: Option<Vec<(Did, bool)>>);
/// Configures the atproto-proxy header to be applied on requests.
fn configure_proxy_header(&self, did: Did, service_type: impl AsRef<str>);
}

Expand Down Expand Up @@ -94,15 +97,12 @@ impl<M> Configure for Agent<M>
where
M: Configure + SessionManager + Send + Sync,
{
/// Set the current endpoint.
fn configure_endpoint(&self, endpoint: String) {
self.session_manager.configure_endpoint(endpoint);
}
/// Configures the moderation services to be applied on requests.
fn configure_labelers_header(&self, labeler_dids: Option<Vec<(Did, bool)>>) {
self.session_manager.configure_labelers_header(labeler_dids);
}
/// Configures the atproto-proxy header to be applied on requests.
fn configure_proxy_header(&self, did: Did, service_type: impl AsRef<str>) {
self.session_manager.configure_proxy_header(did, service_type);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ where
impl<S, T, U> XrpcClient for WrapperClient<S, T, U>
where
S: Store<(), U> + AuthorizationProvider + Send + Sync,
T: XrpcClient + Send + Sync,
T: HttpClient + Send + Sync,
U: Clone + Send + Sync,
{
fn base_uri(&self) -> String {
Expand Down Expand Up @@ -499,7 +499,7 @@ mod tests {
// labeler service
{
agent.configure_proxy_header(
Did::new(String::from("did:fake:service.test")).expect("did should be valid"),
Did::new(String::from("did:fake:service.test"))?,
AtprotoServiceType::AtprotoLabeler,
);
call_service(&agent.api).await?;
Expand All @@ -514,7 +514,7 @@ mod tests {
// custom service
{
agent.configure_proxy_header(
Did::new(String::from("did:fake:service.test")).expect("did should be valid"),
Did::new(String::from("did:fake:service.test"))?,
"custom_service",
);
call_service(&agent.api).await?;
Expand All @@ -528,10 +528,12 @@ mod tests {
}
// api_with_proxy
{
call_service(&agent.api_with_proxy(
Did::new(String::from("did:fake:service.test")).expect("did should be valid"),
"temp_service",
))
call_service(
&agent.api_with_proxy(
Did::new(String::from("did:fake:service.test"))?,
"temp_service",
),
)
.await?;
assert_eq!(
data.lock().await.as_ref().expect("data should be recorded").headers,
Expand Down
3 changes: 1 addition & 2 deletions atrium-oauth/identity/src/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ mod common_resolver;
mod plc_resolver;
mod web_resolver;

use crate::Error;

pub use self::common_resolver::{CommonDidResolver, CommonDidResolverConfig};
pub use self::plc_resolver::DEFAULT_PLC_DIRECTORY_URL;
use crate::Error;
use atrium_api::did_doc::DidDocument;
use atrium_api::types::string::Did;
use atrium_common::resolver::Resolver;
Expand Down
4 changes: 2 additions & 2 deletions atrium-oauth/oauth-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["atproto", "bluesky", "oauth"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
atrium-api.workspace = true
atrium-api = { workspace = true, features = ["agent"] }
atrium-common.workspace = true
atrium-identity.workspace = true
atrium-xrpc.workspace = true
Expand All @@ -37,7 +37,7 @@ trait-variant.workspace = true
[dev-dependencies]
atrium-api = { workspace = true, features = ["bluesky"] }
hickory-resolver.workspace = true
p256 = { workspace = true, features = ["pem"] }
p256 = { workspace = true, features = ["pem", "std"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[features]
Expand Down
28 changes: 28 additions & 0 deletions atrium-oauth/oauth-client/examples/generate_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use elliptic_curve::pkcs8::EncodePrivateKey;
use elliptic_curve::SecretKey;
use jose_jwa::{Algorithm, Signing};
use jose_jwk::{Class, Jwk, JwkSet, Key, Parameters};
use p256::NistP256;
use rand::rngs::ThreadRng;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let secret_key = SecretKey::<NistP256>::random(&mut ThreadRng::default());
let key = Key::from(&secret_key.public_key().into());
let jwks = JwkSet {
keys: vec![Jwk {
key,
prm: Parameters {
alg: Some(Algorithm::Signing(Signing::Es256)),
kid: Some(String::from("kid01")),
cls: Some(Class::Signing),
..Default::default()
},
}],
};
println!("SECRET KEY:");
println!("{}", secret_key.to_pkcs8_pem(Default::default())?.as_str());

println!("JWKS:");
println!("{}", serde_json::to_string_pretty(&jwks)?);
Ok(())
}
11 changes: 11 additions & 0 deletions atrium-oauth/oauth-client/src/http_client/dpop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,14 @@ where
Ok(response)
}
}

impl<T> Clone for DpopClient<T> {
fn clone(&self) -> Self {
Self {
inner: Arc::clone(&self.inner),
key: self.key.clone(),
nonces: self.nonces.clone(),
is_auth_server: self.is_auth_server,
}
}
}
Loading

0 comments on commit 26f1d04

Please sign in to comment.