Created
November 11, 2022 10:12
-
-
Save nul800sebastiaan/65f7b073a6a85b7e745fda55c2d7301a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:[email protected]") | |
{ | |
return new NotFoundResult(); | |
} | |
var value = new WebfingerModel | |
{ | |
Subject = "acct:[email protected]", | |
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