Compare commits
No commits in common. "da7566b2d09585fe6b1b60ce2a792dbfdba2892e" and "6d412cd511896359bd8c45cf9f6fcf7e201c49f3" have entirely different histories.
da7566b2d0
...
6d412cd511
|
@ -10,15 +10,10 @@ use once_cell::sync::Lazy;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
static ACCT: Lazy<String> = Lazy::new(|| format!("blog@{}", *DOMAIN));
|
||||
const OIDC_SUBJECT: &'static str = "me@shadowfacts.net";
|
||||
|
||||
pub async fn handle(req: Request<Body>) -> Response {
|
||||
let resource = resource(req).await;
|
||||
if resource.as_deref() == Some(&*ACCT) {
|
||||
Json(WebfingerResponse::blog()).into_response()
|
||||
} else if resource.as_deref() == Some(&OIDC_SUBJECT) {
|
||||
// used for tailscale OIDC
|
||||
Json(WebfingerResponse::oidc()).into_response()
|
||||
if is_resource_blog(req).await {
|
||||
Json(WebfingerResponse::new()).into_response()
|
||||
} else {
|
||||
// mastodon responds with 400 and an empty body, so we do too
|
||||
StatusCode::BAD_REQUEST.into_response()
|
||||
|
@ -48,16 +43,18 @@ pub async fn handle_interact(
|
|||
.into_response()
|
||||
}
|
||||
|
||||
async fn resource(req: Request<Body>) -> Option<String> {
|
||||
async fn is_resource_blog(req: Request<Body>) -> bool {
|
||||
let mut parts = RequestParts::new(req);
|
||||
let params = parts.extract::<Query<Params>>().await;
|
||||
params.ok().map(|Query(params)| {
|
||||
if params.resource.starts_with("acct:") {
|
||||
params.resource[5..].into()
|
||||
if let Ok(Query(params)) = parts.extract::<Query<Params>>().await {
|
||||
let resource = if params.resource.starts_with("acct:") {
|
||||
¶ms.resource[5..]
|
||||
} else {
|
||||
params.resource
|
||||
¶ms.resource
|
||||
};
|
||||
resource == ACCT.as_str()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async fn query(acct: &str) -> anyhow::Result<WebfingerResponse> {
|
||||
|
@ -92,7 +89,7 @@ pub struct WebfingerResponse {
|
|||
}
|
||||
|
||||
impl WebfingerResponse {
|
||||
fn blog() -> Self {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
subject: ACCT.to_owned(),
|
||||
links: vec![Link {
|
||||
|
@ -104,18 +101,6 @@ impl WebfingerResponse {
|
|||
}],
|
||||
}
|
||||
}
|
||||
|
||||
fn oidc() -> Self {
|
||||
Self {
|
||||
subject: OIDC_SUBJECT.to_owned(),
|
||||
links: vec![Link {
|
||||
rel: "http://openid.net/specs/connect/1.0/issuer".to_owned(),
|
||||
payload: LinkPayload::Href {
|
||||
href: "https://auth.shadowfacts.net/application/o/tailscale/".to_owned(),
|
||||
},
|
||||
}],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -130,7 +115,6 @@ pub struct Link {
|
|||
pub enum LinkPayload {
|
||||
Webfinger { r#type: String, href: String },
|
||||
OStatusSubscribe { template: String },
|
||||
Href { href: String },
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -166,11 +166,7 @@ async fn serve(posts: &[Post<HtmlContent>], pool: SqlitePool) {
|
|||
.fallback(get_service(articles_or_fallback))
|
||||
.layer(Extension(pool));
|
||||
|
||||
let addr = if cfg!(debug_assertions) {
|
||||
SocketAddr::from(([0, 0, 0, 0], 8084))
|
||||
} else {
|
||||
SocketAddr::from(([127, 0, 0, 1], 8084))
|
||||
};
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 8084));
|
||||
info!("Listening on {}", addr);
|
||||
axum::Server::bind(&addr)
|
||||
.serve(app.into_make_service())
|
||||
|
|
Loading…
Reference in New Issue