2026-10-18 09:18:26 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
2026-11-10 07:28:02 +01:00
|
|
|
using PrivaPub.Api.Mastodon.Entities;
|
2026-10-18 09:18:26 +02:00
|
|
|
using PrivaPub.Api.Mastodon.Infrastructure;
|
|
|
|
|
using PrivaPub.Api.Mastodon.Mappers;
|
|
|
|
|
using PrivaPub.Federation.Actors;
|
|
|
|
|
|
|
|
|
|
namespace PrivaPub.Api.Mastodon.Controllers
|
|
|
|
|
{
|
|
|
|
|
// Mastodon 4.4's OAuth userinfo (OpenID Connect's shape, GET or POST, the `profile` scope): who the token's persona is,
|
|
|
|
|
// for a site that signs in with it. Only what its public account says already; never its login. The authorization
|
|
|
|
|
// server's metadata names it (OAuthSetup).
|
2026-11-10 01:24:43 +01:00
|
|
|
public class UserinfoController(
|
|
|
|
|
MastodonMapper mapper,
|
|
|
|
|
ILocalActorService localActors) : MastodonController
|
2026-10-18 09:18:26 +02:00
|
|
|
{
|
|
|
|
|
public const string Path = "/oauth/userinfo";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet(Path), HttpPost(Path), Scope("profile")]
|
|
|
|
|
public async Task<IActionResult> Show(CancellationToken token)
|
|
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
var account = await mapper.Local(Me, false, token);
|
2026-11-10 07:28:02 +01:00
|
|
|
return Json(new UserInfoEntity
|
2026-10-18 09:18:26 +02:00
|
|
|
{
|
2026-11-10 07:28:02 +01:00
|
|
|
Iss = localActors.BaseAddress + "/",
|
|
|
|
|
Sub = Me.Uri,
|
|
|
|
|
Name = account.DisplayName,
|
|
|
|
|
PreferredUsername = account.Username,
|
|
|
|
|
Profile = account.Url,
|
|
|
|
|
Picture = account.Avatar
|
2026-10-18 09:18:26 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|