Iceshrimp.NET/Iceshrimp.Backend/Controllers/Mastodon/MastodonUserController.cs
2024-02-02 20:05:27 +01:00

28 lines
No EOL
1.1 KiB
C#

using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
using Iceshrimp.Backend.Core.Middleware;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
namespace Iceshrimp.Backend.Controllers.Mastodon;
[ApiController]
[Tags("Mastodon")]
[Route("/api/v1/accounts")]
[AuthenticateOauth]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]
public class MastodonUserController(UserRenderer userRenderer) : Controller {
[AuthorizeOauth("read:accounts")]
[HttpGet("verify_credentials")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Account))]
public async Task<IActionResult> VerifyUserCredentials() {
var user = HttpContext.GetOauthUser() ?? throw new GracefulException("Failed to get user from HttpContext");
var res = await userRenderer.RenderAsync(user);
return Ok(res);
}
}