UmbracoApiController and Custom AntiForgeryToken Validator
Hi,
im currently developing a Web Application with Umbraco and Angular. I would like to secure my input Fields with the Microsoft AntiForgeryToken, i was able to create this Token, but unable to Validate it. I added a custom AntiForgeryTokenValidator to the UmbracoApiController
namespace Project.Controllers.APIs
{
[AdfsAuthorize]
[MyValidateAntiForgeryToken]
public class HelperApiController : UmbracoApiController
{
But this Validator is not getting called.
using System;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using static System.String;
namespace Project.Filters
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MyValidateAntiForgeryTokenAttribute : FilterAttribute, IAuthorizationFilter
{
private void ValidateRequestHeader(HttpRequestBase request)
{
var cookieToken = Empty;
var formToken = Empty;
var tokenValue = request.Headers["RequestVerificationToken"];
if (!IsNullOrEmpty(tokenValue))
{
var tokens = tokenValue.Split(':');
if (tokens.Length == 2)
{
cookieToken = tokens[0].Trim();
formToken = tokens[1].Trim();
}
}
AntiForgery.Validate(cookieToken, formToken);
}
public void OnAuthorization(AuthorizationContext filterContext)
{
try
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
ValidateRequestHeader(filterContext.HttpContext.Request);
}
else
{
AntiForgery.Validate();
}
}
catch (HttpAntiForgeryException e)
{
throw new HttpAntiForgeryException("Anti forgery token cookie not found");
}
}
}
}
The same applies to the the AdfsAuthorize Attibute.
The Project is currently on Umbraco 7.5.2.
Do you guys have any idea or possible solution for me?
UmbracoApiController and Custom AntiForgeryToken Validator
Hi,
im currently developing a Web Application with Umbraco and Angular. I would like to secure my input Fields with the Microsoft AntiForgeryToken, i was able to create this Token, but unable to Validate it. I added a custom AntiForgeryTokenValidator to the UmbracoApiController
But this Validator is not getting called.
The same applies to the the AdfsAuthorize Attibute.
The Project is currently on Umbraco 7.5.2.
Do you guys have any idea or possible solution for me?
Best regards from Germany
Malte
Hi Malte,
I'm using the folling attribute to do custom antiforgery validation:
Maybe that helps.
Regard David
Hi David,
thanks for your response. The Problem now is that VS is saying this method is missing:
How do i wire this up correctly?
Regards Malte
Hi all,
@Marcel Wege found the Problem, it was due to the fact that i used
after i change the FilterAttribute namespace to
it all worked fine.
is working on a reply...