diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Mvc.Core/Properties/Resources.Designer.cs
index 887aa1d73d..48d1e9674e 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Properties/Resources.Designer.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Properties/Resources.Designer.cs
@@ -1046,20 +1046,6 @@ internal static string Formatter_NoMediaTypes
internal static string FormatFormatter_NoMediaTypes(object p0, object p1)
=> string.Format(CultureInfo.CurrentCulture, GetString("Formatter_NoMediaTypes"), p0, p1);
- ///
- /// At least one authentication scheme must be specified.
- ///
- internal static string MustSpecifyAtLeastOneAuthenticationScheme
- {
- get => GetString("MustSpecifyAtLeastOneAuthenticationScheme");
- }
-
- ///
- /// At least one authentication scheme must be specified.
- ///
- internal static string FormatMustSpecifyAtLeastOneAuthenticationScheme()
- => GetString("MustSpecifyAtLeastOneAuthenticationScheme");
-
///
/// Could not create a model binder for model object of type '{0}'.
///
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Resources.resx b/src/Microsoft.AspNetCore.Mvc.Core/Resources.resx
index c251ced57a..2202478c35 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Resources.resx
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Resources.resx
@@ -349,9 +349,6 @@
No media types found in '{0}.{1}'. Add at least one media type to the list of supported media types.
-
- At least one authentication scheme must be specified.
-
Could not create a model binder for model object of type '{0}'.
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs
index 17e93b368a..f972b9475c 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs
@@ -17,6 +17,14 @@ namespace Microsoft.AspNetCore.Mvc
///
public class SignOutResult : ActionResult
{
+ ///
+ /// Initializes a new instance of with the default sign out scheme.
+ ///
+ public SignOutResult()
+ : this(Array.Empty())
+ {
+ }
+
///
/// Initializes a new instance of with the
/// specified authentication scheme.
@@ -61,11 +69,6 @@ public SignOutResult(IList authenticationSchemes, AuthenticationProperti
throw new ArgumentNullException(nameof(authenticationSchemes));
}
- if (authenticationSchemes.Count == 0)
- {
- throw new ArgumentException(Resources.MustSpecifyAtLeastOneAuthenticationScheme, nameof(authenticationSchemes));
- }
-
AuthenticationSchemes = authenticationSchemes;
Properties = properties;
}
@@ -96,19 +99,21 @@ public override async Task ExecuteResultAsync(ActionContext context)
/* type: */ nameof(SignOutResult)));
}
- if (AuthenticationSchemes.Count == 0)
- {
- throw new ArgumentException(Resources.MustSpecifyAtLeastOneAuthenticationScheme, nameof(AuthenticationSchemes));
- }
-
var loggerFactory = context.HttpContext.RequestServices.GetRequiredService();
var logger = loggerFactory.CreateLogger();
logger.SignOutResultExecuting(AuthenticationSchemes);
- for (var i = 0; i < AuthenticationSchemes.Count; i++)
+ if (AuthenticationSchemes.Count == 0)
+ {
+ await context.HttpContext.SignOutAsync(Properties);
+ }
+ else
{
- await context.HttpContext.SignOutAsync(AuthenticationSchemes[i], Properties);
+ for (var i = 0; i < AuthenticationSchemes.Count; i++)
+ {
+ await context.HttpContext.SignOutAsync(AuthenticationSchemes[i], Properties);
+ }
}
}
}
diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/SignOutResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/SignOutResultTest.cs
index f2615fc841..fe690c6ef4 100644
--- a/test/Microsoft.AspNetCore.Mvc.Core.Test/SignOutResultTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/SignOutResultTest.cs
@@ -17,6 +17,32 @@ namespace Microsoft.AspNetCore.Mvc
{
public class SignOutResultTest
{
+ [Fact]
+ public async Task ExecuteResultAsync_NoArgsInvokesDefaultSignOut()
+ {
+ // Arrange
+ var httpContext = new Mock();
+ var auth = new Mock();
+ auth
+ .Setup(c => c.SignOutAsync(httpContext.Object, null, null))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
+ httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
+ var result = new SignOutResult();
+ var routeData = new RouteData();
+
+ var actionContext = new ActionContext(
+ httpContext.Object,
+ routeData,
+ new ActionDescriptor());
+
+ // Act
+ await result.ExecuteResultAsync(actionContext);
+
+ // Assert
+ auth.Verify();
+ }
+
[Fact]
public async Task ExecuteResultAsync_InvokesSignOutAsyncOnAuthenticationManager()
{
diff --git a/test/WebSites/RazorPagesWebSite/Startup.cs b/test/WebSites/RazorPagesWebSite/Startup.cs
index 8c3445f82b..c917328e6d 100644
--- a/test/WebSites/RazorPagesWebSite/Startup.cs
+++ b/test/WebSites/RazorPagesWebSite/Startup.cs
@@ -10,9 +10,8 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
- services
- .AddCookieAuthentication(options => options.LoginPath = "/Login")
- .AddMvc()
+ services.AddAuthentication().AddCookie(options => options.LoginPath = "/Login");
+ services.AddMvc()
.AddCookieTempDataProvider()
.AddRazorPagesOptions(options =>
{
diff --git a/test/WebSites/RazorPagesWebSite/StartupWithBasePath.cs b/test/WebSites/RazorPagesWebSite/StartupWithBasePath.cs
index cafae0f4fd..93a058fe81 100644
--- a/test/WebSites/RazorPagesWebSite/StartupWithBasePath.cs
+++ b/test/WebSites/RazorPagesWebSite/StartupWithBasePath.cs
@@ -10,9 +10,9 @@ public class StartupWithBasePath
{
public void ConfigureServices(IServiceCollection services)
{
- services
- .AddCookieAuthentication(options => options.LoginPath = "/Login")
- .AddMvc()
+ services.AddAuthentication()
+ .AddCookie(options => options.LoginPath = "/Login");
+ services.AddMvc()
.AddCookieTempDataProvider()
.AddRazorPagesOptions(options =>
{
diff --git a/test/WebSites/SecurityWebSite/Startup.cs b/test/WebSites/SecurityWebSite/Startup.cs
index 9c2c9b2b20..0ba466b343 100644
--- a/test/WebSites/SecurityWebSite/Startup.cs
+++ b/test/WebSites/SecurityWebSite/Startup.cs
@@ -14,7 +14,7 @@ public void ConfigureServices(IServiceCollection services)
// Add framework services.
services.AddMvc();
services.AddAntiforgery();
- services.AddCookieAuthentication(options =>
+ services.AddAuthentication().AddCookie(options =>
{
options.LoginPath = "/Home/Login";
options.LogoutPath = "/Home/Logout";