Finally fix indieauth, add more logging

This commit is contained in:
Saphire 2023-10-29 14:23:30 +06:00
parent 309b4345f1
commit 72bb48341b
Signed by: Saphire
GPG Key ID: B26EB7A1F07044C4

View File

@ -172,14 +172,27 @@ public class IndieauthController : ControllerBase
public async Task<IActionResult> AuthorizeClient(IndieauthAuthorizeModel model)
{
// A hack for the older stuff
if (model.GrantType is null && model.ClientId is not null && model.ClientId == "https://indieauth.com/")
model.GrantType = "authorization_code";
if (model.GrantType is null)
{
Logger.LogInformation("IndieAuth client token authorization failure: missing grant_type");
return BadRequest(new { Error = "invalid_request", ErrorMessage = "Missing grant_type argument" });
}
if (model.GrantType != "authorization_code")
{
Logger.LogInformation("IndieAuth client token authorization failure: unsupported grant_type \"{grantType}\"", model.GrantType);
return BadRequest(new { Error = "unsupported_grant_type", ErrorMessage = "Supported grant types: authorization_code" });
}
if (model.Code is null || model.ClientId is null || model.RedirectUri is null)
{
Logger.LogInformation("IndieAuth client token authorization failure: missing parameter (code: {noCode}, clientId: {noClientId} or redirectUri: {noRedirectUri})", model.Code is null, model.ClientId is null, model.RedirectUri is null);
return BadRequest(new { Error = "invalid_request", ErrorMessage = "Missing required parameters" });
}
var requestCode = await DbContext.IndieauthRequests.SingleOrDefaultAsync(
c => c.Value == model.Code