Adding Mastodon discoverability by e-mail address
Through the “interesting” days, when people started migrating into Mastodon, I found quite interesting toot from one of its users where he mention adding Mastodon discoverability for any domain using WebFinger Protocol.
I have been quite interested in how to implement this on my end, as I prefer people to discover me with my long-standing email address, rather than the newly created username on the selected mastodon server.
As my website is hosted on Netlify I decided to check if I can implement this. Here is how it goes.
For a better understanding of how Scott achieved this on his end, I referred to his original post1. I read some more information about WebFinger Protocol on Wikipedia and then recalled John Mueller post from not soo far back, where I found a conclusive solution for me.
Before starting I need to explain a couple of things.
As mentioned at the beginning, I would like for people in the Mastodon network to be able to discover me by my email address rather than a specific username in the Mastodon network (currently
I am not using my main domain for my website. My site is served in the subdomain
dariusz of the domain
wieckiewicz.org. Putting an
@ symbol between resolving my email address.
Mastodon uses WebFinger Protocol to discover users.
When using tools like
Lookup WebFinger located in the top-right part of WebFinger website, you can type an email address to find how this resolves.
As you will see at the start, Lookup WebFinger will look into a domain, that is part of your email, as follow:
As my website is static using Hugo I don’t have real server functionality to add dynamic responses. To point out this dynamic request for WebFinger I decided to utilise, what John mention in his Apache & co part – redirects.
Redirect method #
I already got some redirects in place for my main domain. If you type
wieckiewicz.org in your browser address bar you will be 301 redirected to
dariusz.wieckiewicz.org. I am doing this with
_redirects file located in my
/static folder of my Hugo-based website.
https://wieckiewicz.org https://dariusz.wieckiewicz.org 301! https://wieckiewicz.org/* https://dariusz.wieckiewicz.org/:splat 301!
These two rules will not only redirect the main domain but all links, where the subdomain
dariusz. is missing in the URL.
The original request sent by WebFinger looks as follows:
As you noticed, symbols like
@ are replaced by Unicode equivalents for compatibility reasons.
That same matter we need to have in our mind when we will compose a redirect rule in our
_redirects file, so nothing will unintentionally break.
Theoretically reference to
.well-known/webfingershall be enough, but some sourced, including John, referring also to Web Host Metadata (
.well-known/host-meta) and Node Info (
.well-known/nodeinfo), so I will keep them as well.
Between the two rules mentioned above, I pasted the following:
https://wieckiewicz.org/.well-known/webfinger?resource=acct%3Adariusz%40wieckiewicz.org https://seocommunity.social/.well-known/webfinger?resource=acct%3Adariusz_w%40seocommunity.social 301! https://wieckiewicz.org/.well-known/host-meta?resource=acct%3Adariusz%40wieckiewicz.org https://seocommunity.social/.well-known/host-meta?resource=acct%3Adariusz_w%40seocommunity.social 301! https://wieckiewicz.org/.well-known/nodeinfo?resource=acct%3Adariusz%40wieckiewicz.org https://seocommunity.social/.well-known/nodeinfo?resource=acct%3Adariusz_w%40seocommunity.social 301!
This may look a bit complicated, but if you got more users in your domain, and these users may use different servers in the fediverse, it will be easier to add them and not restrict them to one instance (server).
Here you will see, where WebFinger is requesting a response on
.well-known/webfinger?resource=acct:email@example.com in my domain, will be pointed to
seocommunity.social and my username there
Once the redirect is active, WebFinger Lookup service shall return the response for the right user on
Remember, before you apply any
_redirectsin production check them on Netlify’s Playground!
Single file method #
Using the redirect method is a bit ambitious. If you looking for a quick and simple solution, Alex Guyot on Mastodon comes up with a dirty simple solution by faking WebFinger protocol response served from our domain.
The solution is limited to creating a
webfinger file inside the
.well-known folder (with a dot on the front).
Starting with getting a response from that same file on the selected mastodon server, we just need to copy, paste and save it into our dummy file.
Using the following part of the path we can get a JSON response from the mastodon server:
This will give you a simple response:
Copy, save and serve in your
/.well-known/webfinger file will do the trick.
Dirty simple yet working well, so why not give an option.
It’s time to check if other users can search for us (find us) in the Mastodon network using our original e-mail address without knowing where exactly, on which server, we have created our account.
This will give us the flexibility to move between instances and people, who do not follow us, can still find us using our original email address. Of course, as long as we will keep our redirect of webfinger file up-to-date.
Why not you try, find me and say hello!