From 9f9c96454d6cfd33ad87c6067a0f9bcc158dab13 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Sat, 18 Nov 2023 19:19:08 +0100 Subject: [PATCH] Webfinger should return all rels if no rel is specified --- src/api/openid/webfinger.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/api/openid/webfinger.rs b/src/api/openid/webfinger.rs index b35cbfc..1e9501e 100644 --- a/src/api/openid/webfinger.rs +++ b/src/api/openid/webfinger.rs @@ -25,6 +25,7 @@ enum DescriptorTypes { pub enum Rels { Connect1Issuer, Unsupported, + All, } impl From for Rels { @@ -41,6 +42,7 @@ impl Display for Rels { match self { Rels::Connect1Issuer => write!(f, "http://openid.net/specs/connect/1.0/issuer"), Rels::Unsupported => write!(f, ""), + Rels::All => write!(f, ""), } } } @@ -89,37 +91,40 @@ impl From for Resource { #[derive(Debug, Deserialize)] pub struct FingerQuery { resource: Option, + // Todo: rel should allow for multiple values rel: Option, } pub async fn finger(Query(q): Query, Host(host): Host) -> impl IntoResponse { let rel = match q.rel { Some(x) => Rels::from(x), - None => Rels::Unsupported, + None => Rels::All, }; + if rel == Rels::Unsupported { + return ( + StatusCode::NOT_IMPLEMENTED, + "Rel type not supported".to_string(), + ); + } + let resource = match q.resource { Some(x) => Resource::from(ResourceString(x)), None => Resource::Unsupported, }; - tracing::warn!("{} - {:?}", rel, resource); + tracing::warn!("{:?} - {:?}", rel, resource); match resource { Resource::Acct(subject) => { - let doc = ResourceDescriptor { - subject, - links: vec![match rel { - Rels::Connect1Issuer => DescriptorTypes::Issuer(host).into(), - Rels::Unsupported => { - return ( - StatusCode::NOT_IMPLEMENTED, - "Rel type not supported".to_string(), - ) - } - }], + let links = match rel { + Rels::Connect1Issuer => vec![DescriptorTypes::Issuer(host).into()], + Rels::All => vec![DescriptorTypes::Issuer(host).into()], + Rels::Unsupported => vec![], }; + let doc = ResourceDescriptor { subject, links }; + (StatusCode::OK, serde_json::to_string(&doc).unwrap()) } Resource::Unsupported => (