Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

使用您自己的用户@域通过 WebFinger 协议实现 Mastodon 可发现性,而无需托管服务器

Posted on 2022-12-19

Mastodon 是一种免费的开源社交网络服务,是去中心化和分布式的。它创建于 2016 年,作为 Twitter 和 Facebook 等中心化社交媒体平台的替代品。

Mastodon 的主要功能之一是使用 WebFinger 协议,该协议允许用户发现和访问有关 Mastodon 网络上其他用户的信息。 WebFinger 是一个简单的基于 HTTP 的协议,它使用户能够通过使用他们的电子邮件地址或其他识别信息来发现有关 Internet 上其他用户或资源的信息。 WebFinger 协议对 Mastodon 很重要,因为它使用户能够在网络上找到并关注彼此,无论他们位于何处。

WebFinger 在调用域时使用“众所周知”的路径结构。您可能熟悉 robots.txt 约定。我们都同意 robots.txt 将位于每个人域的顶级路径。

WebFinger 协议是一个简单的基于 HTTP 的协议,它使用户或搜索能够通过使用他们的电子邮件地址或其他识别信息来发现有关 Internet 上其他用户或资源的信息。我的名字是姓氏 .com,所以…我的个人 WebFinger API 端点在这里https://www.hanselman.com/.well-known/webfinger

这个想法是……

  1. 用户使用电子邮件地址或其他用户身份信息或他们试图发现的资源向服务器发送 WebFinger 请求。

  2. 服务器在其数据库中查找请求的信息并返回包含有关用户或资源的信息的 JSON 对象。此 JSON 对象称为“资源描述符”。

  3. 用户的客户端接收资源描述符并将信息显示给用户。

资源描述符包含有关用户或资源的各种类型的信息,例如他们的姓名、个人资料图片以及指向他们的社交媒体帐户或其他在线资源的链接。它还可以包括其他类型的信息,例如用户的公钥,可用于与用户建立安全连接。

这里也有很棒的解说员。从那个页面:

当有人在 Mastodon 上搜索您时,您的服务器将使用如下端点查询帐户:

获取https://${MASTODON_DOMAIN}/.well-known/webfinger?resource=acct:${MASTODON_USER}@${MASTODON_DOMAIN }

请注意,Mastodon 用户名以 @ 开头,因此它们是 @[email protected]。就像推特会是@[email protected],我现在可以是@[email protected]!

Searching for me with Mastodon

所以也许https://ift.tt/LwnNpu1

矿山回报

{ 
  

“主题”:“acct:[email protected]”,
“别名”:
[
“https://hachyderm.io/@shanselman”,
“https://hachyderm.io/users/shanselman”
],
“链接”:
[
{
"rel":"http://webfinger.net/rel/profile-page",
“类型”:“文本/html”,
“href”:“https://hachyderm.io/@shanselman”
},
{
“相对”:“自我”,
“类型”:“应用程序/活动+ json”,
“href”:“https://hachyderm.io/users/shanselman”
},
{
“rel”:“http://ostatus.org/schema/1.0/subscribe”,
“模板”:“https://hachyderm.io/authorize_interaction?uri={uri}”
}
]
}

此文件应作为application/jrd+json的 mime 类型返回

我的站点是一个 ASP.NET Razor Pages 站点,所以我只是在 Startup.cs 中执行此操作以将众所周知的 URL 映射到返回所需 JSON 的页面/路由。

 services.AddRazorPages().AddRazorPagesOptions(选项=> 
  

{
options.Conventions.AddPageRoute("/robotstxt", "/Robots.Txt"); //我以前做过,不需要
options.Conventions.AddPageRoute("/webfinger", "/.well-known/webfinger");
options.Conventions.AddPageRoute("/webfinger", "/.well-known/webfinger/{val?}");
});

然后我做了一个 webfinger.cshtml 这样的。请注意,我必须双重转义 @@ 站点,因为它是 Razor。

 @页 
  

@{
布局=空;
this.Response.ContentType = "application/jrd+json";
}
{
“主题”:“acct:[email protected]”,
“别名”:
[
“https://hachyderm.io/@@shanselman”,
“https://hachyderm.io/users/shanselman”
],
“链接”:
[
{
"rel":"http://webfinger.net/rel/profile-page",
“类型”:“文本/html”,
“href”:“https://hachyderm.io/@@shanselman”
},
{
“相对”:“自我”,
“类型”:“应用程序/活动+ json”,
“href”:“https://hachyderm.io/users/shanselman”
},
{
"rel":"http://ostatus.org/schema/1.0/subscribe",
“模板”:“https://hachyderm.io/authorize_interaction?uri={uri}”
}
]
}

这是一个静态响应,但如果我为多个人托管页面,我想获取带有用户名的 url,然后将其映射到他们的别名并正确返回这些别名。

更简单的是,您可以只使用您自己的 Mastodon 服务器的 webfinger 响应的 JSON 文件并将其另存为静态 json 文件并将其复制到您自己的服务器!

只要您的服务器从那个众所周知的 URL 返回正确的 JSON,它就会工作。

所以这是我现在托管的模板https://hachyderm.io/.well-known/webfinger?resource=acct:[email protected] 。

如果您想开始使用 Mastodon,请从这里开始。 https://github.com/joyeusenoelle/GuideToMastodon/感觉就像 2007 年左右的 Twitter,只是它不为任何人所有,并且基于 ActivityPub 等网络标准。

希望这可以帮助!


© 2021 斯科特·汉塞尔曼。版权所有。

fblike20.png 推特20.png电子邮件20.png rss20.png

原文: https://www.hanselman.com/blog/use-your-own-user-domain-for-mastodon-discoverability-with-the-webfinger-protocol-without-hosting-a-server

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • Elad Gil
  • Ellie Huxtable
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mostly metrics
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme