-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
AbpAntiForgeryOptions.cs
66 lines (56 loc) · 2.01 KB
/
AbpAntiForgeryOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Http;
namespace Volo.Abp.AspNetCore.Mvc.AntiForgery;
public class AbpAntiForgeryOptions
{
/// <summary>
/// Use to set the cookie options to transfer Anti Forgery token between server and client.
/// Default name of the cookie: "XSRF-TOKEN".
/// </summary>
public CookieBuilder TokenCookie { get; }
/// <summary>
/// Used to find auth cookie when validating Anti Forgery token.
/// Default value: "Identity.Application".
/// </summary>
public string AuthCookieSchemaName { get; set; }
/// <summary>
/// Default value: true.
/// </summary>
public bool AutoValidate { get; set; } = true;
/// <summary>
/// A predicate to filter types to auto-validate.
/// Return true to select the type to validate.
/// Default: returns true for all given types.
/// </summary>
[NotNull]
public Predicate<Type> AutoValidateFilter {
get => _autoValidateFilter;
set => _autoValidateFilter = Check.NotNull(value, nameof(value));
}
private Predicate<Type> _autoValidateFilter;
/// <summary>
/// Default methods: "GET", "HEAD", "TRACE", "OPTIONS".
/// </summary>
[NotNull]
public HashSet<string> AutoValidateIgnoredHttpMethods {
get => _autoValidateIgnoredHttpMethods;
set => _autoValidateIgnoredHttpMethods = Check.NotNull(value, nameof(value));
}
private HashSet<string> _autoValidateIgnoredHttpMethods;
public AbpAntiForgeryOptions()
{
AutoValidateFilter = type => true;
TokenCookie = new CookieBuilder
{
Name = "XSRF-TOKEN",
HttpOnly = false,
IsEssential = true,
SameSite = SameSiteMode.None,
Expiration = TimeSpan.FromDays(3650) //10 years!
};
AuthCookieSchemaName = "Identity.Application";
AutoValidateIgnoredHttpMethods = new HashSet<string> { "GET", "HEAD", "TRACE", "OPTIONS" };
}
}