Skip to content

Commit c0e2ad5

Browse files
author
Tiago Brenck
committed
Added comments
1 parent 08b13c0 commit c0e2ad5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

1-WebApp-OIDC/1-1-MyOrg/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public void ConfigureServices(IServiceCollection services)
2727
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
2828
options.CheckConsentNeeded = context => true;
2929
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
30+
// Handling SameSite cookie according to https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
3031
options.HandleSameSiteCookieCompatibility();
3132
});
3233

Microsoft.Identity.Web/WebAppServiceCollectionExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,24 @@ public static IServiceCollection AddMsal(this IServiceCollection services, IConf
163163
return services;
164164
}
165165

166+
/// <summary>
167+
/// Handles SameSite cookie issue according to the https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1.
168+
/// 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/
169+
/// </summary>
170+
/// <param name="options"></param>
171+
/// <returns></returns>
166172
public static CookiePolicyOptions HandleSameSiteCookieCompatibility(this CookiePolicyOptions options)
167173
{
168174
return HandleSameSiteCookieCompatibility(options, DisallowsSameSiteNone);
169175
}
170176

177+
/// <summary>
178+
/// Handles SameSite cookie issue according to the docs: https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
179+
/// 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/
180+
/// </summary>
181+
/// <param name="options"></param>
182+
/// <param name="disallowsSameSiteNone">If you dont 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/</param>
183+
/// <returns></returns>
171184
public static CookiePolicyOptions HandleSameSiteCookieCompatibility(this CookiePolicyOptions options, Func<string, bool> disallowsSameSiteNone)
172185
{
173186
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
@@ -190,6 +203,7 @@ private static void CheckSameSite(HttpContext httpContext, CookieOptions options
190203
}
191204
}
192205

206+
// Method taken from https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/
193207
public static bool DisallowsSameSiteNone(string userAgent)
194208
{
195209
// Cover all iOS based browsers here. This includes:

0 commit comments

Comments
 (0)