added url support in webfinger

This commit is contained in:
Nicolas Constant 2022-02-08 23:40:02 -05:00
parent a7b4a4978a
commit e78bc262ed
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 34 additions and 10 deletions

View File

@ -144,11 +144,15 @@ namespace BirdsiteLive.Controllers
[Route("/.well-known/webfinger")]
public IActionResult Webfinger(string resource = null)
{
var acct = resource.Split("acct:")[1].Trim();
if (string.IsNullOrWhiteSpace(resource))
return BadRequest();
string name = null;
string domain = null;
if (resource.StartsWith("acct:"))
{
var acct = resource.Split("acct:")[1].Trim();
var splitAcct = acct.Split('@', StringSplitOptions.RemoveEmptyEntries);
var atCount = acct.Count(x => x == '@');
@ -165,9 +169,29 @@ namespace BirdsiteLive.Controllers
{
return BadRequest();
}
}
else if (resource.StartsWith("https://"))
{
try
{
name = resource.Split('/').Last().Trim();
domain = resource.Split("https://", StringSplitOptions.RemoveEmptyEntries)[0].Split('/')[0].Trim();
}
catch (Exception e)
{
_logger.LogError(e, "Error parsing {Resource}", resource);
throw new NotImplementedException();
}
}
else
{
_logger.LogError("Error parsing {Resource}", resource);
throw new NotImplementedException();
}
// Ensure lowercase
name = name.ToLowerInvariant();
domain = domain?.ToLowerInvariant();
// Ensure valid username
// https://help.twitter.com/en/managing-your-account/twitter-username-rules