added url support in webfinger
This commit is contained in:
parent
a7b4a4978a
commit
e78bc262ed
1 changed files with 34 additions and 10 deletions
|
@ -144,11 +144,15 @@ namespace BirdsiteLive.Controllers
|
||||||
[Route("/.well-known/webfinger")]
|
[Route("/.well-known/webfinger")]
|
||||||
public IActionResult Webfinger(string resource = null)
|
public IActionResult Webfinger(string resource = null)
|
||||||
{
|
{
|
||||||
var acct = resource.Split("acct:")[1].Trim();
|
if (string.IsNullOrWhiteSpace(resource))
|
||||||
|
return BadRequest();
|
||||||
|
|
||||||
string name = null;
|
string name = null;
|
||||||
string domain = null;
|
string domain = null;
|
||||||
|
|
||||||
|
if (resource.StartsWith("acct:"))
|
||||||
|
{
|
||||||
|
var acct = resource.Split("acct:")[1].Trim();
|
||||||
var splitAcct = acct.Split('@', StringSplitOptions.RemoveEmptyEntries);
|
var splitAcct = acct.Split('@', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
var atCount = acct.Count(x => x == '@');
|
var atCount = acct.Count(x => x == '@');
|
||||||
|
@ -165,9 +169,29 @@ namespace BirdsiteLive.Controllers
|
||||||
{
|
{
|
||||||
return BadRequest();
|
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
|
// Ensure lowercase
|
||||||
name = name.ToLowerInvariant();
|
name = name.ToLowerInvariant();
|
||||||
|
domain = domain?.ToLowerInvariant();
|
||||||
|
|
||||||
// Ensure valid username
|
// Ensure valid username
|
||||||
// https://help.twitter.com/en/managing-your-account/twitter-username-rules
|
// https://help.twitter.com/en/managing-your-account/twitter-username-rules
|
||||||
|
|
Loading…
Add table
Reference in a new issue