using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace Kreta.Web.Security
{
///
/// Allow only local requests
///
public class LocalRequestOnlyAttribute : ActionFilterAttribute
{
///
/// Authorization event
///
/// Context of the current action
/// Cancellation token
///
public override Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
{
if (!actionContext.RequestContext.IsLocal)
{
actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Forbidden);
}
return base.OnActionExecutingAsync(actionContext, cancellationToken);
}
}
}