identity: add proxy controller

This commit is contained in:
sam 2024-05-21 21:21:34 +02:00
parent 727f2f6ba2
commit b95fb76cd4
9 changed files with 446 additions and 10 deletions

View file

@ -1,5 +1,6 @@
using Foxchat.Core;
using Foxchat.Identity.Database;
using Foxchat.Identity.Utils;
using NodaTime;
namespace Foxchat.Identity.Middleware;
@ -21,10 +22,10 @@ public class ClientAuthorizationMiddleware(
}
var token = ctx.GetToken();
if (token == null || token.Expires > clock.GetCurrentInstant())
if (token == null || token.Expires < clock.GetCurrentInstant())
throw new ApiError.Unauthorized("This endpoint requires an authenticated user.");
if (attribute.Scopes.Length > 0 && attribute.Scopes.Except(token.Scopes).Any())
throw new ApiError.Forbidden("This endpoint requires ungranted scopes.", attribute.Scopes.Except(token.Scopes));
if (attribute.Scopes.Length > 0 && attribute.Scopes.Except(token.ExpandScopes()).Any())
throw new ApiError.Forbidden("This endpoint requires ungranted scopes.", attribute.Scopes.Except(token.ExpandScopes()));
await next(ctx);
}