We have an ASP.NET Core 2.2 web application with an Angular SPA using cookie authentication.
I'm following the documentation to configure antiforgery features with IAntiforgery.
The relevant code snippets are:
services.AddAntiforgery();
public void Configure(IApplicationBuilder app, IAntiforgery antiforgery)
{
app.Use(next => context =>
{
string path = context.Request.Path.Value;
if (
string.Equals(path, "/", StringComparison.OrdinalIgnoreCase) ||
string.Equals(path, "/index.html", StringComparison.OrdinalIgnoreCase))
{
// The request token can be sent as a JavaScript-readable cookie,
// and Angular uses it by default.
var tokens = antiforgery.GetAndStoreTokens(context);
context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken,
new CookieOptions() { HttpOnly = false });
}
return next(context);
});
}
The call to antiforgery.GetAndStoreTokens(context) returns an AntiforgeryTokenSet which has RequestToken and CookieToken properties.
If I use the code above with the default configuration, I get two cookies: .AspNetCore.Antiforgery.* (matching CookieToken) and XSRF-TOKEN (matching RequestToken), with different values.
What's the difference in usage between the RequestToken and CookieToken