Robert Lowe

Linking to my Mastodon account without running a server

leave a comment »

So I read Scott Hanselman’s post on how to link Mastodon accounts to arbitrary domains and decided to give it a try for

Here’s the idea: I have a Mastodon account, but I’d like people to be able to find/mention me using, say, I’d like to do this without running a Mastodon server.

As Scott points out, Mastodon uses WebFinger to look up accounts. Here’s how that works: a Mastodon account name has two parts, a “user” part (mastodon in the above example), and a “host” part ( in the above example). To look up account details, Mastodon takes the host part and sends a WebFinger request to a well-known endpoint on that host; for the example above that would be The WebFinger request must include a resource parameter whose value is syntactically a URI; Mastodon uses the ‘acct’ URI scheme, so an account would be identified as e.g. Think of this like a mailto: URI, except that there’s no implication that the account is accessible using mail protocols, or actually any other protocols. So the full WebFinger request, after encoding the parameter value, would be made to

If you follow that URL you’ll see a JSON response known as a JSON Resource Descriptor (JRD), which includes details about my actual Mastodon account at If we were implementing WebFinger for a site that supports many accounts, as the Mastodon software would need to do, we’d obviously need some kind of dynamic lookup. However, a key insight here is that, since we want to link a hostname to just a single account, we can implement WebFinger by returning a static file! In other words, the value of the resource parameter will just be ignored. That’s what’s happening here — the file returned from is simply an exact static copy of the response from, served from an S3 bucket.

In fact the only tricky detail here was the S3 configuration. is served from an S3 bucket, and previously this was configured to simply redirect everything to (i.e. this site, a blog), as shown below.

Now, we need to redirect everything except the JRD at /.well-known/webfinger. It turns out that to do this we need to change the Hosting type to Host a static website.

Then, we can write some redirection rules (just one in this case) using JSON. The trick here is to redirect based on an HTTP response code — every URL path except the WebFinger path will get a 404 Not Found response from the S3 bucket.

        "Condition": {
            "HttpErrorCodeReturnedEquals": "404"
        "Redirect": {
            "HostName": "",
            "Protocol": "https"

With this configured, you can go to your favourite Mastodon instance and search for any account name with as the host; it will resolve to my account.

This also works for @ mentions, as demonstrated by this toot.

So, as 2023 begins, I’m a little easier to find on Mastodon, and a little wiser about WebFinger.

Happy New Year!

Written by rmlowe

January 2, 2023 at 8:16 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: