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)); }
public async Task <IActionResult> WebFinger(string resource) { if (!resource.StartsWith("acct:")) { return(Unauthorized()); } var username = resource.Split(':')[1].Split('@'); var param = new _queryParam() { preferredUsername = username[0] }; var items = await _context.Entities.FromSql("SELECT * from \"Entities\" WHERE \"SerializedData\" @> {0}::jsonb", JsonConvert.SerializeObject(param)) .Where(a => a.Type == "Person").ToListAsync(); if (items.Count == 0) { return(NotFound()); } var item = items.First(); var outbox = (string)item.Data["outbox"].First().Primitive + $".atom?from_id={int.MaxValue}"; var inbox = (string)item.Data["inbox"].First().Primitive; 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 = "http://schemas.google.com/g/2010#updates-from", type = "application/atom+xml", href = outbox }, 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 = "salmon", href = inbox }, new WebfingerLink { rel = "http://ostatus.org/schema/1.0/subscribe", template = item.Id + "?subscribe&user={uri}" } } }; var salmon = await _context.GetKey(item.Id); var magicKey = new Salmon.MagicKey(salmon.PrivateKey); result.links.Add(new WebfingerLink { rel = "magic-public-key", href = "data:application/magic-public-key," + magicKey.PublicKey }); return(Json(result)); }