From ad7f66ebc3cdd9dae8194c86f6b692095f158729 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Wed, 17 Jul 2024 15:03:24 +0200 Subject: [PATCH] fix(federation): :bug: Correctly select the WebFinger link with the correct content-type, not just the first rel=self link --- federation/requester/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/federation/requester/index.ts b/federation/requester/index.ts index 886b9b8..0048e03 100644 --- a/federation/requester/index.ts +++ b/federation/requester/index.ts @@ -72,6 +72,7 @@ export class FederationRequester { * Get the user's profile link from their username. * @param username The username to get the profile link for. * @param hostname The hostname to get the profile link for (defaults to the server's hostname). + * @param contentType The content type of the link to get (defaults to "application/json"). * @returns The user's profile link. * @throws If the request fails or the response is invalid. * @example @@ -83,6 +84,7 @@ export class FederationRequester { public async webFinger( username: string, hostname = this.serverUrl.hostname, + contentType = "application/json", ): Promise { const result = await this.get( `/.well-known/webfinger?${new URLSearchParams({ @@ -100,7 +102,9 @@ export class FederationRequester { } // Get the first link with a rel of "self" - const selfLink = data.links?.find((link) => link.rel === "self"); + const selfLink = data.links?.find( + (link) => link.rel === "self" && link.type === contentType, + ); if (!selfLink) { throw new Error(