actpub-webfinger 0.2.1

WebFinger (RFC 7033) client and server primitives for ActivityPub.
Documentation

WebFinger (RFC 7033) primitives for ActivityPub account discovery.

WebFinger is the discovery mechanism used across the Fediverse to map acct:user@host identifiers to ActivityPub actor URLs via a /.well-known/webfinger endpoint returning a JSON Resource Descriptor (JRD).

Example (client)

# #[cfg(feature = "client")]
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use actpub_webfinger::{Account, resolve};

let client = reqwest::Client::new();
let account = Account::parse("acct:gargron@mastodon.social")?;
let jrd = resolve(&account, &client).await?;

if let Some(link) = jrd.activitypub_actor() {
    println!("Actor URL: {}", link.href.as_ref().unwrap());
}
# Ok(()) }

Example (server)

use actpub_webfinger::{Jrd, JrdLink, rels};

let jrd = Jrd::builder("acct:alice@example.com")
    .alias("https://example.com/@alice")
    .link(
        JrdLink::builder(rels::ACTIVITYPUB_ACTOR)
            .href("https://example.com/users/alice".parse().unwrap())
            .media_type("application/activity+json")
            .build(),
    )
    .build();

let json = serde_json::to_string(&jrd).unwrap();
assert!(json.contains(r#""subject":"acct:alice@example.com""#));