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

Code before:
        _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,
            new Error(
                ErrorCode.UNAUTHORIZED,
                new string[] { "Unrecognized agent" }
            ),
            "token verification",
            HttpStatusCode.Unauthorized
        );
    }

    public async Async.Task<OneFuzzResultVoid> CheckRequireAdmins(HttpRequestData req) {

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

Code after:
        _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,
            new Error(
                ErrorCode.UNAUTHORIZED,
                new string[] { "Unrecognized agent" }
            ),
            "token verification",
            HttpStatusCode.Unauthorized
        );
    }

    public async Async.Task<OneFuzzResultVoid> CheckRequireAdmins(HttpRequestData req) {