[backend/middleware] Require administrator role for masto admin scope endpoints
This isn't currently used anywhere, but may become relevant in the future.
This commit is contained in:
parent
3a51684e07
commit
8b514986a4
2 changed files with 4 additions and 2 deletions
|
@ -62,8 +62,8 @@ public class AuthenticationMiddleware(
|
|||
}
|
||||
|
||||
if ((attribute.AdminRole && !oauthToken.User.IsAdmin) ||
|
||||
(attribute.ModeratorRole &&
|
||||
oauthToken.User is { IsAdmin: false, IsModerator: false }))
|
||||
(attribute.ModeratorRole && oauthToken.User is { IsAdmin: false, IsModerator: false }) ||
|
||||
(attribute.Scopes.Any(p => p is "admin" || p.StartsWith("admin:")) && !oauthToken.User.IsAdmin))
|
||||
{
|
||||
await next(ctx);
|
||||
return;
|
||||
|
|
|
@ -26,6 +26,8 @@ public class AuthorizationMiddleware(RequestDelegate next) : ConditionalMiddlewa
|
|||
throw GracefulException.Forbidden("This action is outside the authorized scopes");
|
||||
if (attribute.ModeratorRole && token.User is { IsAdmin: false, IsModerator: false })
|
||||
throw GracefulException.Forbidden("This action is outside the authorized scopes");
|
||||
if (attribute.Scopes.Any(p => p is "admin" || p.StartsWith("admin:") && !token.User.IsAdmin))
|
||||
throw GracefulException.Forbidden("This action is outside the authorized scopes");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue