logo

ap-client

CLI-based client / toolbox for ActivityPub Client-to-Servergit clone https://hacktivis.me/git/ap-client.git
commit: 5326f738474bb89d6d5072a9dd615243c9cacfa4
parent 50e7ba37fd2d90de0223da07c93db1361c11fc1f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 28 Mar 2023 08:27:42 +0200

script/webfinger: New

Diffstat:

Ascript/webfinger42++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+), 0 deletions(-)

diff --git a/script/webfinger b/script/webfinger @@ -0,0 +1,42 @@ +#!/usr/bin/env perl +# AP-Client: CLI-based client / toolbox for ActivityPub +# Copyright © 2020-2023 AP-Client Authors <https://hacktivis.me/git/ap-client/> +# SPDX-License-Identifier: BSD-3-Clause +use strict; +use utf8; + +use LWP::UserAgent; +use HTTP::Request::Common; + +=head1 NAME + +webfinger - Fetch account over WebFinger + +=head1 SYNOPSIS + +B<webfinger> <user@host> +=cut + +my $ua = LWP::UserAgent->new; +$ua->agent("AP-Client fetch <https://hacktivis.me/git/ap-client/>"); + +if ($#ARGV != 0) { + print "usage: webfinger <user\@host>\n"; + exit 1; +} + +my ($user, $host) = ($ARGV[0] =~ m/^@?([^@]+)@([^@]+)$/) + or die 'Error: "' . $ARGV[0] . q{" Doesn't matches user@host}; + +my $req = HTTP::Request->new( + GET => "https://$host/.well-known/webfinger?resource=acct:$user\@$host"); +$req->header('Accept' => 'application/json,application/xml'); + +my $res = $ua->request($req); + +if ($res->is_success) { + print $res->content; +} else { + print STDERR "Got ", $res->status_line, " instead of 2xx\n"; + exit 1; +}