public async Task <IActionResult> Proxy(string id) { if (User.FindFirstValue(JwtTokenSettings.ActorClaim) == null) { return(Unauthorized()); } APEntity entity = null; if (id.StartsWith('@')) { id = id.Substring(1); var spl = id.Split(new char[] { '@' }, 2); var host = spl.Length > 1 ? spl[1] : Request.Host.ToString(); var ent = await _relevantEntities.FindEntitiesWithPreferredUsername(spl[0]); var withHost = ent.FirstOrDefault(a => new Uri(a.Id).Host == host); if (withHost == null && spl.Length == 1) { return(NotFound()); } entity = withHost; if (entity == null && spl.Length > 1) { var hc = new HttpClient(); var webfinger = JsonConvert.DeserializeObject <WellKnownController.WebfingerResult>(await hc.GetStringAsync($"https://{host}/.well-known/webfinger?resource=acct:{id}")); var activityStreams = webfinger.links.FirstOrDefault(a => a.rel == "self" && (a.type == "application/activity+json" || a.type == "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")); if (activityStreams == null) { return(NotFound()); } id = activityStreams.href; } } if (entity == null) { entity = await _entityStore.GetEntity(id, true); } if (entity == null) { return(NotFound()); } var unflattened = await _entityFlattener.Unflatten(_entityStore, entity); return(Content(unflattened.Serialize(true).ToString(), "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")); }
public async Task <IActionResult> WebFinger(string resource) { if (!resource.StartsWith("acct:")) { return(Unauthorized()); } var username = resource.Split(':')[1].Split('@'); var items = await _relevantEntities.FindEntitiesWithPreferredUsername(username[0]); if (items.Count == 0) { return(NotFound()); } var item = items.First(); var result = new WebfingerResult() { subject = resource, aliases = new List <string>() { item.Id }, links = new List <WebfingerLink> { new WebfingerLink { rel = "http://webfinger.net/rel/profile-page", type = "text/html", href = item.Id }, new WebfingerLink { rel = "self", type = "application/activity+json", href = item.Id }, new WebfingerLink { rel = "self", type = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", href = item.Id }, new WebfingerLink { rel = "http://ostatus.org/schema/1.0/subscribe", template = item.Id + "#id=%40{uri}" } } }; var salmon = await _keyService.GetKey(item.Id); var magicKey = new MagicKey(salmon.PrivateKey); result.links.Add(new WebfingerLink { rel = "magic-public-key", href = "data:application/magic-public-key," + magicKey.PublicKey }); return(Json(result)); }