Skip to content

Commit b7bc579

Browse files
authored
Update all built-in AuthenticationSchemeOptions to initialize Events (#62595)
1 parent 20d4a00 commit b7bc579

File tree

15 files changed

+98
-6
lines changed

15 files changed

+98
-6
lines changed

src/Security/Authentication/Certificate/src/CertificateAuthenticationOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ namespace Microsoft.AspNetCore.Authentication.Certificate;
1010
/// </summary>
1111
public class CertificateAuthenticationOptions : AuthenticationSchemeOptions
1212
{
13+
/// <summary>
14+
/// Initializes a new instance of <see cref="CertificateAuthenticationOptions"/>.
15+
/// </summary>
16+
public CertificateAuthenticationOptions()
17+
{
18+
Events = new CertificateAuthenticationEvents();
19+
}
20+
1321
/// <summary>
1422
/// Value indicating the types of certificates accepted by the authentication middleware.
1523
/// </summary>

src/Security/Authentication/JwtBearer/src/JwtBearerOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public JwtBearerOptions()
3232
SecurityTokenValidators = new List<ISecurityTokenValidator> { _defaultHandler };
3333
#pragma warning restore CS0618 // Type or member is obsolete
3434
TokenHandlers = new List<TokenHandler> { _defaultTokenHandler };
35+
Events = new JwtBearerEvents();
3536
}
3637

3738
/// <summary>

src/Security/Authentication/Negotiate/src/NegotiateOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate;
88
/// </summary>
99
public class NegotiateOptions : AuthenticationSchemeOptions
1010
{
11+
/// <summary>
12+
/// Initializes a new instance of <see cref="NegotiateOptions"/>.
13+
/// </summary>
14+
public NegotiateOptions()
15+
{
16+
Events = new NegotiateEvents();
17+
}
18+
1119
/// <summary>
1220
/// The object provided by the application to process events raised by the negotiate authentication handler.
1321
/// The application may use the existing NegotiateEvents instance and assign delegates only to the events it

src/Security/Authentication/Negotiate/test/Negotiate.Test/NegotiateHandlerTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate;
2020

2121
public class NegotiateHandlerTests
2222
{
23+
[Fact]
24+
public void EventsPropertyIsInitializedOnConstruction()
25+
{
26+
var options = new NegotiateOptions();
27+
Assert.NotNull(options.Events);
28+
}
29+
2330
[Fact]
2431
public async Task Anonymous_MissingConnectionFeatures_ThrowsNotSupported()
2532
{

src/Security/Authentication/test/BearerTokenTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ protected override void RegisterAuth(AuthenticationBuilder services, Action<Bear
2323
{
2424
services.AddBearerToken(configure);
2525
}
26+
27+
[Fact]
28+
public void EventsPropertyIsInitializedOnConstruction()
29+
{
30+
var options = new BearerTokenOptions();
31+
Assert.NotNull(options.Events);
32+
}
2633
}

src/Security/Authentication/test/CertificateTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test;
2222

2323
public class ClientCertificateAuthenticationTests
2424
{
25+
[Fact]
26+
public void EventsPropertyIsInitializedOnConstruction()
27+
{
28+
var options = new CertificateAuthenticationOptions();
29+
Assert.NotNull(options.Events);
30+
}
2531

2632
[Fact]
2733
public async Task VerifySchemeDefaults()

src/Security/Authentication/test/CookieTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ protected override void RegisterAuth(AuthenticationBuilder services, Action<Cook
3232
services.AddCookie(configure);
3333
}
3434

35+
[Fact]
36+
public void EventsPropertyIsInitializedOnConstruction()
37+
{
38+
var options = new CookieAuthenticationOptions();
39+
Assert.NotNull(options.Events);
40+
}
41+
3542
[Fact]
3643
public async Task NormalRequestPassesThrough()
3744
{

src/Security/Authentication/test/FacebookTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ protected override void ConfigureDefaults(FacebookOptions o)
4242
o.SignInScheme = "auth1";
4343
}
4444

45+
[Fact]
46+
public void EventsPropertyIsInitializedOnConstruction()
47+
{
48+
var options = new FacebookOptions();
49+
Assert.NotNull(options.Events);
50+
}
51+
4552
[Fact]
4653
public async Task ThrowsIfAppIdMissing()
4754
{

src/Security/Authentication/test/GoogleTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ protected override void ConfigureDefaults(GoogleOptions o)
4242
o.SignInScheme = "auth1";
4343
}
4444

45+
[Fact]
46+
public void EventsPropertyIsInitializedOnConstruction()
47+
{
48+
var options = new GoogleOptions();
49+
Assert.NotNull(options.Events);
50+
}
51+
4552
[Fact]
4653
public async Task ChallengeWillTriggerRedirection()
4754
{

src/Security/Authentication/test/JwtBearerTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ public class JwtBearerTests : SharedAuthenticationTests<JwtBearerOptions>
3333

3434
protected override void RegisterAuth(AuthenticationBuilder services, Action<JwtBearerOptions> configure)
3535
{
36-
services.AddJwtBearer(o =>
37-
{
38-
ConfigureDefaults(o);
39-
configure.Invoke(o);
40-
});
36+
services.AddJwtBearer(configure);
4137
}
4238

43-
private void ConfigureDefaults(JwtBearerOptions o)
39+
[Fact]
40+
public void EventsPropertyIsInitializedOnConstruction()
4441
{
42+
var options = new JwtBearerOptions();
43+
Assert.NotNull(options.Events);
4544
}
4645

4746
[Fact]

0 commit comments

Comments
 (0)