Router, Add wellknow, fix compile errors
This commit is contained in:
parent
ee99f119f0
commit
031faf7db1
8 changed files with 71 additions and 58 deletions
1
router/src/wellknown/atproto.rs
Normal file
1
router/src/wellknown/atproto.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod handle_resolution;
|
||||
52
router/src/wellknown/atproto/handle_resolution.rs
Normal file
52
router/src/wellknown/atproto/handle_resolution.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use crate::{
|
||||
wellknown::WellKnownEndpoint,
|
||||
Error,
|
||||
};
|
||||
use atproto::types::{Handle, Did};
|
||||
use axum::{
|
||||
routing::{
|
||||
method_routing::MethodRouter,
|
||||
get,
|
||||
},
|
||||
http::{
|
||||
StatusCode,
|
||||
HeaderMap,
|
||||
},
|
||||
};
|
||||
|
||||
pub struct HandleResolutionEndpoint {
|
||||
resolver: MethodRouter,
|
||||
}
|
||||
|
||||
impl HandleResolutionEndpoint {
|
||||
pub fn new<HR>(handle_resolver: HR) -> Self where
|
||||
HR: HandleResolver + Clone
|
||||
{
|
||||
HandleResolutionEndpoint {
|
||||
resolver: get(async move | headers: HeaderMap | -> (StatusCode, String) {
|
||||
let Some(Ok(hostname)) = headers.get("host").map(|header_value| {
|
||||
header_value.to_str()
|
||||
}) else {
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, String::from("Internal Server Error"));
|
||||
};
|
||||
let Ok(valid_handle) = hostname.parse::<atproto::types::Handle>() else {
|
||||
return (StatusCode::NOT_FOUND, String::from("User not found"));
|
||||
};
|
||||
match handle_resolver.call(valid_handle) {
|
||||
Ok(Some(did)) => (StatusCode::OK, did.to_string()),
|
||||
Ok(None) => (StatusCode::NOT_FOUND, String::from("User not found")),
|
||||
Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, String::from("Internal Server Error")),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HandleResolver: Send + Sync + 'static {
|
||||
fn call(&self, handle: Handle) -> Result<Option<Did>, Error>;
|
||||
}
|
||||
|
||||
impl WellKnownEndpoint for HandleResolutionEndpoint {
|
||||
fn get_known_route(&self) -> String { String::from("atproto-did") }
|
||||
fn get_resolver(self) -> MethodRouter { self.resolver }
|
||||
}
|
||||
1
router/src/wellknown/oauth.rs
Normal file
1
router/src/wellknown/oauth.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod authorization_server;
|
||||
2
router/src/wellknown/oauth/authorization_server.rs
Normal file
2
router/src/wellknown/oauth/authorization_server.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue