// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; using Microsoft.AspNetCore.Http; namespace Microsoft.AspNetCore.Antiforgery { /// /// Provides access to the antiforgery system, which provides protection against /// Cross-site Request Forgery (XSRF, also called CSRF) attacks. /// public interface IAntiforgery { /// /// Generates an for this request and stores the cookie token /// in the response. This operation also sets the "Cache-control" and "Pragma" headers to "no-cache" and /// the "X-Frame-Options" header to "SAMEORIGIN". /// /// The associated with the current request. /// An with tokens for the response. /// /// This method has a side effect: /// A response cookie is set if there is no valid cookie associated with the request. /// AntiforgeryTokenSet GetAndStoreTokens(HttpContext httpContext); /// /// Generates an for this request. /// /// The associated with the current request. /// /// Unlike , this method has no side effect. The caller /// is responsible for setting the response cookie and injecting the returned /// form token as appropriate. /// AntiforgeryTokenSet GetTokens(HttpContext httpContext); /// /// Asynchronously returns a value indicating whether the request passes antiforgery validation. If the /// request uses a safe HTTP method (GET, HEAD, OPTIONS, TRACE), the antiforgery token is not validated. /// /// The associated with the current request. /// /// A that, when completed, returns true if the request uses a safe HTTP /// method or contains a valid antiforgery token, otherwise returns false. /// Task IsRequestValidAsync(HttpContext httpContext); /// /// Validates an antiforgery token that was supplied as part of the request. /// /// The associated with the current request. /// /// Thrown when the request does not include a valid antiforgery token. /// Task ValidateRequestAsync(HttpContext httpContext); /// /// Generates and stores an antiforgery cookie token if one is not available or not valid. /// /// The associated with the current request. void SetCookieTokenAndHeader(HttpContext httpContext); } }