diff --git a/src/Security/Authentication/Certificate/src/CertificateAuthenticationOptions.cs b/src/Security/Authentication/Certificate/src/CertificateAuthenticationOptions.cs
index 693dd5da942a..cdb6598cf62a 100644
--- a/src/Security/Authentication/Certificate/src/CertificateAuthenticationOptions.cs
+++ b/src/Security/Authentication/Certificate/src/CertificateAuthenticationOptions.cs
@@ -10,6 +10,14 @@ namespace Microsoft.AspNetCore.Authentication.Certificate;
///
public class CertificateAuthenticationOptions : AuthenticationSchemeOptions
{
+ ///
+ /// Initializes a new instance of .
+ ///
+ public CertificateAuthenticationOptions()
+ {
+ Events = new CertificateAuthenticationEvents();
+ }
+
///
/// Value indicating the types of certificates accepted by the authentication middleware.
///
diff --git a/src/Security/Authentication/JwtBearer/src/JwtBearerOptions.cs b/src/Security/Authentication/JwtBearer/src/JwtBearerOptions.cs
index f5b56ed32531..c4142a40da73 100644
--- a/src/Security/Authentication/JwtBearer/src/JwtBearerOptions.cs
+++ b/src/Security/Authentication/JwtBearer/src/JwtBearerOptions.cs
@@ -32,6 +32,7 @@ public JwtBearerOptions()
SecurityTokenValidators = new List { _defaultHandler };
#pragma warning restore CS0618 // Type or member is obsolete
TokenHandlers = new List { _defaultTokenHandler };
+ Events = new JwtBearerEvents();
}
///
diff --git a/src/Security/Authentication/Negotiate/src/NegotiateOptions.cs b/src/Security/Authentication/Negotiate/src/NegotiateOptions.cs
index b170eeb6b7e4..b4fe727ad813 100644
--- a/src/Security/Authentication/Negotiate/src/NegotiateOptions.cs
+++ b/src/Security/Authentication/Negotiate/src/NegotiateOptions.cs
@@ -8,6 +8,14 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate;
///
public class NegotiateOptions : AuthenticationSchemeOptions
{
+ ///
+ /// Initializes a new instance of .
+ ///
+ public NegotiateOptions()
+ {
+ Events = new NegotiateEvents();
+ }
+
///
/// The object provided by the application to process events raised by the negotiate authentication handler.
/// The application may use the existing NegotiateEvents instance and assign delegates only to the events it
diff --git a/src/Security/Authentication/Negotiate/test/Negotiate.Test/NegotiateHandlerTests.cs b/src/Security/Authentication/Negotiate/test/Negotiate.Test/NegotiateHandlerTests.cs
index 1d9ae1ae0356..df34ce9a84ad 100644
--- a/src/Security/Authentication/Negotiate/test/Negotiate.Test/NegotiateHandlerTests.cs
+++ b/src/Security/Authentication/Negotiate/test/Negotiate.Test/NegotiateHandlerTests.cs
@@ -20,6 +20,13 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate;
public class NegotiateHandlerTests
{
+ [Fact]
+ public void EventsPropertyIsInitializedOnConstruction()
+ {
+ var options = new NegotiateOptions();
+ Assert.NotNull(options.Events);
+ }
+
[Fact]
public async Task Anonymous_MissingConnectionFeatures_ThrowsNotSupported()
{
diff --git a/src/Security/Authentication/test/BearerTokenTests.cs b/src/Security/Authentication/test/BearerTokenTests.cs
index 08ee3bb8511e..d5aa657de398 100644
--- a/src/Security/Authentication/test/BearerTokenTests.cs
+++ b/src/Security/Authentication/test/BearerTokenTests.cs
@@ -23,4 +23,11 @@ protected override void RegisterAuth(AuthenticationBuilder services, Action
protected override void RegisterAuth(AuthenticationBuilder services, Action configure)
{
- services.AddJwtBearer(o =>
- {
- ConfigureDefaults(o);
- configure.Invoke(o);
- });
+ services.AddJwtBearer(configure);
}
- private void ConfigureDefaults(JwtBearerOptions o)
+ [Fact]
+ public void EventsPropertyIsInitializedOnConstruction()
{
+ var options = new JwtBearerOptions();
+ Assert.NotNull(options.Events);
}
[Fact]
diff --git a/src/Security/Authentication/test/MicrosoftAccountTests.cs b/src/Security/Authentication/test/MicrosoftAccountTests.cs
index 91e9fa4e9f1a..97517451fa14 100644
--- a/src/Security/Authentication/test/MicrosoftAccountTests.cs
+++ b/src/Security/Authentication/test/MicrosoftAccountTests.cs
@@ -43,6 +43,13 @@ protected override void ConfigureDefaults(MicrosoftAccountOptions o)
o.SignInScheme = "auth1";
}
+ [Fact]
+ public void EventsPropertyIsInitializedOnConstruction()
+ {
+ var options = new MicrosoftAccountOptions();
+ Assert.NotNull(options.Events);
+ }
+
[Fact]
public async Task ChallengeWillTriggerApplyRedirectEvent()
{
diff --git a/src/Security/Authentication/test/OAuthTests.cs b/src/Security/Authentication/test/OAuthTests.cs
index 43463f2e15bf..3349ae96b6ec 100644
--- a/src/Security/Authentication/test/OAuthTests.cs
+++ b/src/Security/Authentication/test/OAuthTests.cs
@@ -31,6 +31,13 @@ protected override void RegisterAuth(AuthenticationBuilder services, Action
/// Tests RedirectForSignOutContext replaces the OpenIdConnectMesssage correctly.
///
diff --git a/src/Security/Authentication/test/TwitterTests.cs b/src/Security/Authentication/test/TwitterTests.cs
index d70230e53c4e..3e6e6174d8fd 100644
--- a/src/Security/Authentication/test/TwitterTests.cs
+++ b/src/Security/Authentication/test/TwitterTests.cs
@@ -41,6 +41,13 @@ protected override void ConfigureDefaults(TwitterOptions o)
o.SignInScheme = "auth1";
}
+ [Fact]
+ public void EventsPropertyIsInitializedOnConstruction()
+ {
+ var options = new TwitterOptions();
+ Assert.NotNull(options.Events);
+ }
+
[Fact]
public async Task ChallengeWillTriggerApplyRedirectEvent()
{
diff --git a/src/Security/Authentication/test/WsFederation/WsFederationTest.cs b/src/Security/Authentication/test/WsFederation/WsFederationTest.cs
index 6ea9ebdb733e..b4b561b7718d 100644
--- a/src/Security/Authentication/test/WsFederation/WsFederationTest.cs
+++ b/src/Security/Authentication/test/WsFederation/WsFederationTest.cs
@@ -23,6 +23,13 @@ namespace Microsoft.AspNetCore.Authentication.WsFederation;
public class WsFederationTest
{
+ [Fact]
+ public void EventsPropertyIsInitializedOnConstruction()
+ {
+ var options = new WsFederationOptions();
+ Assert.NotNull(options.Events);
+ }
+
[Fact]
public async Task VerifySchemeDefaults()
{