logo

ap-client

CLI-based client / toolbox for ActivityPub Client-to-Servergit clone https://hacktivis.me/git/ap-client.git

webfinger (1019B)


  1. #!/usr/bin/env perl
  2. # AP-Client: CLI-based client / toolbox for ActivityPub
  3. # Copyright © 2020-2023 AP-Client Authors <https://hacktivis.me/git/ap-client/>
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. use strict;
  6. use utf8;
  7. our $VERSION = 'v0.1.4';
  8. use LWP::UserAgent;
  9. use HTTP::Request::Common;
  10. =head1 NAME
  11. webfinger - Fetch account over WebFinger
  12. =head1 SYNOPSIS
  13. B<webfinger> <user@host>
  14. =cut
  15. my $ua = LWP::UserAgent->new;
  16. $ua->agent("AP-Client fetch <https://hacktivis.me/git/ap-client/>");
  17. if ($#ARGV != 0) {
  18. print "usage: webfinger <user\@host>\n";
  19. exit 1;
  20. }
  21. my ($user, $host) = ($ARGV[0] =~ m/^@?([^@]+)@([^@]+)$/)
  22. or die 'Error: "' . $ARGV[0] . q{" Doesn't matches user@host};
  23. my $req = HTTP::Request->new(
  24. GET => "https://$host/.well-known/webfinger?resource=acct:$user\@$host");
  25. $req->header('Accept' => 'application/json,application/xml');
  26. my $res = $ua->request($req);
  27. if ($res->is_success) {
  28. print $res->content;
  29. } else {
  30. print STDERR "Got ", $res->status_line, " instead of 2xx\n";
  31. exit 1;
  32. }