Webfinger should return all rels if no rel is specified
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Daan Boerlage 2023-11-18 19:19:08 +01:00
parent 952b16dbb1
commit 9f9c96454d
Signed by: daan
GPG key ID: FCE070E1E4956606

View file

@ -25,6 +25,7 @@ enum DescriptorTypes {
pub enum Rels {
Connect1Issuer,
Unsupported,
All,
}
impl From<String> 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<ResourceString> for Resource {
#[derive(Debug, Deserialize)]
pub struct FingerQuery {
resource: Option<String>,
// Todo: rel should allow for multiple values
rel: Option<String>,
}
pub async fn finger(Query(q): Query<FingerQuery>, 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 => (