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 { pub enum Rels {
Connect1Issuer, Connect1Issuer,
Unsupported, Unsupported,
All,
} }
impl From<String> for Rels { impl From<String> for Rels {
@ -41,6 +42,7 @@ impl Display for Rels {
match self { match self {
Rels::Connect1Issuer => write!(f, "http://openid.net/specs/connect/1.0/issuer"), Rels::Connect1Issuer => write!(f, "http://openid.net/specs/connect/1.0/issuer"),
Rels::Unsupported => write!(f, ""), Rels::Unsupported => write!(f, ""),
Rels::All => write!(f, ""),
} }
} }
} }
@ -89,37 +91,40 @@ impl From<ResourceString> for Resource {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct FingerQuery { pub struct FingerQuery {
resource: Option<String>, resource: Option<String>,
// Todo: rel should allow for multiple values
rel: Option<String>, rel: Option<String>,
} }
pub async fn finger(Query(q): Query<FingerQuery>, Host(host): Host) -> impl IntoResponse { pub async fn finger(Query(q): Query<FingerQuery>, Host(host): Host) -> impl IntoResponse {
let rel = match q.rel { let rel = match q.rel {
Some(x) => Rels::from(x), 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 { let resource = match q.resource {
Some(x) => Resource::from(ResourceString(x)), Some(x) => Resource::from(ResourceString(x)),
None => Resource::Unsupported, None => Resource::Unsupported,
}; };
tracing::warn!("{} - {:?}", rel, resource); tracing::warn!("{:?} - {:?}", rel, resource);
match resource { match resource {
Resource::Acct(subject) => { Resource::Acct(subject) => {
let doc = ResourceDescriptor { let links = match rel {
subject, Rels::Connect1Issuer => vec![DescriptorTypes::Issuer(host).into()],
links: vec![match rel { Rels::All => vec![DescriptorTypes::Issuer(host).into()],
Rels::Connect1Issuer => DescriptorTypes::Issuer(host).into(), Rels::Unsupported => vec![],
Rels::Unsupported => {
return (
StatusCode::NOT_IMPLEMENTED,
"Rel type not supported".to_string(),
)
}
}],
}; };
let doc = ResourceDescriptor { subject, links };
(StatusCode::OK, serde_json::to_string(&doc).unwrap()) (StatusCode::OK, serde_json::to_string(&doc).unwrap())
} }
Resource::Unsupported => ( Resource::Unsupported => (