diff --git a/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs b/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
index e98e9446..2ad8aad2 100644
--- a/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
+++ b/src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
@@ -36,24 +36,24 @@ namespace OpenIddict.Abstractions
///
/// Gets the permissions associated with the application.
///
- public ISet Permissions { get; } = new HashSet(StringComparer.Ordinal);
+ public HashSet Permissions { get; } = new HashSet(StringComparer.Ordinal);
///
/// Gets the logout callback URLs
/// associated with the application.
///
- public ISet PostLogoutRedirectUris { get; } = new HashSet();
+ public HashSet PostLogoutRedirectUris { get; } = new HashSet();
///
/// Gets the callback URLs
/// associated with the application.
///
- public ISet RedirectUris { get; } = new HashSet();
+ public HashSet RedirectUris { get; } = new HashSet();
///
/// Gets the requirements associated with the application.
///
- public ISet Requirements { get; } = new HashSet(StringComparer.Ordinal);
+ public HashSet Requirements { get; } = new HashSet(StringComparer.Ordinal);
///
/// Gets or sets the application type
diff --git a/src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs b/src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs
index 4dbf2ce1..5f5029d6 100644
--- a/src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs
+++ b/src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs
@@ -23,8 +23,7 @@ namespace OpenIddict.Abstractions
///
/// Gets the scopes associated with the authorization.
///
- public ISet Scopes { get; } =
- new HashSet(StringComparer.Ordinal);
+ public HashSet Scopes { get; } = new HashSet(StringComparer.Ordinal);
///
/// Gets or sets the status associated with the authorization.
diff --git a/src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs b/src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs
index fedf6881..24433411 100644
--- a/src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs
+++ b/src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs
@@ -29,7 +29,6 @@ namespace OpenIddict.Abstractions
///
/// Gets the resources associated with the scope.
///
- public virtual ISet Resources { get; }
- = new HashSet(StringComparer.Ordinal);
+ public virtual HashSet Resources { get; } = new HashSet(StringComparer.Ordinal);
}
}
diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs
index 0d5ffe47..22604b87 100644
--- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs
+++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs
@@ -183,38 +183,37 @@ namespace OpenIddict.EntityFramework
// To prevent an SQL exception from being thrown if a new associated entity is
// created after the existing entries have been listed, the following logic is
// executed in a serializable transaction, that will lock the affected tables.
- using (var transaction = CreateTransaction())
+ using var transaction = CreateTransaction();
+
+ // Remove all the tokens associated with the authorization.
+ var tokens = await ListTokensAsync();
+ foreach (var token in tokens)
{
- // Remove all the tokens associated with the authorization.
- var tokens = await ListTokensAsync();
- foreach (var token in tokens)
- {
- Tokens.Remove(token);
- }
+ Tokens.Remove(token);
+ }
- Authorizations.Remove(authorization);
+ Authorizations.Remove(authorization);
- try
- {
- await Context.SaveChangesAsync(cancellationToken);
- transaction?.Commit();
- }
-
- catch (DbUpdateConcurrencyException exception)
- {
- // Reset the state of the entity to prevents future calls to SaveChangesAsync() from failing.
- Context.Entry(authorization).State = EntityState.Unchanged;
+ try
+ {
+ await Context.SaveChangesAsync(cancellationToken);
+ transaction?.Commit();
+ }
- foreach (var token in tokens)
- {
- Context.Entry(token).State = EntityState.Unchanged;
- }
+ catch (DbUpdateConcurrencyException exception)
+ {
+ // Reset the state of the entity to prevents future calls to SaveChangesAsync() from failing.
+ Context.Entry(authorization).State = EntityState.Unchanged;
- throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
- .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
- .Append("Reload the authorization from the database and retry the operation.")
- .ToString(), exception);
+ foreach (var token in tokens)
+ {
+ Context.Entry(token).State = EntityState.Unchanged;
}
+
+ throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder()
+ .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.")
+ .Append("Reload the authorization from the database and retry the operation.")
+ .ToString(), exception);
}
}
@@ -743,7 +742,7 @@ namespace OpenIddict.EntityFramework
// entities in a single command without having to retrieve and materialize them first.
// To work around this limitation, entities are manually listed and deleted using a batch logic.
- IList exceptions = null;
+ List exceptions = null;
DbContextTransaction CreateTransaction()
{
diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs
index 826cd8bd..0d3e0b34 100644
--- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs
+++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs
@@ -771,7 +771,7 @@ namespace OpenIddict.EntityFramework
// entities in a single command without having to retrieve and materialize them first.
// To work around this limitation, entities are manually listed and deleted using a batch logic.
- IList exceptions = null;
+ List exceptions = null;
DbContextTransaction CreateTransaction()
{
diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs
index c088230c..9b11064e 100644
--- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs
+++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs
@@ -805,7 +805,7 @@ namespace OpenIddict.EntityFrameworkCore
// entities in a single command without having to retrieve and materialize them first.
// To work around this limitation, entities are manually listed and deleted using a batch logic.
- IList exceptions = null;
+ List exceptions = null;
async ValueTask CreateTransactionAsync()
{
diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
index 5d8b9659..463fbf24 100644
--- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
+++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
@@ -820,7 +820,7 @@ namespace OpenIddict.EntityFrameworkCore
// entities in a single command without having to retrieve and materialize them first.
// To work around this limitation, entities are manually listed and deleted using a batch logic.
- IList exceptions = null;
+ List exceptions = null;
async ValueTask CreateTransactionAsync()
{
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
index 32fa2262..033e8307 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
@@ -704,7 +704,7 @@ namespace OpenIddict.MongoDb
.DeleteManyAsync(token => buffer.Contains(token.AuthorizationId), cancellationToken);
}
- IEnumerable> Buffer(IEnumerable source, int count)
+ static IEnumerable> Buffer(IEnumerable source, int count)
{
List buffer = null;
diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs
index 3866265c..895ea390 100644
--- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs
+++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs
@@ -54,10 +54,7 @@ namespace OpenIddict.Server.AspNetCore
}
// Register the built-in event handlers used by the OpenIddict ASP.NET Core server components.
- foreach (var handler in OpenIddictServerAspNetCoreHandlers.DefaultHandlers)
- {
- options.DefaultHandlers.Add(handler);
- }
+ options.Handlers.AddRange(OpenIddictServerAspNetCoreHandlers.DefaultHandlers);
}
///
diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs
index e4d5172a..6e70d05b 100644
--- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs
+++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs
@@ -29,19 +29,24 @@ namespace OpenIddict.Server.AspNetCore
IAuthenticationSignInHandler,
IAuthenticationSignOutHandler
{
- private readonly IOpenIddictServerProvider _provider;
+ private readonly IOpenIddictServerDispatcher _dispatcher;
+ private readonly IOpenIddictServerFactory _factory;
///
/// Creates a new instance of the class.
///
public OpenIddictServerAspNetCoreHandler(
- [NotNull] IOpenIddictServerProvider provider,
+ [NotNull] IOpenIddictServerDispatcher dispatcher,
+ [NotNull] IOpenIddictServerFactory factory,
[NotNull] IOptionsMonitor options,
[NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock)
: base(options, logger, encoder, clock)
- => _provider = provider;
+ {
+ _dispatcher = dispatcher;
+ _factory = factory;
+ }
public async Task HandleRequestAsync()
{
@@ -51,7 +56,7 @@ namespace OpenIddict.Server.AspNetCore
if (transaction == null)
{
// Create a new transaction and attach the HTTP request to make it available to the ASP.NET Core handlers.
- transaction = await _provider.CreateTransactionAsync();
+ transaction = await _factory.CreateTransactionAsync();
transaction.Properties[typeof(HttpRequest).FullName] = new WeakReference(Request);
// Attach the OpenIddict server transaction to the ASP.NET Core features
@@ -60,7 +65,7 @@ namespace OpenIddict.Server.AspNetCore
}
var context = new ProcessRequestContext(transaction);
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled)
{
@@ -84,7 +89,7 @@ namespace OpenIddict.Server.AspNetCore
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled)
{
@@ -118,7 +123,7 @@ namespace OpenIddict.Server.AspNetCore
if (context == null)
{
context = new ProcessAuthenticationContext(transaction);
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
// Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the authentication result without triggering a new authentication flow.
@@ -182,7 +187,7 @@ namespace OpenIddict.Server.AspNetCore
Response = new OpenIddictResponse()
};
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped)
{
@@ -201,7 +206,7 @@ namespace OpenIddict.Server.AspNetCore
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped)
{
@@ -237,7 +242,7 @@ namespace OpenIddict.Server.AspNetCore
Response = new OpenIddictResponse()
};
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped)
{
@@ -256,7 +261,7 @@ namespace OpenIddict.Server.AspNetCore
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped)
{
@@ -283,7 +288,7 @@ namespace OpenIddict.Server.AspNetCore
transaction.Properties[typeof(AuthenticationProperties).FullName] = properties ?? new AuthenticationProperties();
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped)
{
@@ -302,7 +307,7 @@ namespace OpenIddict.Server.AspNetCore
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped)
{
diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs
index 563635f3..e3757a97 100644
--- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs
+++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs
@@ -80,6 +80,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler()
.SetOrder(int.MinValue + 50_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -119,7 +120,7 @@ namespace OpenIddict.Server.AspNetCore
return default;
- static bool Matches(HttpRequest request, IList addresses)
+ static bool Matches(HttpRequest request, IReadOnlyList addresses)
{
for (var index = 0; index < addresses.Count; index++)
{
@@ -182,6 +183,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -253,6 +255,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -311,6 +314,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler()
.SetOrder(AttachDefaultChallengeError.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -354,6 +358,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(int.MaxValue - 150_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -414,6 +419,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ValidateTransportSecurityRequirement.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -473,6 +479,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractGetRequest.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -560,6 +567,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractGetOrPostRequest.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -643,6 +651,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractPostRequest.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -744,6 +753,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractBasicAuthenticationCredentials.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -798,6 +808,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(int.MaxValue - 100_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -834,6 +845,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(AttachCacheControlHeader.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -897,6 +909,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(AttachWwwAuthenticateHeader.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -949,6 +962,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessChallengeErrorResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1066,6 +1080,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessJsonResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1117,6 +1132,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessPassthroughErrorResponse>.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1179,6 +1195,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessStatusCodePagesErrorResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1230,6 +1247,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessLocalErrorResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1292,6 +1310,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessEmptyResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1373,6 +1392,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessEmptyResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1425,6 +1445,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter()
.UseSingletonHandler>()
.SetOrder(int.MaxValue - 100_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs
index 30c1edda..12e42881 100644
--- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs
+++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs
@@ -34,10 +34,7 @@ namespace OpenIddict.Server.DataProtection
}
// Register the built-in event handlers used by the OpenIddict Data Protection server components.
- foreach (var handler in OpenIddictServerDataProtectionHandlers.DefaultHandlers)
- {
- options.DefaultHandlers.Add(handler);
- }
+ options.Handlers.AddRange(OpenIddictServerDataProtectionHandlers.DefaultHandlers);
}
///
diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs
index f45edfd9..67f31526 100644
--- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs
+++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs
@@ -62,6 +62,7 @@ namespace OpenIddict.Server.DataProtection
= OpenIddictServerHandlerDescriptor.CreateBuilder()
.UseSingletonHandler()
.SetOrder(ValidateIdentityModelToken.Descriptor.Order + 500)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -180,6 +181,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter()
.UseSingletonHandler()
.SetOrder(GenerateIdentityModelAccessToken.Descriptor.Order - 500)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -244,6 +246,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter()
.UseSingletonHandler()
.SetOrder(GenerateIdentityModelAuthorizationCode.Descriptor.Order - 500)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -308,6 +311,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter()
.UseSingletonHandler()
.SetOrder(GenerateIdentityModelDeviceCode.Descriptor.Order - 500)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -372,6 +376,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter()
.UseSingletonHandler()
.SetOrder(GenerateIdentityModelRefreshToken.Descriptor.Order - 500)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -436,6 +441,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter()
.UseSingletonHandler()
.SetOrder(GenerateIdentityModelUserCode.Descriptor.Order - 500)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs
index eb2e1209..f87105d0 100644
--- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs
+++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs
@@ -26,10 +26,7 @@ namespace OpenIddict.Server.Owin
}
// Register the built-in event handlers used by the OpenIddict OWIN server components.
- foreach (var handler in OpenIddictServerOwinHandlers.DefaultHandlers)
- {
- options.DefaultHandlers.Add(handler);
- }
+ options.Handlers.AddRange(OpenIddictServerOwinHandlers.DefaultHandlers);
}
public void PostConfigure([CanBeNull] string name, [NotNull] OpenIddictServerOwinOptions options)
diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs
index 8b840d70..f8804289 100644
--- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs
+++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs
@@ -24,14 +24,21 @@ namespace OpenIddict.Server.Owin
///
public class OpenIddictServerOwinHandler : AuthenticationHandler
{
- private readonly IOpenIddictServerProvider _provider;
+ private readonly IOpenIddictServerDispatcher _dispatcher;
+ private readonly IOpenIddictServerFactory _factory;
///
/// Creates a new instance of the class.
///
- /// The OpenIddict server OWIN provider used by this instance.
- public OpenIddictServerOwinHandler([NotNull] IOpenIddictServerProvider provider)
- => _provider = provider;
+ /// The OpenIddict server provider used by this instance.
+ /// The OpenIddict server factory used by this instance.
+ public OpenIddictServerOwinHandler(
+ [NotNull] IOpenIddictServerDispatcher dispatcher,
+ [NotNull] IOpenIddictServerFactory factory)
+ {
+ _dispatcher = dispatcher;
+ _factory = factory;
+ }
protected override async Task InitializeCoreAsync()
{
@@ -41,7 +48,7 @@ namespace OpenIddict.Server.Owin
if (transaction == null)
{
// Create a new transaction and attach the OWIN request to make it available to the OWIN handlers.
- transaction = await _provider.CreateTransactionAsync();
+ transaction = await _factory.CreateTransactionAsync();
transaction.Properties[typeof(IOwinRequest).FullName] = new WeakReference(Request);
// Attach the OpenIddict server transaction to the OWIN shared dictionary
@@ -50,7 +57,7 @@ namespace OpenIddict.Server.Owin
}
var context = new ProcessRequestContext(transaction);
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
// Store the context in the transaction so that it can be retrieved from InvokeAsync().
transaction.SetProperty(typeof(ProcessRequestContext).FullName, context);
@@ -90,7 +97,7 @@ namespace OpenIddict.Server.Owin
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled)
{
@@ -127,7 +134,7 @@ namespace OpenIddict.Server.Owin
if (context == null)
{
context = new ProcessAuthenticationContext(transaction);
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
// Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the authentication result without triggering a new authentication flow.
@@ -202,7 +209,7 @@ namespace OpenIddict.Server.Owin
Response = new OpenIddictResponse()
};
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped)
{
@@ -221,7 +228,7 @@ namespace OpenIddict.Server.Owin
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped)
{
@@ -250,7 +257,7 @@ namespace OpenIddict.Server.Owin
Response = new OpenIddictResponse()
};
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped)
{
@@ -269,7 +276,7 @@ namespace OpenIddict.Server.Owin
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped)
{
@@ -297,7 +304,7 @@ namespace OpenIddict.Server.Owin
Response = new OpenIddictResponse()
};
- await _provider.DispatchAsync(context);
+ await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped)
{
@@ -316,7 +323,7 @@ namespace OpenIddict.Server.Owin
}
};
- await _provider.DispatchAsync(notification);
+ await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped)
{
diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs
index 783b39c9..89bac6e3 100644
--- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs
+++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs
@@ -68,6 +68,7 @@ namespace OpenIddict.Server.Owin
// Note: this handler must be invoked before any other handler,
// including the built-in handlers defined in OpenIddict.Server.
.SetOrder(int.MinValue + 50_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -107,7 +108,7 @@ namespace OpenIddict.Server.Owin
return default;
- static bool Matches(IOwinRequest request, IList addresses)
+ static bool Matches(IOwinRequest request, IReadOnlyList addresses)
{
for (var index = 0; index < addresses.Count; index++)
{
@@ -170,6 +171,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -241,6 +243,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -299,6 +302,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler()
.SetOrder(AttachDefaultChallengeError.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -345,6 +349,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ValidateTransportSecurityRequirement.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -404,6 +409,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractGetRequest.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -491,6 +497,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractGetOrPostRequest.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -574,6 +581,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractPostRequest.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -675,6 +683,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ExtractBasicAuthenticationCredentials.Descriptor.Order + 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -729,6 +738,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(int.MaxValue - 100_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -765,6 +775,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(AttachCacheControlHeader.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -828,6 +839,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(AttachWwwAuthenticateHeader.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -880,6 +892,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessChallengeErrorResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -997,6 +1010,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessJsonResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1048,6 +1062,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessPassthroughErrorResponse>.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1110,6 +1125,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessLocalErrorResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1163,6 +1179,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessEmptyResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1244,6 +1261,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(ProcessEmptyResponse.Descriptor.Order - 1_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
@@ -1296,6 +1314,7 @@ namespace OpenIddict.Server.Owin
.AddFilter()
.UseSingletonHandler>()
.SetOrder(int.MaxValue - 100_000)
+ .SetType(OpenIddictServerHandlerType.BuiltIn)
.Build();
///
diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs
index 7c7c4871..613f5176 100644
--- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs
+++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs
@@ -19,26 +19,32 @@ namespace OpenIddict.Server.Owin
///
public class OpenIddictServerOwinMiddleware : AuthenticationMiddleware
{
- private readonly IOpenIddictServerProvider _provider;
+ private readonly IOpenIddictServerDispatcher _dispatcher;
+ private readonly IOpenIddictServerFactory _factory;
///
/// Creates a new instance of the class.
///
/// The next middleware in the pipeline, if applicable.
/// The OpenIddict server OWIN options.
- /// The OpenIddict server provider.
+ /// The OpenIddict server dispatcher.
+ /// The OpenIddict server factory.
public OpenIddictServerOwinMiddleware(
[CanBeNull] OwinMiddleware next,
[NotNull] IOptionsMonitor options,
- [NotNull] IOpenIddictServerProvider provider)
+ [NotNull] IOpenIddictServerDispatcher dispatcher,
+ [NotNull] IOpenIddictServerFactory factory)
: base(next, options.CurrentValue)
- => _provider = provider;
+ {
+ _dispatcher = dispatcher;
+ _factory = factory;
+ }
///
/// Creates and returns a new instance.
///
/// A new instance of the class.
protected override AuthenticationHandler CreateHandler()
- => new OpenIddictServerOwinHandler(_provider);
+ => new OpenIddictServerOwinHandler(_dispatcher, _factory);
}
}
diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs
index ca3c3d3e..44b45754 100644
--- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs
+++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs
@@ -64,13 +64,14 @@ namespace OpenIddict.Server.Owin
var middleware = new OpenIddictServerOwinMiddleware(
next: Next,
options: GetRequiredService>(provider),
- provider: GetRequiredService(provider));
+ dispatcher: GetRequiredService(provider),
+ factory: GetRequiredService(provider));
return middleware.Invoke(context);
static T GetRequiredService(IServiceProvider provider)
=> provider.GetService() ?? throw new InvalidOperationException(new StringBuilder()
- .AppendLine("The OpenIddict server authentication services cannot be resolved from the DI container.")
+ .AppendLine("The OpenIddict server services cannot be resolved from the DI container.")
.Append("To register the OWIN services, use 'services.AddOpenIddict().AddServer().UseOwin()'.")
.ToString());
}
diff --git a/src/OpenIddict.Server/IOpenIddictServerProvider.cs b/src/OpenIddict.Server/IOpenIddictServerDispatcher.cs
similarity index 80%
rename from src/OpenIddict.Server/IOpenIddictServerProvider.cs
rename to src/OpenIddict.Server/IOpenIddictServerDispatcher.cs
index 91051a8c..beee5ae6 100644
--- a/src/OpenIddict.Server/IOpenIddictServerProvider.cs
+++ b/src/OpenIddict.Server/IOpenIddictServerDispatcher.cs
@@ -10,9 +10,8 @@ using static OpenIddict.Server.OpenIddictServerEvents;
namespace OpenIddict.Server
{
- public interface IOpenIddictServerProvider
+ public interface IOpenIddictServerDispatcher
{
- ValueTask CreateTransactionAsync();
ValueTask DispatchAsync([NotNull] TContext context) where TContext : BaseContext;
}
}
\ No newline at end of file
diff --git a/src/OpenIddict.Server/IOpenIddictServerFactory.cs b/src/OpenIddict.Server/IOpenIddictServerFactory.cs
new file mode 100644
index 00000000..eddbb9c4
--- /dev/null
+++ b/src/OpenIddict.Server/IOpenIddictServerFactory.cs
@@ -0,0 +1,15 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
+ * See https://github.com/openiddict/openiddict-core for more information concerning
+ * the license and the contributors participating to this project.
+ */
+
+using System.Threading.Tasks;
+
+namespace OpenIddict.Server
+{
+ public interface IOpenIddictServerFactory
+ {
+ ValueTask CreateTransactionAsync();
+ }
+}
\ No newline at end of file
diff --git a/src/OpenIddict.Server/OpenIddictServerBuilder.cs b/src/OpenIddict.Server/OpenIddictServerBuilder.cs
index 3884a285..9a9fc12a 100644
--- a/src/OpenIddict.Server/OpenIddictServerBuilder.cs
+++ b/src/OpenIddict.Server/OpenIddictServerBuilder.cs
@@ -56,7 +56,10 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(configuration));
}
- var builder = OpenIddictServerHandlerDescriptor.CreateBuilder();
+ // Note: handlers registered using this API are assumed to be custom handlers by default.
+ var builder = OpenIddictServerHandlerDescriptor.CreateBuilder()
+ .SetType(OpenIddictServerHandlerType.Custom);
+
configuration(builder);
return AddEventHandler(builder.Build());
@@ -78,7 +81,7 @@ namespace Microsoft.Extensions.DependencyInjection
// Register the handler in the services collection.
Services.Add(descriptor.ServiceDescriptor);
- return Configure(options => options.CustomHandlers.Add(descriptor));
+ return Configure(options => options.Handlers.Add(descriptor));
}
///
@@ -98,19 +101,11 @@ namespace Microsoft.Extensions.DependencyInjection
Services.PostConfigure(options =>
{
- for (var index = options.CustomHandlers.Count - 1; index >= 0; index--)
- {
- if (options.CustomHandlers[index].ServiceDescriptor.ServiceType == descriptor.ServiceDescriptor.ServiceType)
- {
- options.CustomHandlers.RemoveAt(index);
- }
- }
-
- for (var index = options.DefaultHandlers.Count - 1; index >= 0; index--)
+ for (var index = options.Handlers.Count - 1; index >= 0; index--)
{
- if (options.DefaultHandlers[index].ServiceDescriptor.ServiceType == descriptor.ServiceDescriptor.ServiceType)
+ if (options.Handlers[index].ServiceDescriptor.ServiceType == descriptor.ServiceDescriptor.ServiceType)
{
- options.DefaultHandlers.RemoveAt(index);
+ options.Handlers.RemoveAt(index);
}
}
});
diff --git a/src/OpenIddict.Server/OpenIddictServerConfiguration.cs b/src/OpenIddict.Server/OpenIddictServerConfiguration.cs
index fe5020fb..6a3848bb 100644
--- a/src/OpenIddict.Server/OpenIddictServerConfiguration.cs
+++ b/src/OpenIddict.Server/OpenIddictServerConfiguration.cs
@@ -134,8 +134,9 @@ namespace OpenIddict.Server
// If the degraded mode was enabled, ensure custom validation handlers
// have been registered for the endpoints that require manual validation.
- if (options.AuthorizationEndpointUris.Count != 0 && !options.CustomHandlers.Any(
+ if (options.AuthorizationEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateAuthorizationRequestContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -145,8 +146,9 @@ namespace OpenIddict.Server
.ToString());
}
- if (options.DeviceEndpointUris.Count != 0 && !options.CustomHandlers.Any(
+ if (options.DeviceEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateDeviceRequestContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -156,8 +158,9 @@ namespace OpenIddict.Server
.ToString());
}
- if (options.IntrospectionEndpointUris.Count != 0 && !options.CustomHandlers.Any(
+ if (options.IntrospectionEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateIntrospectionRequestContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -167,8 +170,9 @@ namespace OpenIddict.Server
.ToString());
}
- if (options.LogoutEndpointUris.Count != 0 && !options.CustomHandlers.Any(
+ if (options.LogoutEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateLogoutRequestContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -178,8 +182,9 @@ namespace OpenIddict.Server
.ToString());
}
- if (options.RevocationEndpointUris.Count != 0 && !options.CustomHandlers.Any(
+ if (options.RevocationEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateRevocationRequestContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -189,8 +194,9 @@ namespace OpenIddict.Server
.ToString());
}
- if (options.TokenEndpointUris.Count != 0 && !options.CustomHandlers.Any(
+ if (options.TokenEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateTokenRequestContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -200,8 +206,9 @@ namespace OpenIddict.Server
.ToString());
}
- if (options.VerificationEndpointUris.Count != 0 && !options.CustomHandlers.Any(
+ if (options.VerificationEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateVerificationRequestContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -216,8 +223,9 @@ namespace OpenIddict.Server
if (options.GrantTypes.Contains(GrantTypes.DeviceCode))
{
- if (!options.CustomHandlers.Any(
+ if (!options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ProcessAuthenticationContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -227,8 +235,9 @@ namespace OpenIddict.Server
.ToString());
}
- if (!options.CustomHandlers.Any(
+ if (!options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ProcessSignInContext) &&
+ descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
@@ -240,6 +249,9 @@ namespace OpenIddict.Server
}
}
+ // Sort the handlers collection using the order associated with each handler.
+ options.Handlers.Sort((left, right) => left.Order.CompareTo(right.Order));
+
// Automatically add the offline_access scope if the refresh token grant has been enabled.
if (options.GrantTypes.Contains(GrantTypes.RefreshToken))
{
diff --git a/src/OpenIddict.Server/OpenIddictServerProvider.cs b/src/OpenIddict.Server/OpenIddictServerDispatcher.cs
similarity index 82%
rename from src/OpenIddict.Server/OpenIddictServerProvider.cs
rename to src/OpenIddict.Server/OpenIddictServerDispatcher.cs
index 1af83826..6b7a04b5 100644
--- a/src/OpenIddict.Server/OpenIddictServerProvider.cs
+++ b/src/OpenIddict.Server/OpenIddictServerDispatcher.cs
@@ -15,17 +15,17 @@ using static OpenIddict.Server.OpenIddictServerEvents;
namespace OpenIddict.Server
{
- public class OpenIddictServerProvider : IOpenIddictServerProvider
+ public class OpenIddictServerDispatcher : IOpenIddictServerDispatcher
{
- private readonly ILogger _logger;
+ private readonly ILogger _logger;
private readonly IOptionsMonitor _options;
private readonly IServiceProvider _provider;
///
- /// Creates a new instance of the class.
+ /// Creates a new instance of the class.
///
- public OpenIddictServerProvider(
- [NotNull] ILogger logger,
+ public OpenIddictServerDispatcher(
+ [NotNull] ILogger logger,
[NotNull] IOptionsMonitor options,
[NotNull] IServiceProvider provider)
{
@@ -34,14 +34,6 @@ namespace OpenIddict.Server
_provider = provider;
}
- public ValueTask CreateTransactionAsync()
- => new ValueTask(new OpenIddictServerTransaction
- {
- Issuer = _options.CurrentValue.Issuer,
- Logger = _logger,
- Options = _options.CurrentValue
- });
-
public async ValueTask DispatchAsync([NotNull] TContext context) where TContext : BaseContext
{
if (context == null)
@@ -82,14 +74,12 @@ namespace OpenIddict.Server
async IAsyncEnumerable> GetHandlersAsync()
{
- var descriptors = new List(
- capacity: _options.CurrentValue.CustomHandlers.Count +
- _options.CurrentValue.DefaultHandlers.Count);
-
- descriptors.AddRange(_options.CurrentValue.CustomHandlers);
- descriptors.AddRange(_options.CurrentValue.DefaultHandlers);
-
- descriptors.Sort((left, right) => left.Order.CompareTo(right.Order));
+ // Note: the descriptors collection is sorted during options initialization for performance reasons.
+ var descriptors = _options.CurrentValue.Handlers;
+ if (descriptors.Count == 0)
+ {
+ yield break;
+ }
for (var index = 0; index < descriptors.Count; index++)
{
diff --git a/src/OpenIddict.Server/OpenIddictServerEvents.Discovery.cs b/src/OpenIddict.Server/OpenIddictServerEvents.Discovery.cs
index e13b6c5e..6df55a88 100644
--- a/src/OpenIddict.Server/OpenIddictServerEvents.Discovery.cs
+++ b/src/OpenIddict.Server/OpenIddictServerEvents.Discovery.cs
@@ -107,78 +107,67 @@ namespace OpenIddict.Server
///
/// Gets the list of claims supported by the authorization server.
///
- public ISet Claims { get; } =
- new HashSet(StringComparer.Ordinal);
+ public HashSet Claims { get; } = new HashSet(StringComparer.Ordinal);
///
/// Gets a list of the code challenge methods
/// supported by the authorization server.
///
- public ISet CodeChallengeMethods { get; } =
- new HashSet(StringComparer.Ordinal);
+ public HashSet CodeChallengeMethods { get; } = new HashSet(StringComparer.Ordinal);
///
/// Gets the list of grant types
/// supported by the authorization server.
///
- public ISet GrantTypes { get; } =
- new HashSet(StringComparer.Ordinal);
+ public HashSet GrantTypes { get; } = new HashSet(StringComparer.Ordinal);
///
/// Gets a list of signing algorithms supported by the
/// authorization server for signing the identity tokens.
///
- public ISet IdTokenSigningAlgorithms { get; } =
- new HashSet(StringComparer.Ordinal);
+ public HashSet