Table of Contents

Class CookiePolicyOptionsExtensions

Namespace
Microsoft.Identity.Web
Assembly
Microsoft.Identity.Web.dll

Extension class containing cookie policies (work around for same site).

public static class CookiePolicyOptionsExtensions
Inheritance
CookiePolicyOptionsExtensions
Inherited Members

Methods

DisallowsSameSiteNone(string)

Checks if the specified user agent supports "SameSite=None" cookies.

public static bool DisallowsSameSiteNone(string userAgent)

Parameters

userAgent string

Browser user agent.

Returns

bool

True, if the user agent does not allow "SameSite=None" cookie; otherwise, false.

Remarks

Incompatible user agents include:

  • Versions of Chrome from Chrome 51 to Chrome 66 (inclusive on both ends).
  • Versions of UC Browser on Android prior to version 12.13.2.
  • Versions of Safari and embedded browsers on MacOS 10.14 and all browsers on iOS 12.
Reference: https://www.chromium.org/updates/same-site/incompatible-clients.

HandleSameSiteCookieCompatibility(CookiePolicyOptions)

Handles SameSite cookie issue according to the https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1. The default list of user agents that disallow "SameSite=None", was taken from https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/.

public static CookiePolicyOptions HandleSameSiteCookieCompatibility(this CookiePolicyOptions options)

Parameters

options CookiePolicyOptions

CookiePolicyOptionsto update.

Returns

CookiePolicyOptions

CookiePolicyOptions to chain.

HandleSameSiteCookieCompatibility(CookiePolicyOptions, Func<string, bool>)

Handles SameSite cookie issue according to the docs: https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1 The default list of user agents that disallow "SameSite=None", was taken from https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/.

public static CookiePolicyOptions HandleSameSiteCookieCompatibility(this CookiePolicyOptions options, Func<string, bool> disallowsSameSiteNone)

Parameters

options CookiePolicyOptions

CookiePolicyOptionsto update.

disallowsSameSiteNone Func<string, bool>

If you don't want to use the default user agent list implementation, the method sent in this parameter will be run against the user agent and if returned true, SameSite value will be set to Unspecified. The default user agent list used can be found at: https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/.

Returns

CookiePolicyOptions

CookiePolicyOptions to chain.