Unverified Commit 5d90f7d1 authored by Hong Minhee's avatar Hong Minhee
Browse files

Add avatar links to WebFinger response

parent 6769fd7a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ To be released.
     -  Added `attachSignature()` function.
     -  Added `detachSignature()` function.

 -  WebFinger responses now include <http://webfinger.net/rel/avatar> links
    if the `Actor` object returned by the actor dispatcher has `icon`/`icons`
    property.

 -  The `fedify inbox` command now sends `Delete(Application)` activities when
    it's terminated so that the peers can clean up data related to the temporary
    actor.  [[#135]]
+29 −0
Original line number Diff line number Diff line
@@ -410,3 +410,32 @@ network, because changing the WebFinger username does not affect the actor URI.
> We highly recommend you to set the actor's `preferredUsername` property to
> the corresponding WebFinger username so that peers can find the actor's
> fediverse handle by fetching the actor object.


WebFinger links
---------------

Some properties of an `Actor` returned by the actor dispatcher affect
responses to WebFinger requests.

### `preferredUsername`

*This API is available since Fedify 0.15.0.*

The `preferredUsername` property is the bare handle of the actor.  It is
used as the WebFinger username, used in the `acct:` URI of the `aliases`
property of the WebFinger response.

### `url`

The `url` property usually refers to the actor's profile page.  It is
used as the `links` property of the WebFinger response, with the `rel`
property set to <http://webfinger.net/rel/profile-page>.

### `icon`

*This API is available since Fedify 1.0.0.*

The `icon` property is an `Image` object that represents the actor's
icon (i.e., avatar).  It is used as the `links` property of the WebFinger
response, with the `rel` property set to <http://webfinger.net/rel/avatar>.
+15 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import type {
import { createRequestContext } from "../testing/context.ts";
import { test } from "../testing/mod.ts";
import type { Actor } from "../vocab/actor.ts";
import { Link, Person } from "../vocab/vocab.ts";
import { Image, Link, Person } from "../vocab/vocab.ts";
import { handleWebFinger } from "./handler.ts";

test("handleWebFinger()", async () => {
@@ -35,6 +35,10 @@ test("handleWebFinger()", async () => {
      id: ctx.getActorUri(handle),
      name: handle === "someone" ? "Someone" : "Someone 2",
      preferredUsername: handle === "someone" ? null : handle,
      icon: new Image({
        url: new URL("https://example.com/icon.jpg"),
        mediaType: "image/jpeg",
      }),
      urls: [
        new URL("https://example.com/@" + handle),
        new Link({
@@ -110,6 +114,11 @@ test("handleWebFinger()", async () => {
        rel: "alternate",
        type: "text/html",
      },
      {
        href: "https://example.com/icon.jpg",
        rel: "http://webfinger.net/rel/avatar",
        type: "image/jpeg",
      },
    ],
  };
  assertEquals(await response.json(), expected);
@@ -156,6 +165,11 @@ test("handleWebFinger()", async () => {
        rel: "alternate",
        type: "text/html",
      },
      {
        href: "https://example.com/icon.jpg",
        rel: "http://webfinger.net/rel/avatar",
        type: "image/jpeg",
      },
    ],
  };
  assertEquals(await response.json(), expected2);
+9 −0
Original line number Diff line number Diff line
@@ -122,6 +122,15 @@ export async function handleWebFinger<TContextData>(
      });
    }
  }
  for await (const image of actor.getIcons()) {
    if (image.url?.href == null) continue;
    const link: Link = {
      rel: "http://webfinger.net/rel/avatar",
      href: image.url.href.toString(),
    };
    if (image.mediaType != null) link.type = image.mediaType;
    links.push(link);
  }
  const jrd: ResourceDescriptor = {
    subject: resourceUrl.href,
    aliases: resourceUrl.href === context.getActorUri(handle).href