Skip to content

Commit ef0729f

Browse files
fix(settings): change Mastodon only URI to webfinger
Signed-off-by: 諏訪子 <suwako@076.moe>
1 parent b367ab2 commit ef0729f

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@
620620
- szaimen <szaimen@e.mail.de>
621621
- tbartenstein <tbartenstein@users.noreply.github.com>
622622
- tbelau666 <thomas.belau@gmx.de>
623+
- TechnicalSuwako <suwako@076.moe>
623624
- tgrant <tom.grant760@gmail.com>
624625
- timm2k <timm2k@gmx.de>
625626
- tux-rampage <tux-rampage@users.noreply.github.com>

lib/private/Accounts/AccountManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ private function sanitizePropertyFediverse(IAccountProperty $property): void {
734734

735735
try {
736736
// try the public account lookup API of mastodon
737-
$response = $client->get("https://{$instance}/api/v1/accounts/lookup?acct={$username}@{$instance}");
737+
$response = $client->get("https://{$instance}/.well-known/webfinger?resource=acct:{$username}@{$instance}");
738738
// should be a json response with account information
739739
$data = $response->getBody();
740740
if (is_resource($data)) {
@@ -743,7 +743,7 @@ private function sanitizePropertyFediverse(IAccountProperty $property): void {
743743
$decoded = json_decode($data, true);
744744
// ensure the username is the same the user passed
745745
// in this case we can assume this is a valid fediverse server and account
746-
if (!is_array($decoded) || ($decoded['username'] ?? '') !== $username) {
746+
if (!is_array($decoded) || ($decoded['subject'] ?? '') !== "acct:{$username}@{$instance}") {
747747
throw new InvalidArgumentException();
748748
}
749749
} catch (InvalidArgumentException) {

tests/lib/Accounts/AccountManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,12 @@ public function testSanitizingFediverseServer(string $input, ?string $output, bo
839839
->willReturn($serverResponse);
840840
$client->expects(self::once())
841841
->method('get')
842-
->with('https://example.com/api/v1/accounts/lookup?acct=foo@example.com')
842+
->with('https://example.com/.well-known/webfinger?resource=acct:foo@example.com')
843843
->willReturn($response);
844844
} else {
845845
$client->expects(self::once())
846846
->method('get')
847-
->with('https://example.com/api/v1/accounts/lookup?acct=foo@example.com')
847+
->with('https://example.com/.well-known/webfinger?resource=acct:foo@example.com')
848848
->willThrowException(new \Exception('404'));
849849
}
850850

0 commit comments

Comments
 (0)