Repository: microsoft/onefuzz
File: src/ApiService/ApiService/onefuzzlib/EndpointAuthorization.cs (C#)

Code before:
    Async.Task<OneFuzzResultVoid> CheckRequireAdmins(HttpRequestData req);
}

public class EndpointAuthorization : IEndpointAuthorization {
    private readonly IOnefuzzContext _context;
    private readonly ILogTracer _log;
    private readonly GraphServiceClient _graphClient;
    private static readonly HashSet<string> AgentRoles = new HashSet<string> { "UnmanagedNode", "ManagedNode" };

    public EndpointAuthorization(IOnefuzzContext context, ILogTracer log, GraphServiceClient graphClient) {
        _context = context;
        _log = log;
        _graphClient = graphClient;
    }

    public virtual async Async.Task<HttpResponseData> CallIf(HttpRequestData req, Func<HttpRequestData, Async.Task<HttpResponseData>> method, bool allowUser = false, bool allowAgent = false) {
        var tokenResult = await _context.UserCredentials.ParseJwtToken(req);

        if (!tokenResult.IsOk) {
            return await _context.RequestHandling.NotOk(req, tokenResult.ErrorV, "token verification", HttpStatusCode.Unauthorized);
        }

        var token = tokenResult.OkV.UserInfo;
        if (await IsUser(tokenResult.OkV)) {
            if (!allowUser) {
                return await Reject(req, tokenResult.OkV.UserInfo);
            }

            var access = await CheckAccess(req);
            if (!access.IsOk) {
                return await _context.RequestHandling.NotOk(req, access.ErrorV, "access control", HttpStatusCode.Unauthorized);
            }
        }

        if (await IsAgent(tokenResult.OkV) && !allowAgent) {
            return await Reject(req, tokenResult.OkV.UserInfo);
        }

        return await method(req);
    }

    public async Async.Task<bool> IsUser(UserAuthInfo tokenData) {
        return !await IsAgent(tokenData);
    }

    public async Async.Task<HttpResponseData> Reject(HttpRequestData req, UserInfo token) {
        var body = await req.ReadAsStringAsync();
        _log.Error($"reject token. url:{req.Url:Tag:Url} token:{token:Tag:Token} body:{body:Tag:Body}");

        return await _context.RequestHandling.NotOk(
            req,

Review comment (suggestion):
```suggestion
                return await Reject(req, token);
```

Code after:
    Async.Task<OneFuzzResultVoid> CheckRequireAdmins(HttpRequestData req);
}

public class EndpointAuthorization : IEndpointAuthorization {
    private readonly IOnefuzzContext _context;
    private readonly ILogTracer _log;
    private readonly GraphServiceClient _graphClient;
    private static readonly HashSet<string> AgentRoles = new HashSet<string> { "UnmanagedNode", "ManagedNode" };

    public EndpointAuthorization(IOnefuzzContext context, ILogTracer log, GraphServiceClient graphClient) {
        _context = context;
        _log = log;
        _graphClient = graphClient;
    }

    public virtual async Async.Task<HttpResponseData> CallIf(HttpRequestData req, Func<HttpRequestData, Async.Task<HttpResponseData>> method, bool allowUser = false, bool allowAgent = false) {
        var tokenResult = await _context.UserCredentials.ParseJwtToken(req);

        if (!tokenResult.IsOk) {
            return await _context.RequestHandling.NotOk(req, tokenResult.ErrorV, "token verification", HttpStatusCode.Unauthorized);
        }

        var token = tokenResult.OkV.UserInfo;
        if (await IsUser(tokenResult.OkV)) {
            if (!allowUser) {
                return await Reject(req, token);
            }

            var access = await CheckAccess(req);
            if (!access.IsOk) {
                return await _context.RequestHandling.NotOk(req, access.ErrorV, "access control", HttpStatusCode.Unauthorized);
            }
        }

        if (await IsAgent(tokenResult.OkV) && !allowAgent) {
            return await Reject(req, token);
        }

        return await method(req);
    }

    public async Async.Task<bool> IsUser(UserAuthInfo tokenData) {
        return !await IsAgent(tokenData);
    }

    public async Async.Task<HttpResponseData> Reject(HttpRequestData req, UserInfo token) {
        var body = await req.ReadAsStringAsync();
        _log.Error($"reject token. url:{req.Url:Tag:Url} token:{token:Tag:Token} body:{body:Tag:Body}");

        return await _context.RequestHandling.NotOk(
            req,