Auth0に「Mastodonでログイン」を追加
本文の状態
日本語全文を表示中
詳細モードで約1分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Andrej Karpathy 厳選
OpenBenchesウェブサイト運営者が、Auth0のソーシャルログイン機能にMastodon対応がないことを指摘し、対応方法を模索している。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
私はOpenBenchesウェブサイトにソーシャルログインを提供するためにAuth0を使用しています。ユーザーアカウントの作成やパスワードの管理などを扱いたくないので、Auth0は私のニーズに最適です。Auth0が提供するソーシャルメディアログインの選択肢は幅広く、Facebook、Twitter、WordPress、Discordなどの定番サービスも含まれています。残念ながら、Mastodonのサポートはありません。しかし、すべてが失われたわけではありません…
原文を表示
I use Auth0 to provide social logins for the OpenBenches website. I don't want to deal with creating user accounts, managing passwords, or anything like that, so Auth0 is perfect for my needs.
There are a wide range of social media logins provided by Auth0 - including the usual suspects like Facebook, Twitter, WordPress, Discord, etc. Sadly, there's no support for Mastodon0.
All is not lost though. The Auth0 documentation says:
However, you can use Auth0’s Connections API to add any OAuth2 Authorization Server as an identity provider.
You can manually add a *single* Mastodon instance, but that doesn't work with the decentralised nature of the Fediverse. Instead, I've come up with a manual solution which works with *any* Mastodon server!
背景
Every Mastodon1 server is independent. I have an account on mastodon.social you have an account on whatever.chaos. They are separate servers, albeit running similar software. A generic authenticator needs to work with *all* these servers. There's no point only allowing log ins from a single server.
Fortuitously, Mastodon allows app developers to automatically create new apps. A few simple lines of code and you will have an API key suitable for *read-only* access to that server. You can read how to instantly create Mastodon API keys or you can steal my PHP code.
User Experience
The user clicks the sign-in button on OpenBenches. They're taken to the Auth0 social login screen:

The user clicks on Mastodon. This is where Auth0's involvement ends!
The user is asked to provide the URl of their instance:

In the background, my server contacts the Mastodon instance and creates a read-only API key.
The user is asked to sign in to Mastodon.

The user is asked to authorise read-only access.

The user is now signed in and OpenBenches can retrieve their name, avatar image, and other useful information. Hurrah!
Auth0
Once you have created a service to generate API keys, it will need to run on a publicly accessible web server. For example https://example.com/mastodon_login.
Here's what you need to do within your Auth0 tennant:
- Authentication → Social → Create Connection
- At the bottom, choose "Create Custom".
- Choose "Authentication" only.
- Give your connection a name. This will be visible to users.
- "Authorization URL" and "Token URL" have the same value - the URl of your service.
- "Client ID" is only visible to you.
- "Client Secret" any random password; it won't be used for anything.
- Leave everything else in the default state.
It should look something like this:

Click the "Create" button and you're (almost) done.
Auth0 Icon
You will need to add a custom icon to the social integration. Annoyingly, there's no way to do it through the web interface, so follow that guide to use the command line.
Done!
I'll admit, this isn't the most straightforward thing to implement. Auth0 could make this easier - but it would still rely on users knowing the URl of their home instance.
That said, the Mastodon API is a delight to work with and the read-only permissions reduce risk for all parties.
- Auth0 did blog about Mastodon a few years ago but never bothered implementing it! ↩︎
- I do mean Mastodon; not the wider Fediverse. This only works with sites which have implemented Mastodon's APIs. ↩︎
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み