Skip to content

Commit d57e2e0

Browse files
committed
Throw an exception when no valid sign-in scheme can be found and introduce OpenIdAuthenticationOptions.DataProtectionProvider
1 parent b6d8c02 commit d57e2e0

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/AspNet.Security.OpenId/OpenIdAuthenticationMiddleware.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,30 @@ public OpenIdAuthenticationMiddleware(
2727
[NotNull] IDataProtectionProvider dataProtectionProvider,
2828
[NotNull] ILoggerFactory loggerFactory,
2929
[NotNull] UrlEncoder encoder,
30-
[NotNull] IOptions<SharedAuthenticationOptions> externalOptions)
30+
[NotNull] IOptions<SharedAuthenticationOptions> sharedOptions)
3131
: base(next, options, loggerFactory, encoder)
3232
{
3333
if (string.IsNullOrEmpty(Options.SignInScheme))
3434
{
35-
Options.SignInScheme = externalOptions.Value.SignInScheme;
35+
Options.SignInScheme = sharedOptions.Value.SignInScheme;
36+
}
37+
38+
if (string.IsNullOrEmpty(Options.SignInScheme))
39+
{
40+
throw new ArgumentException("The sign-in scheme cannot be null or empty.", nameof(options));
41+
}
42+
43+
if (Options.DataProtectionProvider == null)
44+
{
45+
Options.DataProtectionProvider = dataProtectionProvider;
3646
}
3747

3848
if (Options.StateDataFormat == null)
3949
{
40-
Options.StateDataFormat = new PropertiesDataFormat(
41-
dataProtectionProvider.CreateProtector(
42-
GetType().FullName, Options.AuthenticationScheme, "v1"));
50+
var protector = Options.DataProtectionProvider.CreateProtector(
51+
GetType().FullName, Options.AuthenticationScheme, "v1");
52+
53+
Options.StateDataFormat = new PropertiesDataFormat(protector);
4354
}
4455

4556
if (Options.HtmlParser == null)

src/AspNet.Security.OpenId/OpenIdAuthenticationOptions.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using AngleSharp.Parser.Html;
1111
using Microsoft.AspNetCore.Authentication;
1212
using Microsoft.AspNetCore.Builder;
13+
using Microsoft.AspNetCore.DataProtection;
1314
using Microsoft.AspNetCore.Http;
1415
using Microsoft.AspNetCore.Http.Authentication;
1516
using Microsoft.IdentityModel.Protocols;
@@ -26,12 +27,6 @@ public OpenIdAuthenticationOptions()
2627
Events = new OpenIdAuthenticationEvents();
2728
}
2829

29-
/// <summary>
30-
/// Gets or sets the data format used to serialize the
31-
/// authentication properties used for the "state" parameter.
32-
/// </summary>
33-
public ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; }
34-
3530
/// <summary>
3631
/// Gets or sets the absolute URL of the OpenID 2.0 authentication server.
3732
/// Note: this property is ignored when <see cref="Configuration"/>
@@ -97,6 +92,20 @@ public OpenIdAuthenticationOptions()
9792
set { base.Events = value; }
9893
}
9994

95+
/// <summary>
96+
/// Gets or sets the data format used to serialize the
97+
/// authentication properties used for the "state" parameter.
98+
/// </summary>
99+
public ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; }
100+
101+
/// <summary>
102+
/// Gets or sets the data protection provider used to create the default
103+
/// data protectors used by the OpenID 2.0 authentication middleware.
104+
/// When this property is set to <c>null</c>, the data protection provider
105+
/// is directly retrieved from the dependency injection container.
106+
/// </summary>
107+
public IDataProtectionProvider DataProtectionProvider { get; set; }
108+
100109
/// <summary>
101110
/// Gets or sets the HTTP client used to communicate with the OpenID provider.
102111
/// </summary>

0 commit comments

Comments
 (0)