add error handler middleware
This commit is contained in:
parent
41e4dda7b4
commit
7a0247b551
13 changed files with 177 additions and 46 deletions
|
@ -1,8 +1,9 @@
|
|||
using Foxchat.Core;
|
||||
using Foxchat.Core.Models.Http;
|
||||
using Foxchat.Identity.Authorization;
|
||||
using Foxchat.Identity.Middleware;
|
||||
using Foxchat.Identity.Database;
|
||||
using Foxchat.Identity.Database.Models;
|
||||
using Foxchat.Identity.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Foxchat.Identity.Controllers.Oauth;
|
||||
|
@ -29,9 +30,7 @@ public class AppsController(ILogger logger, IdentityContext db) : ControllerBase
|
|||
[HttpGet]
|
||||
public IActionResult GetSelfApp([FromQuery(Name = "with_secret")] bool withSecret)
|
||||
{
|
||||
var token = HttpContext.GetToken();
|
||||
if (token is not { Account: null }) throw new ApiError.Forbidden("This endpoint requires a client token.");
|
||||
var app = token.Application;
|
||||
var app = HttpContext.GetApplicationOrThrow();
|
||||
|
||||
return Ok(new Apps.GetSelfResponse(
|
||||
app.Id,
|
||||
|
|
22
Foxchat.Identity/Controllers/Oauth/PasswordAuthController.cs
Normal file
22
Foxchat.Identity/Controllers/Oauth/PasswordAuthController.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using Foxchat.Identity.Middleware;
|
||||
using Foxchat.Identity.Database;
|
||||
using Foxchat.Identity.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Foxchat.Identity.Controllers.Oauth;
|
||||
|
||||
[ApiController]
|
||||
[Authenticate]
|
||||
[Route("/_fox/ident/oauth/password")]
|
||||
public class PasswordAuthController(ILogger logger, IdentityContext db) : ControllerBase
|
||||
{
|
||||
[HttpPost("register")]
|
||||
public async Task<IActionResult> Register()
|
||||
{
|
||||
var app = HttpContext.GetApplicationOrThrow();
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public record RegisterRequest();
|
||||
}
|
|
@ -16,7 +16,7 @@ public class TokenController(ILogger logger, IdentityContext db, IClock clock) :
|
|||
var app = await db.GetApplicationAsync(req.ClientId, req.ClientSecret);
|
||||
|
||||
var scopes = req.Scope.Split(' ');
|
||||
if (app.Scopes.Except(scopes).Any())
|
||||
if (scopes.Except(app.Scopes).Any())
|
||||
{
|
||||
throw new ApiError.BadRequest("Invalid or unauthorized scopes");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue