Skip to content

Commit a218c3b

Browse files
authored
Add docs to CookiePolicy (#26446)
* Add docs to CookiePolicy Contributes to #26397 * Apply suggestions from code review
1 parent 66584a0 commit a218c3b

File tree

6 files changed

+116
-6
lines changed

6 files changed

+116
-6
lines changed
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Http;
56

67
namespace Microsoft.AspNetCore.CookiePolicy
78
{
9+
/// <summary>
10+
/// Context for <see cref="CookiePolicyOptions.OnAppendCookie"/> that allows changes to the cookie prior to being appended.
11+
/// </summary>
812
public class AppendCookieContext
913
{
14+
/// <summary>
15+
/// Initializes a new instance of <see cref="AppendCookieContext"/>.
16+
/// </summary>
17+
/// <param name="context">The request <see cref="HttpContext"/>.</param>
18+
/// <param name="options">The <see cref="Http.CookieOptions"/> passed to the cookie policy.</param>
19+
/// <param name="name">The cookie name.</param>
20+
/// <param name="value">The cookie value.</param>
1021
public AppendCookieContext(HttpContext context, CookieOptions options, string name, string value)
1122
{
1223
Context = context;
@@ -15,12 +26,40 @@ public AppendCookieContext(HttpContext context, CookieOptions options, string na
1526
CookieValue = value;
1627
}
1728

29+
/// <summary>
30+
/// Gets the <see cref="HttpContext"/>.
31+
/// </summary>
1832
public HttpContext Context { get; }
33+
34+
/// <summary>
35+
/// Gets the <see cref="Http.CookieOptions"/>.
36+
/// </summary>
1937
public CookieOptions CookieOptions { get; }
38+
39+
/// <summary>
40+
/// Gets or sets the cookie name.
41+
/// </summary>
2042
public string CookieName { get; set; }
43+
44+
/// <summary>
45+
/// Gets or sets the cookie value.
46+
/// </summary>
2147
public string CookieValue { get; set; }
48+
49+
/// <summary>
50+
/// Gets a value that determines if cookie consent is required before setting this cookie.
51+
/// </summary>
2252
public bool IsConsentNeeded { get; internal set; }
53+
54+
/// <summary>
55+
/// Gets a value that determines if cookie consent was provided.
56+
/// </summary>
2357
public bool HasConsent { get; internal set; }
58+
59+
/// <summary>
60+
/// Gets or sets a value that determines if the cookie can be appended. If set to <see langword="false" />,
61+
/// the cookie is not appended.
62+
/// </summary>
2463
public bool IssueCookie { get; set; }
2564
}
26-
}
65+
}

src/Security/CookiePolicy/src/CookiePolicyMiddleware.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,48 @@
1212

1313
namespace Microsoft.AspNetCore.CookiePolicy
1414
{
15+
/// <summary>
16+
/// Initializes a new instance of <see cref="CookiePolicyMiddleware"/>.
17+
/// </summary>
1518
public class CookiePolicyMiddleware
1619
{
1720
private readonly RequestDelegate _next;
1821
private readonly ILogger _logger;
1922

23+
/// <summary>
24+
/// Initializes a new instance of <see cref="CookiePolicyMiddleware"/>.
25+
/// </summary>
26+
/// <param name="next">A reference to the next item in the application pipeline.</param>
27+
/// <param name="options">Accessor to <see cref="CookiePolicyOptions"/>.</param>
28+
/// <param name="factory">The <see cref="ILoggerFactory"/>.</param>
2029
public CookiePolicyMiddleware(RequestDelegate next, IOptions<CookiePolicyOptions> options, ILoggerFactory factory)
2130
{
2231
Options = options.Value;
2332
_next = next ?? throw new ArgumentNullException(nameof(next));
2433
_logger = factory.CreateLogger<CookiePolicyMiddleware>();
2534
}
2635

36+
/// <summary>
37+
/// Initializes a new instance of <see cref="CookiePolicyMiddleware"/>.
38+
/// </summary>
39+
/// <param name="next">A reference to the next item in the application pipeline.</param>
40+
/// <param name="options">Accessor to <see cref="CookiePolicyOptions"/>.</param>
2741
public CookiePolicyMiddleware(RequestDelegate next, IOptions<CookiePolicyOptions> options)
2842
{
2943
Options = options.Value;
3044
_next = next;
3145
_logger = NullLogger.Instance;
3246
}
3347

48+
/// <summary>
49+
/// Gets or sets the <see cref="CookiePolicyOptions"/>.
50+
/// </summary>
3451
public CookiePolicyOptions Options { get; set; }
3552

53+
/// <summary>
54+
/// Invokes the middleware.
55+
/// </summary>
56+
/// <param name="context">The <see cref="HttpContext" />.</param>
3657
public Task Invoke(HttpContext context)
3758
{
3859
var feature = context.Features.Get<IResponseCookiesFeature>() ?? new ResponseCookiesFeature(context.Features);
@@ -53,4 +74,4 @@ public CookiesWrapperFeature(ResponseCookiesWrapper wrapper)
5374
public IResponseCookies Cookies { get; }
5475
}
5576
}
56-
}
77+
}

