Skip to main content

Module webfinger

Module webfinger 

Source
Expand description

WebFinger (RFC 7033), the successor that honours finger by name.

Where finger returned whatever text a host felt like printing, WebFinger returns a JSON Resource Descriptor: a subject, its aliases, and a list of typed links. It is what resolves @alice@example.social on the fediverse, and it is the discovery step in OpenID Connect.

§What this module does and does not do

WebFinger rides on HTTPS, and this crate does not contain an HTTP client. It implements the two spec-shaped halves and leaves the GET to the caller, who almost certainly has an HTTP stack already:

  • request_url builds the well-known URI, with the resource and any rel filters correctly encoded;
  • parse reads the JRD that comes back.

Perform the request with Accept: application/jrd+json (MEDIA_TYPE).

use finger_protocol::webfinger::{acct, request_url, parse};

let url = request_url("example.social", &acct("alice", "example.social"), &["self"]);
assert_eq!(
    url,
    "https://example.social/.well-known/webfinger\
     ?resource=acct%3Aalice%40example.social&rel=self"
);

// ... GET that URL, then:
let jrd = parse(r#"{"subject":"acct:alice@example.social",
    "links":[{"rel":"self","type":"application/activity+json",
              "href":"https://example.social/users/alice"}]}"#).unwrap();
assert_eq!(jrd.link("self").unwrap().href.as_deref(),
           Some("https://example.social/users/alice"));

Structs§

Jrd
A JSON Resource Descriptor: WebFinger’s answer.
Link
One link relation in a Jrd.

Constants§

MEDIA_TYPE
The media type of a JRD document, for the request’s Accept header.
WELL_KNOWN_PATH
The path every WebFinger query is served from.

Functions§

acct
Build an acct: URI (RFC 7565), the usual way to name a person.
parse
Parse a JRD document.
request_url
Build the WebFinger request URL for a resource at a host.