fix: check for obviously invalid instance URLs, use correct JSON key for mastodon scopes

This commit is contained in:
sam 2024-11-23 20:40:09 +01:00
parent 9160281ea2
commit d0bf638a21
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
2 changed files with 18 additions and 10 deletions

View file

@ -6,7 +6,6 @@ using Foxnouns.Backend.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using NodaTime;
using FediverseAuthService = Foxnouns.Backend.Services.Auth.FediverseAuthService;
namespace Foxnouns.Backend.Controllers.Authentication;
@ -25,6 +24,9 @@ public class FediverseAuthController(
[ProducesResponseType<FediverseUrlResponse>(statusCode: StatusCodes.Status200OK)]
public async Task<IActionResult> GetFediverseUrlAsync([FromQuery] string instance)
{
if (instance.Any(c => c is '@' or ':' or '/') || !instance.Contains('.'))
throw new ApiError.BadRequest("Not a valid domain.", "instance", instance);
var url = await fediverseAuthService.GenerateAuthUrlAsync(instance);
return Ok(new FediverseUrlResponse(url));
}