JasperFx/alba

How to setup properly X-XSRF-TOKEN header for ValidateAntiForgeryToken?

AdaskoTheBeAsT opened this issue · 1 comments

for now I tried to do some preflight to "get" endpoint and extract value from cookie

var setCookieHeaderValues = result.Context.Response.GetTypedHeaders().SetCookie;
        var xsrfTokenCookie = setCookieHeaderValues.First(v => v.Name.Equals(XsrfCookieName, StringComparison.OrdinalIgnoreCase));
        XsrfTokenValue = xsrfTokenCookie.Value.Value;

and then use XsrfTokenValue

    _.WithRequestHeader(XsrfHeaderName, XsrfTokenValue ?? string.Empty);
    _.Post.Json(request).ToUrl("/api/<some endpoint>");

for now I receive 400
not sure if I missed something (without ValidateAntiForgeryToken attribute it works so it is only problem with antiforgery)

Do you have any tips?

ok found it - I need to also save whole cookie and add it in request