/// <inheritdoc />
        public async Task <AuthorizationResult> Evaluate(
            ClaimsPrincipal principal,
            IDictionary <string, object> userContext,
            IReadOnlyDictionary <string, object> inputs,
            IEnumerable <string> requiredPolicies)
        {
            if (requiredPolicies == null)
            {
                return(AuthorizationResult.Success());
            }

            var context = new AuthorizationContext
            {
                User        = principal ?? new ClaimsPrincipal(new ClaimsIdentity()),
                UserContext = userContext,
                Inputs      = inputs
            };

            var tasks = new List <Task>();

            foreach (string requiredPolicy in requiredPolicies)
            {
                var authorizationPolicy = _settings.GetPolicy(requiredPolicy);
                if (authorizationPolicy == null)
                {
                    context.ReportError($"Required policy '{requiredPolicy}' is not present.");
                }
                else
                {
                    foreach (var r in authorizationPolicy.Requirements)
                    {
                        var task = r.Authorize(context);
                        tasks.Add(task);
                    }
                }
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);

            return(context.HasErrors
                ? AuthorizationResult.Fail(context.Errors)
                : AuthorizationResult.Success());
        }
        public async Task <AuthorizationResult> Evaluate(
            ClaimsPrincipal principal,
            object userContext,
            IDictionary <string, object> inputVariables,
            IEnumerable <string> requiredPolicies)
        {
            var context = new AuthorizationContext
            {
                User           = principal ?? new ClaimsPrincipal(new ClaimsIdentity()),
                UserContext    = userContext,
                InputVariables = inputVariables
            };

            var tasks = new List <Task>();

            requiredPolicies?.ToList()
            .Apply(requiredPolicy =>
            {
                var authorizationPolicy = _settings.GetPolicy(requiredPolicy);
                if (authorizationPolicy == null)
                {
                    context.ReportError($"Required policy '{requiredPolicy}' is not present.");
                }
                else
                {
                    authorizationPolicy.Requirements.Apply(r =>
                    {
                        var task = r.Authorize(context);
                        tasks.Add(task);
                    });
                }
            });

            await Task.WhenAll(tasks.ToArray());

            return(!context.HasErrors
                ? AuthorizationResult.Success()
                : AuthorizationResult.Fail(context.Errors));
        }