src/Security/CookiePolicy/src/CookiePolicyOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class CookiePolicyOptions
2727
/// </summary>
2828
public CookieSecurePolicy Secure { get; set; } = CookieSecurePolicy.None;
2929

30+
/// <summary>
31+
/// Gets or sets the <see cref="CookieBuilder"/> that is used to track if the user consented to the
32+
/// cookie use policy.
33+
/// </summary>
3034
public CookieBuilder ConsentCookie { get; set; } = new CookieBuilder()
3135
{
3236
Name = ".AspNet.Consent",
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Http;
56

67
namespace Microsoft.AspNetCore.CookiePolicy
78
{
9+
/// <summary>
10+
/// Context for <see cref="CookiePolicyOptions.OnDeleteCookie"/> that allows changes to the cookie prior to being deleted.
11+
/// </summary>
812
public class DeleteCookieContext
913
{
14+
/// <summary>
15+
/// Initializes a new instance of <see cref="DeleteCookieContext"/>.
16+
/// </summary>
17+
/// <param name="context">The request <see cref="HttpContext"/>.</param>
18+
/// <param name="options">The <see cref="Http.CookieOptions"/> passed to the cookie policy.</param>
19+
/// <param name="name">The cookie name to be deleted.</param>
1020
public DeleteCookieContext(HttpContext context, CookieOptions options, string name)
1121
{
1222
Context = context;
1323
CookieOptions = options;
1424
CookieName = name;
1525
}
1626

27+
/// <summary>
28+
/// Gets the <see cref="HttpContext"/>.
29+
/// </summary>
1730
public HttpContext Context { get; }
31+
32+
/// <summary>
33+
/// Gets the <see cref="Http.CookieOptions"/>.
34+
/// </summary>
1835
public CookieOptions CookieOptions { get; }
36+
37+
/// <summary>
38+
/// Gets or sets the cookie name.
39+
/// </summary>
1940
public string CookieName { get; set; }
41+
42+
/// <summary>
43+
/// Gets a value that determines if cookie consent is required before setting this cookie.
44+
/// </summary>
2045
public bool IsConsentNeeded { get; internal set; }
46+
47+
/// <summary>
48+
/// Gets a value that determines if cookie consent was provided.
49+
/// </summary>
2150
public bool HasConsent { get; internal set; }
51+
52+
/// <summary>
53+
/// Gets or sets a value that determines if the cookie can be deleted. If set to <see langword="false" />,
54+
/// cookie deletion is suppressed.
55+
/// </summary>
2256
public bool IssueCookie { get; set; }
2357
}
24-
}
58+
}

src/Security/CookiePolicy/src/HttpOnlyPolicy.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33

44
namespace Microsoft.AspNetCore.CookiePolicy
55
{
6+
/// <summary>
7+
/// Describes the HttpOnly behavior for cookies.
8+
/// </summary>
69
public enum HttpOnlyPolicy
710
{
11+
/// <summary>
12+
/// The cookie does not have a configured HttpOnly behavior. This cookie can be accessed by
13+
/// JavaScript <c>document.cookie</c> API.
14+
/// </summary>
815
None,
16+
17+
/// <summary>
18+
/// The cookie is configured with a HttpOnly attribute. This cookie inaccessible to the
19+
/// JavaScript <c>document.cookie</c> API.
20+
/// </summary>
921
Always
1022
}
11-
}
23+
}

src/Security/CookiePolicy/src/Microsoft.AspNetCore.CookiePolicy.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>ASP.NET Core cookie policy classes to control the behavior of cookies.</Description>
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<IsAspNetCoreApp>true</IsAspNetCoreApp>
7-
<NoWarn>$(NoWarn);CS1591</NoWarn>
7+
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<PackageTags>aspnetcore</PackageTags>
1010
<IsPackable>false</IsPackable>

0 commit comments

Comments
 (0)