Accept webfinger requests where resource is actor ID

This commit is contained in:
silverpill 2023-01-05 18:30:00 +00:00
parent 48de6218eb
commit 143e6c2417
2 changed files with 15 additions and 4 deletions

View file

@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added `/api/v1/settings/move_followers` API endpoint (replaces `/api/v1/accounts/move_followers`). - Added `/api/v1/settings/move_followers` API endpoint (replaces `/api/v1/accounts/move_followers`).
- Added `/api/v1/settings/import_follows` API endpoint. - Added `/api/v1/settings/import_follows` API endpoint.
- Validation of Monero subscription payout address. - Validation of Monero subscription payout address.
- Accept webfinger requests where `resource` is actor ID.
### Removed ### Removed

View file

@ -5,6 +5,7 @@ use crate::activitypub::constants::AP_MEDIA_TYPE;
use crate::activitypub::identifiers::{ use crate::activitypub::identifiers::{
local_actor_id, local_actor_id,
local_instance_actor_id, local_instance_actor_id,
parse_local_actor_id,
}; };
use crate::config::{Config, Instance}; use crate::config::{Config, Instance};
use crate::database::{get_database_client, DbPool}; use crate::database::{get_database_client, DbPool};
@ -31,12 +32,21 @@ async fn get_jrd(
instance: Instance, instance: Instance,
resource: &str, resource: &str,
) -> Result<JsonResourceDescriptor, HttpError> { ) -> Result<JsonResourceDescriptor, HttpError> {
let actor_address = parse_acct_uri(resource)?; let actor_address = if resource.starts_with("acct:") {
parse_acct_uri(resource)?
} else {
// Actor ID? (reverse webfinger)
let username = parse_local_actor_id(
&instance.url(),
resource,
)?;
ActorAddress { username, hostname: instance.hostname() }
};
if actor_address.hostname != instance.hostname() { if actor_address.hostname != instance.hostname() {
// Wrong instance // Wrong instance
return Err(HttpError::NotFoundError("user")); return Err(HttpError::NotFoundError("user"));
}; };
let actor_url = if actor_address.username == instance.hostname() { let actor_id = if actor_address.username == instance.hostname() {
local_instance_actor_id(&instance.url()) local_instance_actor_id(&instance.url())
} else { } else {
if !is_registered_user(db_client, &actor_address.username).await? { if !is_registered_user(db_client, &actor_address.username).await? {
@ -47,10 +57,10 @@ async fn get_jrd(
let link = Link { let link = Link {
rel: "self".to_string(), rel: "self".to_string(),
link_type: Some(AP_MEDIA_TYPE.to_string()), link_type: Some(AP_MEDIA_TYPE.to_string()),
href: Some(actor_url), href: Some(actor_id),
}; };
let jrd = JsonResourceDescriptor { let jrd = JsonResourceDescriptor {
subject: resource.to_string(), subject: format!("acct:{}", actor_address),
links: vec![link], links: vec![link],
}; };
Ok(jrd) Ok(jrd)