Skip to content

Instantly share code, notes, and snippets.

@nul800sebastiaan
Created November 11, 2022 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nul800sebastiaan/65f7b073a6a85b7e745fda55c2d7301a to your computer and use it in GitHub Desktop.
Save nul800sebastiaan/65f7b073a6a85b7e745fda55c2d7301a to your computer and use it in GitHub Desktop.
using System.Text.Json.Serialization;
using J2N.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Cultiv.Controllers;
[ApiController]
[Route(".well-known/[controller]")]
[Produces("application/json")]
public class WebfingerController : ControllerBase
{
[HttpGet]
public ActionResult Get([FromQuery] string resource)
{
if (string.IsNullOrEmpty(resource) || resource != "acct:hello@cultiv.nl")
{
return new NotFoundResult();
}
var value = new WebfingerModel
{
Subject = "acct:cultiv@mastodon.social",
Aliases = new List<string>
{
"https://mastodon.social/@cultiv",
"https://mastodon.social/user/cultiv"
},
Links = new List<Link>
{
new Link
{
Rel = "http://webfinger.net/rel/profile-page",
Type = "text/html",
Href = "https://mastodon.social/@cultiv"
},
new Link
{
Rel = "self",
Type = "application/activity+json",
Href = "https://mastodon.social/users/cultiv"
},
new Link
{
Rel = "http://ostatus.org/schema/1.0/subscribe",
Template = "https://mastodon.social/authorize_interaction?uri={uri}",
}
}
};
return new JsonResult(value);
}
}
public class Link
{
[JsonProperty("rel")]
[JsonPropertyName("rel")]
public string Rel { get; set; }
[JsonProperty("type")]
[JsonPropertyName("type")]
public string Type { get; set; }
[JsonProperty("href")]
[JsonPropertyName("href")]
public string Href { get; set; }
[JsonProperty("template")]
[JsonPropertyName("template")]
public string Template { get; set; }
}
public class WebfingerModel
{
[JsonProperty("subject")]
[JsonPropertyName("subject")]
public string Subject { get; set; }
[JsonProperty("aliases")]
[JsonPropertyName("aliases")]
public List<string> Aliases { get; set; }
[JsonProperty("links")]
[JsonPropertyName("links")]
public List<Link> Links { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment