From ac702f68189dca89b621dc9f144d03b2677c090e Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Thu, 16 Nov 2017 21:27:05 -0800 Subject: [PATCH] Add the cookie IsEssential flag and feature --- .../CookieBuilder.cs | 7 ++++ .../CookieOptions.cs | 6 +++ .../ITrackingConsentFeature.cs | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.cs diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs b/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs index 203a7a0402..ce89e5b054 100644 --- a/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs +++ b/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs @@ -72,6 +72,12 @@ namespace Microsoft.AspNetCore.Http /// public virtual TimeSpan? MaxAge { get; set; } + /// + /// Indicates if this cookie is essential for the application to function correctly. If true then + /// consent policy checks may be bypassed. The default value is false. + /// + public virtual bool IsEssential { get; set; } + /// /// Creates the cookie options from the given . /// @@ -99,6 +105,7 @@ namespace Microsoft.AspNetCore.Http HttpOnly = HttpOnly, MaxAge = MaxAge, Domain = Domain, + IsEssential = IsEssential, Secure = SecurePolicy == CookieSecurePolicy.Always || (SecurePolicy == CookieSecurePolicy.SameAsRequest && context.Request.IsHttps), Expires = Expiration.HasValue ? expiresFrom.Add(Expiration.Value) : default(DateTimeOffset?) }; diff --git a/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs b/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs index e01a759c8f..27141a32f2 100644 --- a/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs +++ b/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs @@ -59,5 +59,11 @@ namespace Microsoft.AspNetCore.Http /// /// The max-age date and time for the cookie. public TimeSpan? MaxAge { get; set; } + + /// + /// Indicates if this cookie is essential for the application to function correctly. If true then + /// consent policy checks may be bypassed. The default value is false. + /// + public bool IsEssential { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.cs b/src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.cs new file mode 100644 index 0000000000..9e5108db43 --- /dev/null +++ b/src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.cs @@ -0,0 +1,39 @@ +// 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. + +namespace Microsoft.AspNetCore.Http.Features +{ + /// + /// Used to query, grant, and withdraw user consent regarding the storage of user + /// information related to site activity and functionality. + /// + public interface ITrackingConsentFeature + { + /// + /// Indicates if consent is required for the given request. + /// + bool IsConsentNeeded { get; } + + /// + /// Indicates if consent was given. + /// + bool HasConsent { get; } + + /// + /// Indicates either if consent has been given or if consent is not required. + /// + bool CanTrack { get; } + + /// + /// Grants consent for this request. If the response has not yet started then + /// this will also grant consent for future requests. + /// + void GrantConsent(); + + /// + /// Withdraws consent for this request. If the response has not yet started then + /// this will also withdraw consent for future requests. + /// + void WithdrawConsent(); + } +}