Browse Source

Reunify the custom and built-in handlers collections to avoid computing the collections per-request

pull/992/head
Kévin Chalet 6 years ago
parent
commit
ed0dc56487
  1. 8
      src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
  2. 3
      src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs
  3. 3
      src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs
  4. 53
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs
  5. 2
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs
  6. 2
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs
  7. 2
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
  8. 2
      src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
  9. 5
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreConfiguration.cs
  10. 31
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs
  11. 23
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs
  12. 5
      src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionConfiguration.cs
  13. 6
      src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs
  14. 5
      src/OpenIddict.Server.Owin/OpenIddictServerOwinConfiguration.cs
  15. 35
      src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs
  16. 21
      src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs
  17. 16
      src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs
  18. 5
      src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs
  19. 3
      src/OpenIddict.Server/IOpenIddictServerDispatcher.cs
  20. 15
      src/OpenIddict.Server/IOpenIddictServerFactory.cs
  21. 21
      src/OpenIddict.Server/OpenIddictServerBuilder.cs
  22. 30
      src/OpenIddict.Server/OpenIddictServerConfiguration.cs
  23. 32
      src/OpenIddict.Server/OpenIddictServerDispatcher.cs
  24. 35
      src/OpenIddict.Server/OpenIddictServerEvents.Discovery.cs
  25. 6
      src/OpenIddict.Server/OpenIddictServerEvents.Introspection.cs
  26. 3
      src/OpenIddict.Server/OpenIddictServerEvents.Userinfo.cs
  27. 3
      src/OpenIddict.Server/OpenIddictServerExtensions.cs
  28. 38
      src/OpenIddict.Server/OpenIddictServerFactory.cs
  29. 27
      src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs
  30. 29
      src/OpenIddict.Server/OpenIddictServerHandlerType.cs
  31. 34
      src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs
  32. 76
      src/OpenIddict.Server/OpenIddictServerHandlers.Device.cs
  33. 82
      src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs
  34. 42
      src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs
  35. 40
      src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs
  36. 40
      src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs
  37. 34
      src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs
  38. 40
      src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs
  39. 60
      src/OpenIddict.Server/OpenIddictServerHandlers.cs
  40. 49
      src/OpenIddict.Server/OpenIddictServerOptions.cs
  41. 5
      src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreConfiguration.cs
  42. 23
      src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs
  43. 9
      src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs
  44. 5
      src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionConfiguration.cs
  45. 1
      src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.cs
  46. 5
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinConfiguration.cs
  47. 27
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs
  48. 9
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs
  49. 16
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddleware.cs
  50. 5
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddlewareFactory.cs
  51. 5
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs
  52. 6
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs
  53. 3
      src/OpenIddict.Validation/IOpenIddictValidationDispatcher.cs
  54. 15
      src/OpenIddict.Validation/IOpenIddictValidationFactory.cs
  55. 21
      src/OpenIddict.Validation/OpenIddictValidationBuilder.cs
  56. 9
      src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs
  57. 32
      src/OpenIddict.Validation/OpenIddictValidationDispatcher.cs
  58. 3
      src/OpenIddict.Validation/OpenIddictValidationExtensions.cs
  59. 38
      src/OpenIddict.Validation/OpenIddictValidationFactory.cs
  60. 27
      src/OpenIddict.Validation/OpenIddictValidationHandlerDescriptor.cs
  61. 29
      src/OpenIddict.Validation/OpenIddictValidationHandlerType.cs
  62. 14
      src/OpenIddict.Validation/OpenIddictValidationHandlers.cs
  63. 17
      src/OpenIddict.Validation/OpenIddictValidationOptions.cs
  64. 39
      src/OpenIddict.Validation/OpenIddictValidationService.cs
  65. 3
      test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs

8
src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs

@ -36,24 +36,24 @@ namespace OpenIddict.Abstractions
/// <summary> /// <summary>
/// Gets the permissions associated with the application. /// Gets the permissions associated with the application.
/// </summary> /// </summary>
public ISet<string> Permissions { get; } = new HashSet<string>(StringComparer.Ordinal); public HashSet<string> Permissions { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the logout callback URLs /// Gets the logout callback URLs
/// associated with the application. /// associated with the application.
/// </summary> /// </summary>
public ISet<Uri> PostLogoutRedirectUris { get; } = new HashSet<Uri>(); public HashSet<Uri> PostLogoutRedirectUris { get; } = new HashSet<Uri>();
/// <summary> /// <summary>
/// Gets the callback URLs /// Gets the callback URLs
/// associated with the application. /// associated with the application.
/// </summary> /// </summary>
public ISet<Uri> RedirectUris { get; } = new HashSet<Uri>(); public HashSet<Uri> RedirectUris { get; } = new HashSet<Uri>();
/// <summary> /// <summary>
/// Gets the requirements associated with the application. /// Gets the requirements associated with the application.
/// </summary> /// </summary>
public ISet<string> Requirements { get; } = new HashSet<string>(StringComparer.Ordinal); public HashSet<string> Requirements { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets or sets the application type /// Gets or sets the application type

3
src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs

@ -23,8 +23,7 @@ namespace OpenIddict.Abstractions
/// <summary> /// <summary>
/// Gets the scopes associated with the authorization. /// Gets the scopes associated with the authorization.
/// </summary> /// </summary>
public ISet<string> Scopes { get; } = public HashSet<string> Scopes { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets or sets the status associated with the authorization. /// Gets or sets the status associated with the authorization.

3
src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs

@ -29,7 +29,6 @@ namespace OpenIddict.Abstractions
/// <summary> /// <summary>
/// Gets the resources associated with the scope. /// Gets the resources associated with the scope.
/// </summary> /// </summary>
public virtual ISet<string> Resources { get; } public virtual HashSet<string> Resources { get; } = new HashSet<string>(StringComparer.Ordinal);
= new HashSet<string>(StringComparer.Ordinal);
} }
} }

53
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 // 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 // created after the existing entries have been listed, the following logic is
// executed in a serializable transaction, that will lock the affected tables. // 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. Tokens.Remove(token);
var tokens = await ListTokensAsync(); }
foreach (var token in tokens)
{
Tokens.Remove(token);
}
Authorizations.Remove(authorization); Authorizations.Remove(authorization);
try try
{ {
await Context.SaveChangesAsync(cancellationToken); await Context.SaveChangesAsync(cancellationToken);
transaction?.Commit(); 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;
foreach (var token in tokens) catch (DbUpdateConcurrencyException exception)
{ {
Context.Entry(token).State = EntityState.Unchanged; // 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() foreach (var token in tokens)
.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.") Context.Entry(token).State = EntityState.Unchanged;
.ToString(), exception);
} }
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. // 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. // To work around this limitation, entities are manually listed and deleted using a batch logic.
IList<Exception> exceptions = null; List<Exception> exceptions = null;
DbContextTransaction CreateTransaction() DbContextTransaction CreateTransaction()
{ {

2
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. // 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. // To work around this limitation, entities are manually listed and deleted using a batch logic.
IList<Exception> exceptions = null; List<Exception> exceptions = null;
DbContextTransaction CreateTransaction() DbContextTransaction CreateTransaction()
{ {

2
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. // 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. // To work around this limitation, entities are manually listed and deleted using a batch logic.
IList<Exception> exceptions = null; List<Exception> exceptions = null;
async ValueTask<IDbContextTransaction> CreateTransactionAsync() async ValueTask<IDbContextTransaction> CreateTransactionAsync()
{ {

2
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. // 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. // To work around this limitation, entities are manually listed and deleted using a batch logic.
IList<Exception> exceptions = null; List<Exception> exceptions = null;
async ValueTask<IDbContextTransaction> CreateTransactionAsync() async ValueTask<IDbContextTransaction> CreateTransactionAsync()
{ {

2
src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs

@ -704,7 +704,7 @@ namespace OpenIddict.MongoDb
.DeleteManyAsync(token => buffer.Contains(token.AuthorizationId), cancellationToken); .DeleteManyAsync(token => buffer.Contains(token.AuthorizationId), cancellationToken);
} }
IEnumerable<IList<TSource>> Buffer<TSource>(IEnumerable<TSource> source, int count) static IEnumerable<List<TSource>> Buffer<TSource>(IEnumerable<TSource> source, int count)
{ {
List<TSource> buffer = null; List<TSource> buffer = null;

5
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. // Register the built-in event handlers used by the OpenIddict ASP.NET Core server components.
foreach (var handler in OpenIddictServerAspNetCoreHandlers.DefaultHandlers) options.Handlers.AddRange(OpenIddictServerAspNetCoreHandlers.DefaultHandlers);
{
options.DefaultHandlers.Add(handler);
}
} }
/// <summary> /// <summary>

31
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandler.cs

@ -29,19 +29,24 @@ namespace OpenIddict.Server.AspNetCore
IAuthenticationSignInHandler, IAuthenticationSignInHandler,
IAuthenticationSignOutHandler IAuthenticationSignOutHandler
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
private readonly IOpenIddictServerFactory _factory;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictServerAspNetCoreHandler"/> class. /// Creates a new instance of the <see cref="OpenIddictServerAspNetCoreHandler"/> class.
/// </summary> /// </summary>
public OpenIddictServerAspNetCoreHandler( public OpenIddictServerAspNetCoreHandler(
[NotNull] IOpenIddictServerProvider provider, [NotNull] IOpenIddictServerDispatcher dispatcher,
[NotNull] IOpenIddictServerFactory factory,
[NotNull] IOptionsMonitor<OpenIddictServerAspNetCoreOptions> options, [NotNull] IOptionsMonitor<OpenIddictServerAspNetCoreOptions> options,
[NotNull] ILoggerFactory logger, [NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder, [NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock) [NotNull] ISystemClock clock)
: base(options, logger, encoder, clock) : base(options, logger, encoder, clock)
=> _provider = provider; {
_dispatcher = dispatcher;
_factory = factory;
}
public async Task<bool> HandleRequestAsync() public async Task<bool> HandleRequestAsync()
{ {
@ -51,7 +56,7 @@ namespace OpenIddict.Server.AspNetCore
if (transaction == null) if (transaction == null)
{ {
// Create a new transaction and attach the HTTP request to make it available to the ASP.NET Core handlers. // 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<HttpRequest>(Request); transaction.Properties[typeof(HttpRequest).FullName] = new WeakReference<HttpRequest>(Request);
// Attach the OpenIddict server transaction to the ASP.NET Core features // Attach the OpenIddict server transaction to the ASP.NET Core features
@ -60,7 +65,7 @@ namespace OpenIddict.Server.AspNetCore
} }
var context = new ProcessRequestContext(transaction); var context = new ProcessRequestContext(transaction);
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled) if (context.IsRequestHandled)
{ {
@ -84,7 +89,7 @@ namespace OpenIddict.Server.AspNetCore
} }
}; };
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -118,7 +123,7 @@ namespace OpenIddict.Server.AspNetCore
if (context == null) if (context == null)
{ {
context = new ProcessAuthenticationContext(transaction); 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 // 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. // that want to access the authentication result without triggering a new authentication flow.
@ -182,7 +187,7 @@ namespace OpenIddict.Server.AspNetCore
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) 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) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {
@ -237,7 +242,7 @@ namespace OpenIddict.Server.AspNetCore
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) 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) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {
@ -283,7 +288,7 @@ namespace OpenIddict.Server.AspNetCore
transaction.Properties[typeof(AuthenticationProperties).FullName] = properties ?? new AuthenticationProperties(); transaction.Properties[typeof(AuthenticationProperties).FullName] = properties ?? new AuthenticationProperties();
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) 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) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {

23
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs

@ -80,6 +80,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<InferEndpointType>() .UseSingletonHandler<InferEndpointType>()
.SetOrder(int.MinValue + 50_000) .SetOrder(int.MinValue + 50_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -119,7 +120,7 @@ namespace OpenIddict.Server.AspNetCore
return default; return default;
static bool Matches(HttpRequest request, IList<Uri> addresses) static bool Matches(HttpRequest request, IReadOnlyList<Uri> addresses)
{ {
for (var index = 0; index < addresses.Count; index++) for (var index = 0; index < addresses.Count; index++)
{ {
@ -182,6 +183,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<InferIssuerFromHost>() .UseSingletonHandler<InferIssuerFromHost>()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000) .SetOrder(InferEndpointType.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -253,6 +255,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireTransportSecurityRequirementEnabled>() .AddFilter<RequireTransportSecurityRequirementEnabled>()
.UseSingletonHandler<ValidateTransportSecurityRequirement>() .UseSingletonHandler<ValidateTransportSecurityRequirement>()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000) .SetOrder(InferEndpointType.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -311,6 +314,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachHostChallengeError>() .UseSingletonHandler<AttachHostChallengeError>()
.SetOrder(AttachDefaultChallengeError.Descriptor.Order - 1_000) .SetOrder(AttachDefaultChallengeError.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -354,6 +358,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachHostParameters<TContext>>() .UseSingletonHandler<AttachHostParameters<TContext>>()
.SetOrder(int.MaxValue - 150_000) .SetOrder(int.MaxValue - 150_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -414,6 +419,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ExtractGetRequest<TContext>>() .UseSingletonHandler<ExtractGetRequest<TContext>>()
.SetOrder(ValidateTransportSecurityRequirement.Descriptor.Order + 1_000) .SetOrder(ValidateTransportSecurityRequirement.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -473,6 +479,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ExtractGetOrPostRequest<TContext>>() .UseSingletonHandler<ExtractGetOrPostRequest<TContext>>()
.SetOrder(ExtractGetRequest<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractGetRequest<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -560,6 +567,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ExtractPostRequest<TContext>>() .UseSingletonHandler<ExtractPostRequest<TContext>>()
.SetOrder(ExtractGetOrPostRequest<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractGetOrPostRequest<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -643,6 +651,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ExtractBasicAuthenticationCredentials<TContext>>() .UseSingletonHandler<ExtractBasicAuthenticationCredentials<TContext>>()
.SetOrder(ExtractPostRequest<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractPostRequest<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -744,6 +753,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ExtractAccessToken<TContext>>() .UseSingletonHandler<ExtractAccessToken<TContext>>()
.SetOrder(ExtractBasicAuthenticationCredentials<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractBasicAuthenticationCredentials<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -798,6 +808,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<TFilter>() .AddFilter<TFilter>()
.UseSingletonHandler<EnablePassthroughMode<TContext, TFilter>>() .UseSingletonHandler<EnablePassthroughMode<TContext, TFilter>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -834,6 +845,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachHttpResponseCode<TContext>>() .UseSingletonHandler<AttachHttpResponseCode<TContext>>()
.SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -897,6 +909,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachCacheControlHeader<TContext>>() .UseSingletonHandler<AttachCacheControlHeader<TContext>>()
.SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -949,6 +962,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>() .UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>()
.SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1066,6 +1080,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>() .UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>()
.SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1117,6 +1132,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessJsonResponse<TContext>>() .UseSingletonHandler<ProcessJsonResponse<TContext>>()
.SetOrder(ProcessPassthroughErrorResponse<TContext, IOpenIddictServerHandlerFilter<TContext>>.Descriptor.Order - 1_000) .SetOrder(ProcessPassthroughErrorResponse<TContext, IOpenIddictServerHandlerFilter<TContext>>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1179,6 +1195,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<TFilter>() .AddFilter<TFilter>()
.UseSingletonHandler<ProcessPassthroughErrorResponse<TContext, TFilter>>() .UseSingletonHandler<ProcessPassthroughErrorResponse<TContext, TFilter>>()
.SetOrder(ProcessStatusCodePagesErrorResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessStatusCodePagesErrorResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1230,6 +1247,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireStatusCodePagesIntegrationEnabled>() .AddFilter<RequireStatusCodePagesIntegrationEnabled>()
.UseSingletonHandler<ProcessStatusCodePagesErrorResponse<TContext>>() .UseSingletonHandler<ProcessStatusCodePagesErrorResponse<TContext>>()
.SetOrder(ProcessLocalErrorResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessLocalErrorResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1292,6 +1310,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessLocalErrorResponse<TContext>>() .UseSingletonHandler<ProcessLocalErrorResponse<TContext>>()
.SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1373,6 +1392,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessHostRedirectionResponse<TContext>>() .UseSingletonHandler<ProcessHostRedirectionResponse<TContext>>()
.SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1425,6 +1445,7 @@ namespace OpenIddict.Server.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessEmptyResponse<TContext>>() .UseSingletonHandler<ProcessEmptyResponse<TContext>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

5
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. // Register the built-in event handlers used by the OpenIddict Data Protection server components.
foreach (var handler in OpenIddictServerDataProtectionHandlers.DefaultHandlers) options.Handlers.AddRange(OpenIddictServerDataProtectionHandlers.DefaultHandlers);
{
options.DefaultHandlers.Add(handler);
}
} }
/// <summary> /// <summary>

6
src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs

@ -62,6 +62,7 @@ namespace OpenIddict.Server.DataProtection
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateDataProtectionToken>() .UseSingletonHandler<ValidateDataProtectionToken>()
.SetOrder(ValidateIdentityModelToken.Descriptor.Order + 500) .SetOrder(ValidateIdentityModelToken.Descriptor.Order + 500)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -180,6 +181,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter<RequireDataProtectionFormatEnabled>() .AddFilter<RequireDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionAccessToken>() .UseSingletonHandler<GenerateDataProtectionAccessToken>()
.SetOrder(GenerateIdentityModelAccessToken.Descriptor.Order - 500) .SetOrder(GenerateIdentityModelAccessToken.Descriptor.Order - 500)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -244,6 +246,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter<RequireDataProtectionFormatEnabled>() .AddFilter<RequireDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionAuthorizationCode>() .UseSingletonHandler<GenerateDataProtectionAuthorizationCode>()
.SetOrder(GenerateIdentityModelAuthorizationCode.Descriptor.Order - 500) .SetOrder(GenerateIdentityModelAuthorizationCode.Descriptor.Order - 500)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -308,6 +311,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter<RequireDataProtectionFormatEnabled>() .AddFilter<RequireDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionDeviceCode>() .UseSingletonHandler<GenerateDataProtectionDeviceCode>()
.SetOrder(GenerateIdentityModelDeviceCode.Descriptor.Order - 500) .SetOrder(GenerateIdentityModelDeviceCode.Descriptor.Order - 500)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -372,6 +376,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter<RequireDataProtectionFormatEnabled>() .AddFilter<RequireDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionRefreshToken>() .UseSingletonHandler<GenerateDataProtectionRefreshToken>()
.SetOrder(GenerateIdentityModelRefreshToken.Descriptor.Order - 500) .SetOrder(GenerateIdentityModelRefreshToken.Descriptor.Order - 500)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -436,6 +441,7 @@ namespace OpenIddict.Server.DataProtection
.AddFilter<RequireDataProtectionFormatEnabled>() .AddFilter<RequireDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionUserCode>() .UseSingletonHandler<GenerateDataProtectionUserCode>()
.SetOrder(GenerateIdentityModelUserCode.Descriptor.Order - 500) .SetOrder(GenerateIdentityModelUserCode.Descriptor.Order - 500)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

5
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. // Register the built-in event handlers used by the OpenIddict OWIN server components.
foreach (var handler in OpenIddictServerOwinHandlers.DefaultHandlers) options.Handlers.AddRange(OpenIddictServerOwinHandlers.DefaultHandlers);
{
options.DefaultHandlers.Add(handler);
}
} }
public void PostConfigure([CanBeNull] string name, [NotNull] OpenIddictServerOwinOptions options) public void PostConfigure([CanBeNull] string name, [NotNull] OpenIddictServerOwinOptions options)

35
src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs

@ -24,14 +24,21 @@ namespace OpenIddict.Server.Owin
/// </summary> /// </summary>
public class OpenIddictServerOwinHandler : AuthenticationHandler<OpenIddictServerOwinOptions> public class OpenIddictServerOwinHandler : AuthenticationHandler<OpenIddictServerOwinOptions>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
private readonly IOpenIddictServerFactory _factory;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictServerOwinHandler"/> class. /// Creates a new instance of the <see cref="OpenIddictServerOwinHandler"/> class.
/// </summary> /// </summary>
/// <param name="provider">The OpenIddict server OWIN provider used by this instance.</param> /// <param name="dispatcher">The OpenIddict server provider used by this instance.</param>
public OpenIddictServerOwinHandler([NotNull] IOpenIddictServerProvider provider) /// <param name="factory">The OpenIddict server factory used by this instance.</param>
=> _provider = provider; public OpenIddictServerOwinHandler(
[NotNull] IOpenIddictServerDispatcher dispatcher,
[NotNull] IOpenIddictServerFactory factory)
{
_dispatcher = dispatcher;
_factory = factory;
}
protected override async Task InitializeCoreAsync() protected override async Task InitializeCoreAsync()
{ {
@ -41,7 +48,7 @@ namespace OpenIddict.Server.Owin
if (transaction == null) if (transaction == null)
{ {
// Create a new transaction and attach the OWIN request to make it available to the OWIN handlers. // 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<IOwinRequest>(Request); transaction.Properties[typeof(IOwinRequest).FullName] = new WeakReference<IOwinRequest>(Request);
// Attach the OpenIddict server transaction to the OWIN shared dictionary // Attach the OpenIddict server transaction to the OWIN shared dictionary
@ -50,7 +57,7 @@ namespace OpenIddict.Server.Owin
} }
var context = new ProcessRequestContext(transaction); 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(). // Store the context in the transaction so that it can be retrieved from InvokeAsync().
transaction.SetProperty(typeof(ProcessRequestContext).FullName, context); 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) if (notification.IsRequestHandled)
{ {
@ -127,7 +134,7 @@ namespace OpenIddict.Server.Owin
if (context == null) if (context == null)
{ {
context = new ProcessAuthenticationContext(transaction); 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 // 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. // that want to access the authentication result without triggering a new authentication flow.
@ -202,7 +209,7 @@ namespace OpenIddict.Server.Owin
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) 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) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {
@ -250,7 +257,7 @@ namespace OpenIddict.Server.Owin
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) 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) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {
@ -297,7 +304,7 @@ namespace OpenIddict.Server.Owin
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) 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) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {

21
src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs

@ -68,6 +68,7 @@ namespace OpenIddict.Server.Owin
// Note: this handler must be invoked before any other handler, // Note: this handler must be invoked before any other handler,
// including the built-in handlers defined in OpenIddict.Server. // including the built-in handlers defined in OpenIddict.Server.
.SetOrder(int.MinValue + 50_000) .SetOrder(int.MinValue + 50_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -107,7 +108,7 @@ namespace OpenIddict.Server.Owin
return default; return default;
static bool Matches(IOwinRequest request, IList<Uri> addresses) static bool Matches(IOwinRequest request, IReadOnlyList<Uri> addresses)
{ {
for (var index = 0; index < addresses.Count; index++) for (var index = 0; index < addresses.Count; index++)
{ {
@ -170,6 +171,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<InferIssuerFromHost>() .UseSingletonHandler<InferIssuerFromHost>()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000) .SetOrder(InferEndpointType.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -241,6 +243,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireTransportSecurityRequirementEnabled>() .AddFilter<RequireTransportSecurityRequirementEnabled>()
.UseSingletonHandler<ValidateTransportSecurityRequirement>() .UseSingletonHandler<ValidateTransportSecurityRequirement>()
.SetOrder(InferEndpointType.Descriptor.Order + 1_000) .SetOrder(InferEndpointType.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -299,6 +302,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachHostChallengeError>() .UseSingletonHandler<AttachHostChallengeError>()
.SetOrder(AttachDefaultChallengeError.Descriptor.Order - 1_000) .SetOrder(AttachDefaultChallengeError.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -345,6 +349,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ExtractGetRequest<TContext>>() .UseSingletonHandler<ExtractGetRequest<TContext>>()
.SetOrder(ValidateTransportSecurityRequirement.Descriptor.Order + 1_000) .SetOrder(ValidateTransportSecurityRequirement.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -404,6 +409,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ExtractGetOrPostRequest<TContext>>() .UseSingletonHandler<ExtractGetOrPostRequest<TContext>>()
.SetOrder(ExtractGetRequest<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractGetRequest<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -491,6 +497,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ExtractPostRequest<TContext>>() .UseSingletonHandler<ExtractPostRequest<TContext>>()
.SetOrder(ExtractGetOrPostRequest<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractGetOrPostRequest<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -574,6 +581,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ExtractBasicAuthenticationCredentials<TContext>>() .UseSingletonHandler<ExtractBasicAuthenticationCredentials<TContext>>()
.SetOrder(ExtractPostRequest<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractPostRequest<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -675,6 +683,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ExtractAccessToken<TContext>>() .UseSingletonHandler<ExtractAccessToken<TContext>>()
.SetOrder(ExtractBasicAuthenticationCredentials<TContext>.Descriptor.Order + 1_000) .SetOrder(ExtractBasicAuthenticationCredentials<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -729,6 +738,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<TFilter>() .AddFilter<TFilter>()
.UseSingletonHandler<EnablePassthroughMode<TContext, TFilter>>() .UseSingletonHandler<EnablePassthroughMode<TContext, TFilter>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -765,6 +775,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachHttpResponseCode<TContext>>() .UseSingletonHandler<AttachHttpResponseCode<TContext>>()
.SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -828,6 +839,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachCacheControlHeader<TContext>>() .UseSingletonHandler<AttachCacheControlHeader<TContext>>()
.SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -880,6 +892,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>() .UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>()
.SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -997,6 +1010,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>() .UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>()
.SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1048,6 +1062,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessJsonResponse<TContext>>() .UseSingletonHandler<ProcessJsonResponse<TContext>>()
.SetOrder(ProcessPassthroughErrorResponse<TContext, IOpenIddictServerHandlerFilter<TContext>>.Descriptor.Order - 1_000) .SetOrder(ProcessPassthroughErrorResponse<TContext, IOpenIddictServerHandlerFilter<TContext>>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1110,6 +1125,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<TFilter>() .AddFilter<TFilter>()
.UseSingletonHandler<ProcessPassthroughErrorResponse<TContext, TFilter>>() .UseSingletonHandler<ProcessPassthroughErrorResponse<TContext, TFilter>>()
.SetOrder(ProcessLocalErrorResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessLocalErrorResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1163,6 +1179,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessLocalErrorResponse<TContext>>() .UseSingletonHandler<ProcessLocalErrorResponse<TContext>>()
.SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1244,6 +1261,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessHostRedirectionResponse<TContext>>() .UseSingletonHandler<ProcessHostRedirectionResponse<TContext>>()
.SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessEmptyResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1296,6 +1314,7 @@ namespace OpenIddict.Server.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessEmptyResponse<TContext>>() .UseSingletonHandler<ProcessEmptyResponse<TContext>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

16
src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddleware.cs

@ -19,26 +19,32 @@ namespace OpenIddict.Server.Owin
/// </summary> /// </summary>
public class OpenIddictServerOwinMiddleware : AuthenticationMiddleware<OpenIddictServerOwinOptions> public class OpenIddictServerOwinMiddleware : AuthenticationMiddleware<OpenIddictServerOwinOptions>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
private readonly IOpenIddictServerFactory _factory;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictServerOwinMiddleware"/> class. /// Creates a new instance of the <see cref="OpenIddictServerOwinMiddleware"/> class.
/// </summary> /// </summary>
/// <param name="next">The next middleware in the pipeline, if applicable.</param> /// <param name="next">The next middleware in the pipeline, if applicable.</param>
/// <param name="options">The OpenIddict server OWIN options.</param> /// <param name="options">The OpenIddict server OWIN options.</param>
/// <param name="provider">The OpenIddict server provider.</param> /// <param name="dispatcher">The OpenIddict server dispatcher.</param>
/// <param name="factory">The OpenIddict server factory.</param>
public OpenIddictServerOwinMiddleware( public OpenIddictServerOwinMiddleware(
[CanBeNull] OwinMiddleware next, [CanBeNull] OwinMiddleware next,
[NotNull] IOptionsMonitor<OpenIddictServerOwinOptions> options, [NotNull] IOptionsMonitor<OpenIddictServerOwinOptions> options,
[NotNull] IOpenIddictServerProvider provider) [NotNull] IOpenIddictServerDispatcher dispatcher,
[NotNull] IOpenIddictServerFactory factory)
: base(next, options.CurrentValue) : base(next, options.CurrentValue)
=> _provider = provider; {
_dispatcher = dispatcher;
_factory = factory;
}
/// <summary> /// <summary>
/// Creates and returns a new <see cref="OpenIddictServerOwinHandler"/> instance. /// Creates and returns a new <see cref="OpenIddictServerOwinHandler"/> instance.
/// </summary> /// </summary>
/// <returns>A new instance of the <see cref="OpenIddictServerOwinHandler"/> class.</returns> /// <returns>A new instance of the <see cref="OpenIddictServerOwinHandler"/> class.</returns>
protected override AuthenticationHandler<OpenIddictServerOwinOptions> CreateHandler() protected override AuthenticationHandler<OpenIddictServerOwinOptions> CreateHandler()
=> new OpenIddictServerOwinHandler(_provider); => new OpenIddictServerOwinHandler(_dispatcher, _factory);
} }
} }

5
src/OpenIddict.Server.Owin/OpenIddictServerOwinMiddlewareFactory.cs

@ -64,13 +64,14 @@ namespace OpenIddict.Server.Owin
var middleware = new OpenIddictServerOwinMiddleware( var middleware = new OpenIddictServerOwinMiddleware(
next: Next, next: Next,
options: GetRequiredService<IOptionsMonitor<OpenIddictServerOwinOptions>>(provider), options: GetRequiredService<IOptionsMonitor<OpenIddictServerOwinOptions>>(provider),
provider: GetRequiredService<IOpenIddictServerProvider>(provider)); dispatcher: GetRequiredService<IOpenIddictServerDispatcher>(provider),
factory: GetRequiredService<IOpenIddictServerFactory>(provider));
return middleware.Invoke(context); return middleware.Invoke(context);
static T GetRequiredService<T>(IServiceProvider provider) static T GetRequiredService<T>(IServiceProvider provider)
=> provider.GetService<T>() ?? throw new InvalidOperationException(new StringBuilder() => provider.GetService<T>() ?? 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()'.") .Append("To register the OWIN services, use 'services.AddOpenIddict().AddServer().UseOwin()'.")
.ToString()); .ToString());
} }

3
src/OpenIddict.Server/IOpenIddictServerProvider.cs → src/OpenIddict.Server/IOpenIddictServerDispatcher.cs

@ -10,9 +10,8 @@ using static OpenIddict.Server.OpenIddictServerEvents;
namespace OpenIddict.Server namespace OpenIddict.Server
{ {
public interface IOpenIddictServerProvider public interface IOpenIddictServerDispatcher
{ {
ValueTask<OpenIddictServerTransaction> CreateTransactionAsync();
ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext; ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext;
} }
} }

15
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<OpenIddictServerTransaction> CreateTransactionAsync();
}
}

21
src/OpenIddict.Server/OpenIddictServerBuilder.cs

@ -56,7 +56,10 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(configuration)); throw new ArgumentNullException(nameof(configuration));
} }
var builder = OpenIddictServerHandlerDescriptor.CreateBuilder<TContext>(); // Note: handlers registered using this API are assumed to be custom handlers by default.
var builder = OpenIddictServerHandlerDescriptor.CreateBuilder<TContext>()
.SetType(OpenIddictServerHandlerType.Custom);
configuration(builder); configuration(builder);
return AddEventHandler(builder.Build()); return AddEventHandler(builder.Build());
@ -78,7 +81,7 @@ namespace Microsoft.Extensions.DependencyInjection
// Register the handler in the services collection. // Register the handler in the services collection.
Services.Add(descriptor.ServiceDescriptor); Services.Add(descriptor.ServiceDescriptor);
return Configure(options => options.CustomHandlers.Add(descriptor)); return Configure(options => options.Handlers.Add(descriptor));
} }
/// <summary> /// <summary>
@ -98,19 +101,11 @@ namespace Microsoft.Extensions.DependencyInjection
Services.PostConfigure<OpenIddictServerOptions>(options => Services.PostConfigure<OpenIddictServerOptions>(options =>
{ {
for (var index = options.CustomHandlers.Count - 1; index >= 0; index--) for (var index = options.Handlers.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--)
{ {
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);
} }
} }
}); });

30
src/OpenIddict.Server/OpenIddictServerConfiguration.cs

@ -134,8 +134,9 @@ namespace OpenIddict.Server
// If the degraded mode was enabled, ensure custom validation handlers // If the degraded mode was enabled, ensure custom validation handlers
// have been registered for the endpoints that require manual validation. // 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 => descriptor.ContextType == typeof(ValidateAuthorizationRequestContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -145,8 +146,9 @@ namespace OpenIddict.Server
.ToString()); .ToString());
} }
if (options.DeviceEndpointUris.Count != 0 && !options.CustomHandlers.Any( if (options.DeviceEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateDeviceRequestContext) && descriptor => descriptor.ContextType == typeof(ValidateDeviceRequestContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -156,8 +158,9 @@ namespace OpenIddict.Server
.ToString()); .ToString());
} }
if (options.IntrospectionEndpointUris.Count != 0 && !options.CustomHandlers.Any( if (options.IntrospectionEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateIntrospectionRequestContext) && descriptor => descriptor.ContextType == typeof(ValidateIntrospectionRequestContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -167,8 +170,9 @@ namespace OpenIddict.Server
.ToString()); .ToString());
} }
if (options.LogoutEndpointUris.Count != 0 && !options.CustomHandlers.Any( if (options.LogoutEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateLogoutRequestContext) && descriptor => descriptor.ContextType == typeof(ValidateLogoutRequestContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -178,8 +182,9 @@ namespace OpenIddict.Server
.ToString()); .ToString());
} }
if (options.RevocationEndpointUris.Count != 0 && !options.CustomHandlers.Any( if (options.RevocationEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateRevocationRequestContext) && descriptor => descriptor.ContextType == typeof(ValidateRevocationRequestContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -189,8 +194,9 @@ namespace OpenIddict.Server
.ToString()); .ToString());
} }
if (options.TokenEndpointUris.Count != 0 && !options.CustomHandlers.Any( if (options.TokenEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateTokenRequestContext) && descriptor => descriptor.ContextType == typeof(ValidateTokenRequestContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -200,8 +206,9 @@ namespace OpenIddict.Server
.ToString()); .ToString());
} }
if (options.VerificationEndpointUris.Count != 0 && !options.CustomHandlers.Any( if (options.VerificationEndpointUris.Count != 0 && !options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ValidateVerificationRequestContext) && descriptor => descriptor.ContextType == typeof(ValidateVerificationRequestContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -216,8 +223,9 @@ namespace OpenIddict.Server
if (options.GrantTypes.Contains(GrantTypes.DeviceCode)) if (options.GrantTypes.Contains(GrantTypes.DeviceCode))
{ {
if (!options.CustomHandlers.Any( if (!options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ProcessAuthenticationContext) && descriptor => descriptor.ContextType == typeof(ProcessAuthenticationContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
@ -227,8 +235,9 @@ namespace OpenIddict.Server
.ToString()); .ToString());
} }
if (!options.CustomHandlers.Any( if (!options.Handlers.Any(
descriptor => descriptor.ContextType == typeof(ProcessSignInContext) && descriptor => descriptor.ContextType == typeof(ProcessSignInContext) &&
descriptor.Type == OpenIddictServerHandlerType.Custom &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type)))) descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{ {
throw new InvalidOperationException(new StringBuilder() 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. // Automatically add the offline_access scope if the refresh token grant has been enabled.
if (options.GrantTypes.Contains(GrantTypes.RefreshToken)) if (options.GrantTypes.Contains(GrantTypes.RefreshToken))
{ {

32
src/OpenIddict.Server/OpenIddictServerProvider.cs → src/OpenIddict.Server/OpenIddictServerDispatcher.cs

@ -15,17 +15,17 @@ using static OpenIddict.Server.OpenIddictServerEvents;
namespace OpenIddict.Server namespace OpenIddict.Server
{ {
public class OpenIddictServerProvider : IOpenIddictServerProvider public class OpenIddictServerDispatcher : IOpenIddictServerDispatcher
{ {
private readonly ILogger<OpenIddictServerProvider> _logger; private readonly ILogger<OpenIddictServerDispatcher> _logger;
private readonly IOptionsMonitor<OpenIddictServerOptions> _options; private readonly IOptionsMonitor<OpenIddictServerOptions> _options;
private readonly IServiceProvider _provider; private readonly IServiceProvider _provider;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictServerProvider"/> class. /// Creates a new instance of the <see cref="OpenIddictServerDispatcher"/> class.
/// </summary> /// </summary>
public OpenIddictServerProvider( public OpenIddictServerDispatcher(
[NotNull] ILogger<OpenIddictServerProvider> logger, [NotNull] ILogger<OpenIddictServerDispatcher> logger,
[NotNull] IOptionsMonitor<OpenIddictServerOptions> options, [NotNull] IOptionsMonitor<OpenIddictServerOptions> options,
[NotNull] IServiceProvider provider) [NotNull] IServiceProvider provider)
{ {
@ -34,14 +34,6 @@ namespace OpenIddict.Server
_provider = provider; _provider = provider;
} }
public ValueTask<OpenIddictServerTransaction> CreateTransactionAsync()
=> new ValueTask<OpenIddictServerTransaction>(new OpenIddictServerTransaction
{
Issuer = _options.CurrentValue.Issuer,
Logger = _logger,
Options = _options.CurrentValue
});
public async ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext public async ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext
{ {
if (context == null) if (context == null)
@ -82,14 +74,12 @@ namespace OpenIddict.Server
async IAsyncEnumerable<IOpenIddictServerHandler<TContext>> GetHandlersAsync() async IAsyncEnumerable<IOpenIddictServerHandler<TContext>> GetHandlersAsync()
{ {
var descriptors = new List<OpenIddictServerHandlerDescriptor>( // Note: the descriptors collection is sorted during options initialization for performance reasons.
capacity: _options.CurrentValue.CustomHandlers.Count + var descriptors = _options.CurrentValue.Handlers;
_options.CurrentValue.DefaultHandlers.Count); if (descriptors.Count == 0)
{
descriptors.AddRange(_options.CurrentValue.CustomHandlers); yield break;
descriptors.AddRange(_options.CurrentValue.DefaultHandlers); }
descriptors.Sort((left, right) => left.Order.CompareTo(right.Order));
for (var index = 0; index < descriptors.Count; index++) for (var index = 0; index < descriptors.Count; index++)
{ {

35
src/OpenIddict.Server/OpenIddictServerEvents.Discovery.cs

@ -107,78 +107,67 @@ namespace OpenIddict.Server
/// <summary> /// <summary>
/// Gets the list of claims supported by the authorization server. /// Gets the list of claims supported by the authorization server.
/// </summary> /// </summary>
public ISet<string> Claims { get; } = public HashSet<string> Claims { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets a list of the code challenge methods /// Gets a list of the code challenge methods
/// supported by the authorization server. /// supported by the authorization server.
/// </summary> /// </summary>
public ISet<string> CodeChallengeMethods { get; } = public HashSet<string> CodeChallengeMethods { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the list of grant types /// Gets the list of grant types
/// supported by the authorization server. /// supported by the authorization server.
/// </summary> /// </summary>
public ISet<string> GrantTypes { get; } = public HashSet<string> GrantTypes { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets a list of signing algorithms supported by the /// Gets a list of signing algorithms supported by the
/// authorization server for signing the identity tokens. /// authorization server for signing the identity tokens.
/// </summary> /// </summary>
public ISet<string> IdTokenSigningAlgorithms { get; } = public HashSet<string> IdTokenSigningAlgorithms { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets a list of client authentication methods supported by /// Gets a list of client authentication methods supported by
/// the introspection endpoint provided by the authorization server. /// the introspection endpoint provided by the authorization server.
/// </summary> /// </summary>
public ISet<string> IntrospectionEndpointAuthenticationMethods { get; } = public HashSet<string> IntrospectionEndpointAuthenticationMethods { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the list of response modes /// Gets the list of response modes
/// supported by the authorization server. /// supported by the authorization server.
/// </summary> /// </summary>
public ISet<string> ResponseModes { get; } = public HashSet<string> ResponseModes { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the list of response types /// Gets the list of response types
/// supported by the authorization server. /// supported by the authorization server.
/// </summary> /// </summary>
public ISet<string> ResponseTypes { get; } = public HashSet<string> ResponseTypes { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets a list of client authentication methods supported by /// Gets a list of client authentication methods supported by
/// the revocation endpoint provided by the authorization server. /// the revocation endpoint provided by the authorization server.
/// </summary> /// </summary>
public ISet<string> RevocationEndpointAuthenticationMethods { get; } = public HashSet<string> RevocationEndpointAuthenticationMethods { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the list of scope values /// Gets the list of scope values
/// supported by the authorization server. /// supported by the authorization server.
/// </summary> /// </summary>
public ISet<string> Scopes { get; } = public HashSet<string> Scopes { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the list of subject types /// Gets the list of subject types
/// supported by the authorization server. /// supported by the authorization server.
/// </summary> /// </summary>
public ISet<string> SubjectTypes { get; } = public HashSet<string> SubjectTypes { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets a list of client authentication methods supported by /// Gets a list of client authentication methods supported by
/// the token endpoint provided by the authorization server. /// the token endpoint provided by the authorization server.
/// </summary> /// </summary>
public ISet<string> TokenEndpointAuthenticationMethods { get; } = public HashSet<string> TokenEndpointAuthenticationMethods { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
} }
/// <summary> /// <summary>
@ -249,7 +238,7 @@ namespace OpenIddict.Server
/// <summary> /// <summary>
/// Gets the list of JSON Web Keys exposed by the JWKS endpoint. /// Gets the list of JSON Web Keys exposed by the JWKS endpoint.
/// </summary> /// </summary>
public IList<JsonWebKey> Keys { get; } = new List<JsonWebKey>(); public List<JsonWebKey> Keys { get; } = new List<JsonWebKey>();
} }
/// <summary> /// <summary>

6
src/OpenIddict.Server/OpenIddictServerEvents.Introspection.cs

@ -84,8 +84,7 @@ namespace OpenIddict.Server
/// Gets the list of audiences returned to the caller /// Gets the list of audiences returned to the caller
/// as part of the "aud" claim, if applicable. /// as part of the "aud" claim, if applicable.
/// </summary> /// </summary>
public ISet<string> Audiences { get; } = public HashSet<string> Audiences { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets or sets the "client_id" claim /// Gets or sets the "client_id" claim
@ -115,8 +114,7 @@ namespace OpenIddict.Server
/// Gets the list of scopes returned to the caller /// Gets the list of scopes returned to the caller
/// as part of the "scope" claim, if applicable. /// as part of the "scope" claim, if applicable.
/// </summary> /// </summary>
public ISet<string> Scopes { get; } = public HashSet<string> Scopes { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets or sets the "sub" claim /// Gets or sets the "sub" claim

3
src/OpenIddict.Server/OpenIddictServerEvents.Userinfo.cs

@ -85,8 +85,7 @@ namespace OpenIddict.Server
/// <summary> /// <summary>
/// Gets or sets the values used for the "aud" claim. /// Gets or sets the values used for the "aud" claim.
/// </summary> /// </summary>
public ISet<string> Audiences { get; } = public HashSet<string> Audiences { get; } = new HashSet<string>(StringComparer.Ordinal);
new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets or sets the value used for the "birthdate" claim. /// Gets or sets the value used for the "birthdate" claim.

3
src/OpenIddict.Server/OpenIddictServerExtensions.cs

@ -36,7 +36,8 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.AddLogging(); builder.Services.AddLogging();
builder.Services.AddOptions(); builder.Services.AddOptions();
builder.Services.TryAddScoped<IOpenIddictServerProvider, OpenIddictServerProvider>(); builder.Services.TryAddScoped<IOpenIddictServerDispatcher, OpenIddictServerDispatcher>();
builder.Services.TryAddScoped<IOpenIddictServerFactory, OpenIddictServerFactory>();
// Register the built-in server event handlers used by the OpenIddict server components. // Register the built-in server event handlers used by the OpenIddict server components.
// Note: the order used here is not important, as the actual order is set in the options. // Note: the order used here is not important, as the actual order is set in the options.

38
src/OpenIddict.Server/OpenIddictServerFactory.cs

@ -0,0 +1,38 @@
/*
* 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;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace OpenIddict.Server
{
public class OpenIddictServerFactory : IOpenIddictServerFactory
{
private readonly ILogger<OpenIddictServerDispatcher> _logger;
private readonly IOptionsMonitor<OpenIddictServerOptions> _options;
/// <summary>
/// Creates a new instance of the <see cref="OpenIddictServerDispatcher"/> class.
/// </summary>
public OpenIddictServerFactory(
[NotNull] ILogger<OpenIddictServerDispatcher> logger,
[NotNull] IOptionsMonitor<OpenIddictServerOptions> options)
{
_logger = logger;
_options = options;
}
public ValueTask<OpenIddictServerTransaction> CreateTransactionAsync()
=> new ValueTask<OpenIddictServerTransaction>(new OpenIddictServerTransaction
{
Issuer = _options.CurrentValue.Issuer,
Logger = _logger,
Options = _options.CurrentValue
});
}
}

27
src/OpenIddict.Server/OpenIddictServerHandlerDescriptor.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
@ -47,6 +48,11 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public ServiceDescriptor ServiceDescriptor { get; private set; } public ServiceDescriptor ServiceDescriptor { get; private set; }
/// <summary>
/// Gets the type associated with the handler.
/// </summary>
public OpenIddictServerHandlerType Type { get; private set; }
/// <summary> /// <summary>
/// Creates a builder allowing to initialize an immutable descriptor. /// Creates a builder allowing to initialize an immutable descriptor.
/// </summary> /// </summary>
@ -64,6 +70,7 @@ namespace OpenIddict.Server
private ServiceDescriptor _descriptor; private ServiceDescriptor _descriptor;
private readonly List<Type> _filterTypes = new List<Type>(); private readonly List<Type> _filterTypes = new List<Type>();
private int _order; private int _order;
private OpenIddictServerHandlerType _type;
/// <summary> /// <summary>
/// Adds the type of a handler filter to the filters list. /// Adds the type of a handler filter to the filters list.
@ -131,6 +138,23 @@ namespace OpenIddict.Server
return this; return this;
} }
/// <summary>
/// Sets the type associated to the handler.
/// </summary>
/// <param name="type">The handler type.</param>
/// <returns>The builder instance, so that calls can be easily chained.</returns>
public Builder<TContext> SetType(OpenIddictServerHandlerType type)
{
if (!Enum.IsDefined(typeof(OpenIddictServerHandlerType), type))
{
throw new InvalidEnumArgumentException(nameof(type), (int) type, typeof(OpenIddictServerHandlerType));
}
_type = type;
return this;
}
/// <summary> /// <summary>
/// Configures the descriptor to use the specified inline handler. /// Configures the descriptor to use the specified inline handler.
/// </summary> /// </summary>
@ -192,7 +216,8 @@ namespace OpenIddict.Server
ContextType = typeof(TContext), ContextType = typeof(TContext),
FilterTypes = _filterTypes.ToImmutableArray(), FilterTypes = _filterTypes.ToImmutableArray(),
Order = _order, Order = _order,
ServiceDescriptor = _descriptor ?? throw new InvalidOperationException("No service descriptor was set.") ServiceDescriptor = _descriptor ?? throw new InvalidOperationException("No service descriptor was set."),
Type = _type
}; };
} }
} }

29
src/OpenIddict.Server/OpenIddictServerHandlerType.cs

@ -0,0 +1,29 @@
/*
* 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.
*/
namespace OpenIddict.Server
{
/// <summary>
/// Represents the type of an OpenIddict server handler.
/// </summary>
public enum OpenIddictServerHandlerType
{
/// <summary>
/// The handler is of an unspecified type.
/// </summary>
Unknown = 0,
/// <summary>
/// The handler is a built-in handler, provided as part of the official OpenIddict packages.
/// </summary>
BuiltIn = 1,
/// <summary>
/// The handler is a custom handler, registered by the end user or a third-party package.
/// </summary>
Custom = 2
}
}

34
src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs

@ -69,10 +69,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractAuthorizationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractAuthorizationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractAuthorizationRequest([NotNull] IOpenIddictServerProvider provider) public ExtractAuthorizationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -103,7 +103,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractAuthorizationRequestContext(context.Transaction); var notification = new ExtractAuthorizationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -144,10 +144,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateAuthorizationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateAuthorizationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateAuthorizationRequest([NotNull] IOpenIddictServerProvider provider) public ValidateAuthorizationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -178,7 +178,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateAuthorizationRequestContext(context.Transaction); var notification = new ValidateAuthorizationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the redirect_uri without triggering a new validation process. // that want to access the redirect_uri without triggering a new validation process.
@ -219,10 +219,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleAuthorizationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleAuthorizationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleAuthorizationRequest([NotNull] IOpenIddictServerProvider provider) public HandleAuthorizationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -253,7 +253,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleAuthorizationRequestContext(context.Transaction); var notification = new HandleAuthorizationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -284,7 +284,7 @@ namespace OpenIddict.Server
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(@event); await _dispatcher.DispatchAsync(@event);
if (@event.IsRequestHandled) if (@event.IsRequestHandled)
{ {
@ -322,10 +322,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyAuthorizationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyAuthorizationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyAuthorizationResponse([NotNull] IOpenIddictServerProvider provider) public ApplyAuthorizationResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -356,7 +356,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyAuthorizationResponseContext(context.Transaction); var notification = new ApplyAuthorizationResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {

76
src/OpenIddict.Server/OpenIddictServerHandlers.Device.cs

@ -67,10 +67,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractDeviceRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractDeviceRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractDeviceRequest([NotNull] IOpenIddictServerProvider provider) public ExtractDeviceRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -101,7 +101,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractDeviceRequestContext(context.Transaction); var notification = new ExtractDeviceRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -142,10 +142,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateDeviceRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateDeviceRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateDeviceRequest([NotNull] IOpenIddictServerProvider provider) public ValidateDeviceRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -176,7 +176,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateDeviceRequestContext(context.Transaction); var notification = new ValidateDeviceRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -208,10 +208,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleDeviceRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleDeviceRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleDeviceRequest([NotNull] IOpenIddictServerProvider provider) public HandleDeviceRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -242,7 +242,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleDeviceRequestContext(context.Transaction); var notification = new HandleDeviceRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -280,7 +280,7 @@ namespace OpenIddict.Server
@event.Principal = principal; @event.Principal = principal;
} }
await _provider.DispatchAsync(@event); await _dispatcher.DispatchAsync(@event);
if (@event.IsRequestHandled) if (@event.IsRequestHandled)
{ {
@ -317,10 +317,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyDeviceResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyDeviceResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyDeviceResponse([NotNull] IOpenIddictServerProvider provider) public ApplyDeviceResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -351,7 +351,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyDeviceResponseContext(context.Transaction); var notification = new ApplyDeviceResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -849,10 +849,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractVerificationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractVerificationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractVerificationRequest([NotNull] IOpenIddictServerProvider provider) public ExtractVerificationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -883,7 +883,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractVerificationRequestContext(context.Transaction); var notification = new ExtractVerificationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -924,10 +924,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateVerificationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateVerificationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateVerificationRequest([NotNull] IOpenIddictServerProvider provider) public ValidateVerificationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -958,7 +958,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateVerificationRequestContext(context.Transaction); var notification = new ValidateVerificationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -990,10 +990,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleVerificationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleVerificationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleVerificationRequest([NotNull] IOpenIddictServerProvider provider) public HandleVerificationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -1024,7 +1024,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleVerificationRequestContext(context.Transaction); var notification = new HandleVerificationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -1055,7 +1055,7 @@ namespace OpenIddict.Server
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(@event); await _dispatcher.DispatchAsync(@event);
if (@event.IsRequestHandled) if (@event.IsRequestHandled)
{ {
@ -1093,10 +1093,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyVerificationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyVerificationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyVerificationResponse([NotNull] IOpenIddictServerProvider provider) public ApplyVerificationResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -1127,7 +1127,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyVerificationResponseContext(context.Transaction); var notification = new ApplyVerificationResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -1154,10 +1154,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class AttachUserCodePrincipal : IOpenIddictServerHandler<HandleVerificationRequestContext> public class AttachUserCodePrincipal : IOpenIddictServerHandler<HandleVerificationRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public AttachUserCodePrincipal([NotNull] IOpenIddictServerProvider provider) public AttachUserCodePrincipal([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -1192,7 +1192,7 @@ namespace OpenIddict.Server
} }
var notification = new ProcessAuthenticationContext(context.Transaction); var notification = new ProcessAuthenticationContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // 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. // that want to access the authentication result without triggering a new authentication flow.

82
src/OpenIddict.Server/OpenIddictServerHandlers.Discovery.cs

@ -71,10 +71,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractConfigurationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractConfigurationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractConfigurationRequest([NotNull] IOpenIddictServerProvider provider) public ExtractConfigurationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -105,7 +105,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractConfigurationRequestContext(context.Transaction); var notification = new ExtractConfigurationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -146,10 +146,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateConfigurationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateConfigurationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateConfigurationRequest([NotNull] IOpenIddictServerProvider provider) public ValidateConfigurationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -180,7 +180,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateConfigurationRequestContext(context.Transaction); var notification = new ValidateConfigurationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -212,10 +212,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleConfigurationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleConfigurationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleConfigurationRequest([NotNull] IOpenIddictServerProvider provider) public HandleConfigurationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -246,7 +246,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleConfigurationRequestContext(context.Transaction); var notification = new HandleConfigurationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -307,10 +307,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyConfigurationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyConfigurationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyConfigurationResponse([NotNull] IOpenIddictServerProvider provider) public ApplyConfigurationResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -341,7 +341,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyConfigurationResponseContext(context.Transaction); var notification = new ApplyConfigurationResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -394,33 +394,33 @@ namespace OpenIddict.Server
// Note: while OpenIddict allows specifying multiple endpoint addresses, the OAuth 2.0 // Note: while OpenIddict allows specifying multiple endpoint addresses, the OAuth 2.0
// and OpenID Connect discovery specifications only allow a single address per endpoint. // and OpenID Connect discovery specifications only allow a single address per endpoint.
context.AuthorizationEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.AuthorizationEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.AuthorizationEndpointUris.FirstOrDefault()); context.Options.AuthorizationEndpointUris.FirstOrDefault());
context.CryptographyEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.CryptographyEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.CryptographyEndpointUris.FirstOrDefault()); context.Options.CryptographyEndpointUris.FirstOrDefault());
context.DeviceEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.DeviceEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.DeviceEndpointUris.FirstOrDefault()); context.Options.DeviceEndpointUris.FirstOrDefault());
context.IntrospectionEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.IntrospectionEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.IntrospectionEndpointUris.FirstOrDefault()); context.Options.IntrospectionEndpointUris.FirstOrDefault());
context.LogoutEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.LogoutEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.LogoutEndpointUris.FirstOrDefault()); context.Options.LogoutEndpointUris.FirstOrDefault());
context.RevocationEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.RevocationEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.RevocationEndpointUris.FirstOrDefault()); context.Options.RevocationEndpointUris.FirstOrDefault());
context.TokenEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.TokenEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.TokenEndpointUris.FirstOrDefault()); context.Options.TokenEndpointUris.FirstOrDefault());
context.UserinfoEndpoint ??= GetEndpointAbsoluteUrl(context.Issuer, context.UserinfoEndpoint ??= GetEndpointAbsoluteUri(context.Issuer,
context.Options.UserinfoEndpointUris.FirstOrDefault()); context.Options.UserinfoEndpointUris.FirstOrDefault());
return default; return default;
static Uri GetEndpointAbsoluteUrl(Uri issuer, Uri endpoint) static Uri GetEndpointAbsoluteUri(Uri issuer, Uri endpoint)
{ {
// If the endpoint is disabled (i.e a null address is specified), return null. // If the endpoint is disabled (i.e a null address is specified), return null.
if (endpoint == null) if (endpoint == null)
@ -863,10 +863,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractCryptographyRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractCryptographyRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractCryptographyRequest([NotNull] IOpenIddictServerProvider provider) public ExtractCryptographyRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -897,7 +897,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractCryptographyRequestContext(context.Transaction); var notification = new ExtractCryptographyRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -938,10 +938,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateCryptographyRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateCryptographyRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateCryptographyRequest([NotNull] IOpenIddictServerProvider provider) public ValidateCryptographyRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -972,7 +972,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateCryptographyRequestContext(context.Transaction); var notification = new ValidateCryptographyRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -1004,10 +1004,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleCryptographyRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleCryptographyRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleCryptographyRequest([NotNull] IOpenIddictServerProvider provider) public HandleCryptographyRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -1038,7 +1038,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleCryptographyRequestContext(context.Transaction); var notification = new HandleCryptographyRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -1142,10 +1142,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyCryptographyResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyCryptographyResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyCryptographyResponse([NotNull] IOpenIddictServerProvider provider) public ApplyCryptographyResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -1176,7 +1176,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyCryptographyResponseContext(context.Transaction); var notification = new ApplyCryptographyResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {

42
src/OpenIddict.Server/OpenIddictServerHandlers.Exchange.cs

@ -74,10 +74,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractTokenRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractTokenRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractTokenRequest([NotNull] IOpenIddictServerProvider provider) public ExtractTokenRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -108,7 +108,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractTokenRequestContext(context.Transaction); var notification = new ExtractTokenRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -149,10 +149,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateTokenRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateTokenRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateTokenRequest([NotNull] IOpenIddictServerProvider provider) public ValidateTokenRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -183,7 +183,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateTokenRequestContext(context.Transaction); var notification = new ValidateTokenRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the principal without triggering a new validation process. // that want to access the principal without triggering a new validation process.
@ -219,10 +219,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleTokenRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleTokenRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleTokenRequest([NotNull] IOpenIddictServerProvider provider) public HandleTokenRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -253,7 +253,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleTokenRequestContext(context.Transaction); var notification = new HandleTokenRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -284,7 +284,7 @@ namespace OpenIddict.Server
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(@event); await _dispatcher.DispatchAsync(@event);
if (@event.IsRequestHandled) if (@event.IsRequestHandled)
{ {
@ -322,10 +322,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyTokenResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyTokenResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyTokenResponse([NotNull] IOpenIddictServerProvider provider) public ApplyTokenResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -356,7 +356,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyTokenResponseContext(context.Transaction); var notification = new ApplyTokenResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -1332,10 +1332,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateToken : IOpenIddictServerHandler<ValidateTokenRequestContext> public class ValidateToken : IOpenIddictServerHandler<ValidateTokenRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateToken([NotNull] IOpenIddictServerProvider provider) public ValidateToken([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -1368,7 +1368,7 @@ namespace OpenIddict.Server
} }
var notification = new ProcessAuthenticationContext(context.Transaction); var notification = new ProcessAuthenticationContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // 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. // that want to access the authentication result without triggering a new authentication flow.

40
src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs

@ -68,10 +68,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractIntrospectionRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractIntrospectionRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractIntrospectionRequest([NotNull] IOpenIddictServerProvider provider) public ExtractIntrospectionRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -102,7 +102,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractIntrospectionRequestContext(context.Transaction); var notification = new ExtractIntrospectionRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -143,10 +143,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateIntrospectionRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateIntrospectionRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateIntrospectionRequest([NotNull] IOpenIddictServerProvider provider) public ValidateIntrospectionRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -177,7 +177,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateIntrospectionRequestContext(context.Transaction); var notification = new ValidateIntrospectionRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the principal without triggering a new validation process. // that want to access the principal without triggering a new validation process.
@ -213,10 +213,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleIntrospectionRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleIntrospectionRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleIntrospectionRequest([NotNull] IOpenIddictServerProvider provider) public HandleIntrospectionRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -247,7 +247,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleIntrospectionRequestContext(context.Transaction); var notification = new HandleIntrospectionRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -325,10 +325,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyIntrospectionResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyIntrospectionResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyIntrospectionResponse([NotNull] IOpenIddictServerProvider provider) public ApplyIntrospectionResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -359,7 +359,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyIntrospectionResponseContext(context.Transaction); var notification = new ApplyIntrospectionResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -752,10 +752,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateToken : IOpenIddictServerHandler<ValidateIntrospectionRequestContext> public class ValidateToken : IOpenIddictServerHandler<ValidateIntrospectionRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateToken([NotNull] IOpenIddictServerProvider provider) public ValidateToken([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -781,7 +781,7 @@ namespace OpenIddict.Server
} }
var notification = new ProcessAuthenticationContext(context.Transaction); var notification = new ProcessAuthenticationContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {

40
src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs

@ -60,10 +60,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractRevocationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractRevocationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractRevocationRequest([NotNull] IOpenIddictServerProvider provider) public ExtractRevocationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -94,7 +94,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractRevocationRequestContext(context.Transaction); var notification = new ExtractRevocationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -135,10 +135,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateRevocationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateRevocationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateRevocationRequest([NotNull] IOpenIddictServerProvider provider) public ValidateRevocationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -169,7 +169,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateRevocationRequestContext(context.Transaction); var notification = new ValidateRevocationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the principal without triggering a new validation process. // that want to access the principal without triggering a new validation process.
@ -205,10 +205,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleRevocationRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleRevocationRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleRevocationRequest([NotNull] IOpenIddictServerProvider provider) public HandleRevocationRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -239,7 +239,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleRevocationRequestContext(context.Transaction); var notification = new HandleRevocationRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -271,10 +271,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyRevocationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyRevocationResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyRevocationResponse([NotNull] IOpenIddictServerProvider provider) public ApplyRevocationResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -305,7 +305,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyRevocationResponseContext(context.Transaction); var notification = new ApplyRevocationResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -698,10 +698,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateToken : IOpenIddictServerHandler<ValidateRevocationRequestContext> public class ValidateToken : IOpenIddictServerHandler<ValidateRevocationRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateToken([NotNull] IOpenIddictServerProvider provider) public ValidateToken([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -727,7 +727,7 @@ namespace OpenIddict.Server
} }
var notification = new ProcessAuthenticationContext(context.Transaction); var notification = new ProcessAuthenticationContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {

34
src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs

@ -49,10 +49,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractLogoutRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractLogoutRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractLogoutRequest([NotNull] IOpenIddictServerProvider provider) public ExtractLogoutRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -83,7 +83,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractLogoutRequestContext(context.Transaction); var notification = new ExtractLogoutRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -124,10 +124,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateLogoutRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateLogoutRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateLogoutRequest([NotNull] IOpenIddictServerProvider provider) public ValidateLogoutRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -158,7 +158,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateLogoutRequestContext(context.Transaction); var notification = new ValidateLogoutRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the redirect_uri without triggering a new validation process. // that want to access the redirect_uri without triggering a new validation process.
@ -194,10 +194,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleLogoutRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleLogoutRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleLogoutRequest([NotNull] IOpenIddictServerProvider provider) public HandleLogoutRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -228,7 +228,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleLogoutRequestContext(context.Transaction); var notification = new HandleLogoutRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -256,7 +256,7 @@ namespace OpenIddict.Server
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(@event); await _dispatcher.DispatchAsync(@event);
if (@event.IsRequestHandled) if (@event.IsRequestHandled)
{ {
@ -293,10 +293,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyLogoutResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyLogoutResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyLogoutResponse([NotNull] IOpenIddictServerProvider provider) public ApplyLogoutResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -327,7 +327,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyLogoutResponseContext(context.Transaction); var notification = new ApplyLogoutResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {

40
src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs

@ -50,10 +50,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ExtractUserinfoRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ExtractUserinfoRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ExtractUserinfoRequest([NotNull] IOpenIddictServerProvider provider) public ExtractUserinfoRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -84,7 +84,7 @@ namespace OpenIddict.Server
} }
var notification = new ExtractUserinfoRequestContext(context.Transaction); var notification = new ExtractUserinfoRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -125,10 +125,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateUserinfoRequest : IOpenIddictServerHandler<ProcessRequestContext> public class ValidateUserinfoRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateUserinfoRequest([NotNull] IOpenIddictServerProvider provider) public ValidateUserinfoRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -159,7 +159,7 @@ namespace OpenIddict.Server
} }
var notification = new ValidateUserinfoRequestContext(context.Transaction); var notification = new ValidateUserinfoRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
// Store the context object in the transaction so it can be later retrieved by handlers // Store the context object in the transaction so it can be later retrieved by handlers
// that want to access the principal without triggering a new validation process. // that want to access the principal without triggering a new validation process.
@ -195,10 +195,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class HandleUserinfoRequest : IOpenIddictServerHandler<ProcessRequestContext> public class HandleUserinfoRequest : IOpenIddictServerHandler<ProcessRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public HandleUserinfoRequest([NotNull] IOpenIddictServerProvider provider) public HandleUserinfoRequest([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -229,7 +229,7 @@ namespace OpenIddict.Server
} }
var notification = new HandleUserinfoRequestContext(context.Transaction); var notification = new HandleUserinfoRequestContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -296,10 +296,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ApplyUserinfoResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext public class ApplyUserinfoResponse<TContext> : IOpenIddictServerHandler<TContext> where TContext : BaseRequestContext
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ApplyUserinfoResponse([NotNull] IOpenIddictServerProvider provider) public ApplyUserinfoResponse([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -330,7 +330,7 @@ namespace OpenIddict.Server
} }
var notification = new ApplyUserinfoResponseContext(context.Transaction); var notification = new ApplyUserinfoResponseContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -400,10 +400,10 @@ namespace OpenIddict.Server
/// </summary> /// </summary>
public class ValidateToken : IOpenIddictServerHandler<ValidateUserinfoRequestContext> public class ValidateToken : IOpenIddictServerHandler<ValidateUserinfoRequestContext>
{ {
private readonly IOpenIddictServerProvider _provider; private readonly IOpenIddictServerDispatcher _dispatcher;
public ValidateToken([NotNull] IOpenIddictServerProvider provider) public ValidateToken([NotNull] IOpenIddictServerDispatcher dispatcher)
=> _provider = provider; => _dispatcher = dispatcher;
/// <summary> /// <summary>
/// Gets the default descriptor definition assigned to this handler. /// Gets the default descriptor definition assigned to this handler.
@ -429,7 +429,7 @@ namespace OpenIddict.Server
} }
var notification = new ProcessAuthenticationContext(context.Transaction); var notification = new ProcessAuthenticationContext(context.Transaction);
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {

60
src/OpenIddict.Server/OpenIddictServerHandlers.cs

@ -132,6 +132,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateAuthenticationDemand>() .UseSingletonHandler<ValidateAuthenticationDemand>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -190,6 +191,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateTokenParameter>() .UseSingletonHandler<ValidateTokenParameter>()
.SetOrder(ValidateAuthenticationDemand.Descriptor.Order + 1_000) .SetOrder(ValidateAuthenticationDemand.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -263,6 +265,7 @@ namespace OpenIddict.Server
.AddFilter<RequireDegradedModeDisabled>() .AddFilter<RequireDegradedModeDisabled>()
.UseSingletonHandler<NormalizeUserCode>() .UseSingletonHandler<NormalizeUserCode>()
.SetOrder(ValidateTokenParameter.Descriptor.Order + 1_000) .SetOrder(ValidateTokenParameter.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -333,6 +336,7 @@ namespace OpenIddict.Server
.AddFilter<RequireTokenStorageEnabled>() .AddFilter<RequireTokenStorageEnabled>()
.UseScopedHandler<ValidateReferenceTokenIdentifier>() .UseScopedHandler<ValidateReferenceTokenIdentifier>()
.SetOrder(NormalizeUserCode.Descriptor.Order + 1_000) .SetOrder(NormalizeUserCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -411,6 +415,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateIdentityModelToken>() .UseSingletonHandler<ValidateIdentityModelToken>()
.SetOrder(ValidateReferenceTokenIdentifier.Descriptor.Order + 1_000) .SetOrder(ValidateReferenceTokenIdentifier.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -521,6 +526,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<NormalizeScopeClaims>() .UseSingletonHandler<NormalizeScopeClaims>()
.SetOrder(ValidateIdentityModelToken.Descriptor.Order + 1_000) .SetOrder(ValidateIdentityModelToken.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -571,6 +577,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<MapInternalClaims>() .UseSingletonHandler<MapInternalClaims>()
.SetOrder(NormalizeScopeClaims.Descriptor.Order + 1_000) .SetOrder(NormalizeScopeClaims.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -695,6 +702,7 @@ namespace OpenIddict.Server
.AddFilter<RequireTokenStorageEnabled>() .AddFilter<RequireTokenStorageEnabled>()
.UseScopedHandler<RestoreReferenceTokenProperties>() .UseScopedHandler<RestoreReferenceTokenProperties>()
.SetOrder(MapInternalClaims.Descriptor.Order + 1_000) .SetOrder(MapInternalClaims.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -743,6 +751,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidatePrincipal>() .UseSingletonHandler<ValidatePrincipal>()
.SetOrder(RestoreReferenceTokenProperties.Descriptor.Order + 1_000) .SetOrder(RestoreReferenceTokenProperties.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -850,6 +859,7 @@ namespace OpenIddict.Server
.AddFilter<RequireTokenStorageEnabled>() .AddFilter<RequireTokenStorageEnabled>()
.UseScopedHandler<ValidateTokenEntry>() .UseScopedHandler<ValidateTokenEntry>()
.SetOrder(ValidatePrincipal.Descriptor.Order + 1_000) .SetOrder(ValidatePrincipal.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -1051,6 +1061,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAuthorizationStorageEnabled>() .AddFilter<RequireAuthorizationStorageEnabled>()
.UseScopedHandler<ValidateAuthorizationEntry>() .UseScopedHandler<ValidateAuthorizationEntry>()
.SetOrder(ValidateTokenEntry.Descriptor.Order + 1_000) .SetOrder(ValidateTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -1106,6 +1117,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateExpirationDate>() .UseSingletonHandler<ValidateExpirationDate>()
.SetOrder(ValidateTokenEntry.Descriptor.Order + 1_000) .SetOrder(ValidateTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1174,6 +1186,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>()
.UseSingletonHandler<ValidateChallengeDemand>() .UseSingletonHandler<ValidateChallengeDemand>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1215,6 +1228,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessChallengeContext>()
.UseSingletonHandler<AttachDefaultChallengeError>() .UseSingletonHandler<AttachDefaultChallengeError>()
.SetOrder(ValidateChallengeDemand.Descriptor.Order + 1_000) .SetOrder(ValidateChallengeDemand.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1283,6 +1297,7 @@ namespace OpenIddict.Server
.AddFilter<RequireTokenStorageEnabled>() .AddFilter<RequireTokenStorageEnabled>()
.UseScopedHandler<RejectDeviceCodeEntry>() .UseScopedHandler<RejectDeviceCodeEntry>()
.SetOrder(AttachDefaultChallengeError.Descriptor.Order + 1_000) .SetOrder(AttachDefaultChallengeError.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1351,6 +1366,7 @@ namespace OpenIddict.Server
.AddFilter<RequireTokenStorageEnabled>() .AddFilter<RequireTokenStorageEnabled>()
.UseScopedHandler<RejectUserCodeEntry>() .UseScopedHandler<RejectUserCodeEntry>()
.SetOrder(RejectDeviceCodeEntry.Descriptor.Order + 1_000) .SetOrder(RejectDeviceCodeEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1404,6 +1420,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.UseSingletonHandler<ValidateSignInDemand>() .UseSingletonHandler<ValidateSignInDemand>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1497,6 +1514,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.UseSingletonHandler<RestoreInternalClaims>() .UseSingletonHandler<RestoreInternalClaims>()
.SetOrder(ValidateSignInDemand.Descriptor.Order + 1_000) .SetOrder(ValidateSignInDemand.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1567,6 +1585,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.UseSingletonHandler<AttachDefaultScopes>() .UseSingletonHandler<AttachDefaultScopes>()
.SetOrder(RestoreInternalClaims.Descriptor.Order + 1_000) .SetOrder(RestoreInternalClaims.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1607,6 +1626,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.UseSingletonHandler<AttachDefaultPresenters>() .UseSingletonHandler<AttachDefaultPresenters>()
.SetOrder(AttachDefaultScopes.Descriptor.Order + 1_000) .SetOrder(AttachDefaultScopes.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1646,6 +1666,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.UseSingletonHandler<InferResources>() .UseSingletonHandler<InferResources>()
.SetOrder(AttachDefaultPresenters.Descriptor.Order + 1_000) .SetOrder(AttachDefaultPresenters.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1687,6 +1708,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.UseSingletonHandler<EvaluateReturnedTokens>() .UseSingletonHandler<EvaluateReturnedTokens>()
.SetOrder(InferResources.Descriptor.Order + 1_000) .SetOrder(InferResources.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1809,6 +1831,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAuthorizationStorageEnabled>() .AddFilter<RequireAuthorizationStorageEnabled>()
.UseScopedHandler<AttachAuthorization>() .UseScopedHandler<AttachAuthorization>()
.SetOrder(EvaluateReturnedTokens.Descriptor.Order + 1_000) .SetOrder(EvaluateReturnedTokens.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -1900,6 +1923,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAccessTokenIncluded>() .AddFilter<RequireAccessTokenIncluded>()
.UseSingletonHandler<PrepareAccessTokenPrincipal>() .UseSingletonHandler<PrepareAccessTokenPrincipal>()
.SetOrder(AttachAuthorization.Descriptor.Order + 1_000) .SetOrder(AttachAuthorization.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2023,6 +2047,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAuthorizationCodeIncluded>() .AddFilter<RequireAuthorizationCodeIncluded>()
.UseSingletonHandler<PrepareAuthorizationCodePrincipal>() .UseSingletonHandler<PrepareAuthorizationCodePrincipal>()
.SetOrder(PrepareAccessTokenPrincipal.Descriptor.Order + 1_000) .SetOrder(PrepareAccessTokenPrincipal.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2112,6 +2137,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.UseSingletonHandler<PrepareDeviceCodePrincipal>() .UseSingletonHandler<PrepareDeviceCodePrincipal>()
.SetOrder(PrepareAuthorizationCodePrincipal.Descriptor.Order + 1_000) .SetOrder(PrepareAuthorizationCodePrincipal.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2196,6 +2222,7 @@ namespace OpenIddict.Server
.AddFilter<RequireRefreshTokenIncluded>() .AddFilter<RequireRefreshTokenIncluded>()
.UseSingletonHandler<PrepareRefreshTokenPrincipal>() .UseSingletonHandler<PrepareRefreshTokenPrincipal>()
.SetOrder(PrepareDeviceCodePrincipal.Descriptor.Order + 1_000) .SetOrder(PrepareDeviceCodePrincipal.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2281,6 +2308,7 @@ namespace OpenIddict.Server
.AddFilter<RequireIdentityTokenIncluded>() .AddFilter<RequireIdentityTokenIncluded>()
.UseSingletonHandler<PrepareIdentityTokenPrincipal>() .UseSingletonHandler<PrepareIdentityTokenPrincipal>()
.SetOrder(PrepareRefreshTokenPrincipal.Descriptor.Order + 1_000) .SetOrder(PrepareRefreshTokenPrincipal.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2398,6 +2426,7 @@ namespace OpenIddict.Server
.AddFilter<RequireUserCodeIncluded>() .AddFilter<RequireUserCodeIncluded>()
.UseSingletonHandler<PrepareUserCodePrincipal>() .UseSingletonHandler<PrepareUserCodePrincipal>()
.SetOrder(PrepareIdentityTokenPrincipal.Descriptor.Order + 1_000) .SetOrder(PrepareIdentityTokenPrincipal.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2486,6 +2515,7 @@ namespace OpenIddict.Server
.AddFilter<RequireTokenStorageEnabled>() .AddFilter<RequireTokenStorageEnabled>()
.UseScopedHandler<RedeemTokenEntry>() .UseScopedHandler<RedeemTokenEntry>()
.SetOrder(100_000) .SetOrder(100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2588,6 +2618,7 @@ namespace OpenIddict.Server
.AddFilter<RequireRollingTokensEnabled>() .AddFilter<RequireRollingTokensEnabled>()
.UseScopedHandler<RevokeExistingTokenEntries>() .UseScopedHandler<RevokeExistingTokenEntries>()
.SetOrder(RedeemTokenEntry.Descriptor.Order + 1_000) .SetOrder(RedeemTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2664,6 +2695,7 @@ namespace OpenIddict.Server
.AddFilter<RequireRollingTokensDisabled>() .AddFilter<RequireRollingTokensDisabled>()
.UseScopedHandler<ExtendRefreshTokenEntry>() .UseScopedHandler<ExtendRefreshTokenEntry>()
.SetOrder(RevokeExistingTokenEntries.Descriptor.Order + 1_000) .SetOrder(RevokeExistingTokenEntries.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2748,6 +2780,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAccessTokenIncluded>() .AddFilter<RequireAccessTokenIncluded>()
.UseScopedHandler<CreateAccessTokenEntry>() .UseScopedHandler<CreateAccessTokenEntry>()
.SetOrder(ExtendRefreshTokenEntry.Descriptor.Order + 1_000) .SetOrder(ExtendRefreshTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2821,6 +2854,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAccessTokenIncluded>() .AddFilter<RequireAccessTokenIncluded>()
.UseSingletonHandler<GenerateIdentityModelAccessToken>() .UseSingletonHandler<GenerateIdentityModelAccessToken>()
.SetOrder(CreateAccessTokenEntry.Descriptor.Order + 1_000) .SetOrder(CreateAccessTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -2950,6 +2984,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAccessTokenIncluded>() .AddFilter<RequireAccessTokenIncluded>()
.UseScopedHandler<ConvertReferenceAccessToken>() .UseScopedHandler<ConvertReferenceAccessToken>()
.SetOrder(GenerateIdentityModelAccessToken.Descriptor.Order + 1_000) .SetOrder(GenerateIdentityModelAccessToken.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3050,6 +3085,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAuthorizationCodeIncluded>() .AddFilter<RequireAuthorizationCodeIncluded>()
.UseScopedHandler<CreateAuthorizationCodeEntry>() .UseScopedHandler<CreateAuthorizationCodeEntry>()
.SetOrder(ConvertReferenceAccessToken.Descriptor.Order + 1_000) .SetOrder(ConvertReferenceAccessToken.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3123,6 +3159,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAuthorizationCodeIncluded>() .AddFilter<RequireAuthorizationCodeIncluded>()
.UseSingletonHandler<GenerateIdentityModelAuthorizationCode>() .UseSingletonHandler<GenerateIdentityModelAuthorizationCode>()
.SetOrder(CreateAuthorizationCodeEntry.Descriptor.Order + 1_000) .SetOrder(CreateAuthorizationCodeEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3233,6 +3270,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAuthorizationCodeIncluded>() .AddFilter<RequireAuthorizationCodeIncluded>()
.UseScopedHandler<ConvertReferenceAuthorizationCode>() .UseScopedHandler<ConvertReferenceAuthorizationCode>()
.SetOrder(GenerateIdentityModelAuthorizationCode.Descriptor.Order + 1_000) .SetOrder(GenerateIdentityModelAuthorizationCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3333,6 +3371,7 @@ namespace OpenIddict.Server
.AddFilter<RequireDeviceCodeIncluded>() .AddFilter<RequireDeviceCodeIncluded>()
.UseScopedHandler<CreateDeviceCodeEntry>() .UseScopedHandler<CreateDeviceCodeEntry>()
.SetOrder(ConvertReferenceAuthorizationCode.Descriptor.Order + 1_000) .SetOrder(ConvertReferenceAuthorizationCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3411,6 +3450,7 @@ namespace OpenIddict.Server
.AddFilter<RequireDeviceCodeIncluded>() .AddFilter<RequireDeviceCodeIncluded>()
.UseSingletonHandler<GenerateIdentityModelDeviceCode>() .UseSingletonHandler<GenerateIdentityModelDeviceCode>()
.SetOrder(CreateDeviceCodeEntry.Descriptor.Order + 1_000) .SetOrder(CreateDeviceCodeEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3521,6 +3561,7 @@ namespace OpenIddict.Server
.AddFilter<RequireDeviceCodeIncluded>() .AddFilter<RequireDeviceCodeIncluded>()
.UseScopedHandler<ConvertReferenceDeviceCode>() .UseScopedHandler<ConvertReferenceDeviceCode>()
.SetOrder(GenerateIdentityModelDeviceCode.Descriptor.Order + 1_000) .SetOrder(GenerateIdentityModelDeviceCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3620,6 +3661,7 @@ namespace OpenIddict.Server
.AddFilter<RequireDeviceCodeIncluded>() .AddFilter<RequireDeviceCodeIncluded>()
.UseScopedHandler<UpdateReferenceDeviceCodeEntry>() .UseScopedHandler<UpdateReferenceDeviceCodeEntry>()
.SetOrder(ConvertReferenceDeviceCode.Descriptor.Order + 1_000) .SetOrder(ConvertReferenceDeviceCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3722,6 +3764,7 @@ namespace OpenIddict.Server
.AddFilter<RequireRefreshTokenIncluded>() .AddFilter<RequireRefreshTokenIncluded>()
.UseScopedHandler<CreateRefreshTokenEntry>() .UseScopedHandler<CreateRefreshTokenEntry>()
.SetOrder(UpdateReferenceDeviceCodeEntry.Descriptor.Order + 1_000) .SetOrder(UpdateReferenceDeviceCodeEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3795,6 +3838,7 @@ namespace OpenIddict.Server
.AddFilter<RequireRefreshTokenIncluded>() .AddFilter<RequireRefreshTokenIncluded>()
.UseSingletonHandler<GenerateIdentityModelRefreshToken>() .UseSingletonHandler<GenerateIdentityModelRefreshToken>()
.SetOrder(CreateRefreshTokenEntry.Descriptor.Order + 1_000) .SetOrder(CreateRefreshTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3905,6 +3949,7 @@ namespace OpenIddict.Server
.AddFilter<RequireRefreshTokenIncluded>() .AddFilter<RequireRefreshTokenIncluded>()
.UseScopedHandler<ConvertReferenceRefreshToken>() .UseScopedHandler<ConvertReferenceRefreshToken>()
.SetOrder(GenerateIdentityModelRefreshToken.Descriptor.Order + 1_000) .SetOrder(GenerateIdentityModelRefreshToken.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -3984,6 +4029,7 @@ namespace OpenIddict.Server
.AddFilter<RequireUserCodeIncluded>() .AddFilter<RequireUserCodeIncluded>()
.UseSingletonHandler<AttachDeviceCodeIdentifier>() .UseSingletonHandler<AttachDeviceCodeIdentifier>()
.SetOrder(ConvertReferenceRefreshToken.Descriptor.Order + 1_000) .SetOrder(ConvertReferenceRefreshToken.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4051,6 +4097,7 @@ namespace OpenIddict.Server
.AddFilter<RequireUserCodeIncluded>() .AddFilter<RequireUserCodeIncluded>()
.UseScopedHandler<CreateUserCodeEntry>() .UseScopedHandler<CreateUserCodeEntry>()
.SetOrder(AttachDeviceCodeIdentifier.Descriptor.Order + 1_000) .SetOrder(AttachDeviceCodeIdentifier.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4124,6 +4171,7 @@ namespace OpenIddict.Server
.AddFilter<RequireUserCodeIncluded>() .AddFilter<RequireUserCodeIncluded>()
.UseSingletonHandler<GenerateIdentityModelUserCode>() .UseSingletonHandler<GenerateIdentityModelUserCode>()
.SetOrder(CreateUserCodeEntry.Descriptor.Order + 1_000) .SetOrder(CreateUserCodeEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4224,6 +4272,7 @@ namespace OpenIddict.Server
.AddFilter<RequireUserCodeIncluded>() .AddFilter<RequireUserCodeIncluded>()
.UseScopedHandler<ConvertReferenceUserCode>() .UseScopedHandler<ConvertReferenceUserCode>()
.SetOrder(GenerateIdentityModelUserCode.Descriptor.Order + 1_000) .SetOrder(GenerateIdentityModelUserCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4315,6 +4364,7 @@ namespace OpenIddict.Server
.AddFilter<RequireIdentityTokenIncluded>() .AddFilter<RequireIdentityTokenIncluded>()
.UseSingletonHandler<AttachTokenDigests>() .UseSingletonHandler<AttachTokenDigests>()
.SetOrder(ConvertReferenceUserCode.Descriptor.Order + 1_000) .SetOrder(ConvertReferenceUserCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4468,6 +4518,7 @@ namespace OpenIddict.Server
.AddFilter<RequireIdentityTokenIncluded>() .AddFilter<RequireIdentityTokenIncluded>()
.UseScopedHandler<CreateIdentityTokenEntry>() .UseScopedHandler<CreateIdentityTokenEntry>()
.SetOrder(AttachTokenDigests.Descriptor.Order + 1_000) .SetOrder(AttachTokenDigests.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4541,6 +4592,7 @@ namespace OpenIddict.Server
.AddFilter<RequireIdentityTokenIncluded>() .AddFilter<RequireIdentityTokenIncluded>()
.UseSingletonHandler<GenerateIdentityModelIdentityToken>() .UseSingletonHandler<GenerateIdentityModelIdentityToken>()
.SetOrder(CreateIdentityTokenEntry.Descriptor.Order + 1_000) .SetOrder(CreateIdentityTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4639,6 +4691,7 @@ namespace OpenIddict.Server
.AddFilter<RequireUserCodeIncluded>() .AddFilter<RequireUserCodeIncluded>()
.UseSingletonHandler<BeautifyUserCode>() .UseSingletonHandler<BeautifyUserCode>()
.SetOrder(GenerateIdentityModelIdentityToken.Descriptor.Order + 1_000) .SetOrder(GenerateIdentityModelIdentityToken.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4692,6 +4745,7 @@ namespace OpenIddict.Server
.AddFilter<RequireAccessTokenIncluded>() .AddFilter<RequireAccessTokenIncluded>()
.UseSingletonHandler<AttachAccessTokenProperties>() .UseSingletonHandler<AttachAccessTokenProperties>()
.SetOrder(BeautifyUserCode.Descriptor.Order + 1_000) .SetOrder(BeautifyUserCode.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4743,6 +4797,7 @@ namespace OpenIddict.Server
.AddFilter<RequireDeviceCodeIncluded>() .AddFilter<RequireDeviceCodeIncluded>()
.UseSingletonHandler<AttachDeviceCodeProperties>() .UseSingletonHandler<AttachDeviceCodeProperties>()
.SetOrder(AttachAccessTokenProperties.Descriptor.Order + 1_000) .SetOrder(AttachAccessTokenProperties.Descriptor.Order + 1_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -4759,7 +4814,7 @@ namespace OpenIddict.Server
throw new ArgumentNullException(nameof(context)); throw new ArgumentNullException(nameof(context));
} }
var address = GetEndpointAbsoluteUrl(context.Issuer, context.Options.VerificationEndpointUris.FirstOrDefault()); var address = GetEndpointAbsoluteUri(context.Issuer, context.Options.VerificationEndpointUris.FirstOrDefault());
if (address != null) if (address != null)
{ {
var builder = new UriBuilder(address) var builder = new UriBuilder(address)
@ -4780,7 +4835,7 @@ namespace OpenIddict.Server
return default; return default;
static Uri GetEndpointAbsoluteUrl(Uri issuer, Uri endpoint) static Uri GetEndpointAbsoluteUri(Uri issuer, Uri endpoint)
{ {
// If the endpoint is disabled (i.e a null address is specified), return null. // If the endpoint is disabled (i.e a null address is specified), return null.
if (endpoint == null) if (endpoint == null)
@ -4832,6 +4887,7 @@ namespace OpenIddict.Server
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignOutContext>() = OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignOutContext>()
.UseSingletonHandler<ValidateSignOutDemand>() .UseSingletonHandler<ValidateSignOutDemand>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictServerHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

49
src/OpenIddict.Server/OpenIddictServerOptions.cs

@ -31,7 +31,7 @@ namespace OpenIddict.Server
/// OpenIddict server services. Note: the encryption credentials are not /// OpenIddict server services. Note: the encryption credentials are not
/// used to protect/unprotect tokens issued by ASP.NET Core Data Protection. /// used to protect/unprotect tokens issued by ASP.NET Core Data Protection.
/// </summary> /// </summary>
public IList<EncryptingCredentials> EncryptionCredentials { get; } = new List<EncryptingCredentials>(); public List<EncryptingCredentials> EncryptionCredentials { get; } = new List<EncryptingCredentials>();
/// <summary> /// <summary>
/// Gets the list of credentials used to sign the tokens issued by the OpenIddict server services. /// Gets the list of credentials used to sign the tokens issued by the OpenIddict server services.
@ -39,17 +39,17 @@ namespace OpenIddict.Server
/// Note that only asymmetric RSA and ECDSA keys can be exposed by the JWKS metadata endpoint and that the /// Note that only asymmetric RSA and ECDSA keys can be exposed by the JWKS metadata endpoint and that the
/// signing credentials are not used to protect/unprotect tokens issued by ASP.NET Core Data Protection. /// signing credentials are not used to protect/unprotect tokens issued by ASP.NET Core Data Protection.
/// </summary> /// </summary>
public IList<SigningCredentials> SigningCredentials { get; } = new List<SigningCredentials>(); public List<SigningCredentials> SigningCredentials { get; } = new List<SigningCredentials>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the authorization endpoint. /// Gets the absolute and relative URIs associated to the authorization endpoint.
/// </summary> /// </summary>
public IList<Uri> AuthorizationEndpointUris { get; } = new List<Uri>(); public List<Uri> AuthorizationEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the configuration endpoint. /// Gets the absolute and relative URIs associated to the configuration endpoint.
/// </summary> /// </summary>
public IList<Uri> ConfigurationEndpointUris { get; } = new List<Uri> public List<Uri> ConfigurationEndpointUris { get; } = new List<Uri>
{ {
new Uri("/.well-known/openid-configuration", UriKind.Relative), new Uri("/.well-known/openid-configuration", UriKind.Relative),
new Uri("/.well-known/oauth-authorization-server", UriKind.Relative) new Uri("/.well-known/oauth-authorization-server", UriKind.Relative)
@ -58,7 +58,7 @@ namespace OpenIddict.Server
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the cryptography endpoint. /// Gets the absolute and relative URIs associated to the cryptography endpoint.
/// </summary> /// </summary>
public IList<Uri> CryptographyEndpointUris { get; } = new List<Uri> public List<Uri> CryptographyEndpointUris { get; } = new List<Uri>
{ {
new Uri("/.well-known/jwks", UriKind.Relative) new Uri("/.well-known/jwks", UriKind.Relative)
}; };
@ -66,37 +66,37 @@ namespace OpenIddict.Server
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the device endpoint. /// Gets the absolute and relative URIs associated to the device endpoint.
/// </summary> /// </summary>
public IList<Uri> DeviceEndpointUris { get; } = new List<Uri>(); public List<Uri> DeviceEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the introspection endpoint. /// Gets the absolute and relative URIs associated to the introspection endpoint.
/// </summary> /// </summary>
public IList<Uri> IntrospectionEndpointUris { get; } = new List<Uri>(); public List<Uri> IntrospectionEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the logout endpoint. /// Gets the absolute and relative URIs associated to the logout endpoint.
/// </summary> /// </summary>
public IList<Uri> LogoutEndpointUris { get; } = new List<Uri>(); public List<Uri> LogoutEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the revocation endpoint. /// Gets the absolute and relative URIs associated to the revocation endpoint.
/// </summary> /// </summary>
public IList<Uri> RevocationEndpointUris { get; } = new List<Uri>(); public List<Uri> RevocationEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the token endpoint. /// Gets the absolute and relative URIs associated to the token endpoint.
/// </summary> /// </summary>
public IList<Uri> TokenEndpointUris { get; } = new List<Uri>(); public List<Uri> TokenEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the userinfo endpoint. /// Gets the absolute and relative URIs associated to the userinfo endpoint.
/// </summary> /// </summary>
public IList<Uri> UserinfoEndpointUris { get; } = new List<Uri>(); public List<Uri> UserinfoEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets the absolute and relative URIs associated to the verification endpoint. /// Gets the absolute and relative URIs associated to the verification endpoint.
/// </summary> /// </summary>
public IList<Uri> VerificationEndpointUris { get; } = new List<Uri>(); public List<Uri> VerificationEndpointUris { get; } = new List<Uri>();
/// <summary> /// <summary>
/// Gets or sets the JWT handler used to protect and unprotect tokens. /// Gets or sets the JWT handler used to protect and unprotect tokens.
@ -215,16 +215,11 @@ namespace OpenIddict.Server
public bool EnableDegradedMode { get; set; } public bool EnableDegradedMode { get; set; }
/// <summary> /// <summary>
/// Gets the list of the user-defined/custom handlers responsible of processing the OpenIddict server requests. /// Gets the list of the handlers responsible of processing the OpenIddict server operations.
/// Note: the handlers added to this list must be also registered in the DI container using an appropriate lifetime. /// Note: the list is automatically sorted based on the order assigned to each handler descriptor.
/// As such, it MUST NOT be mutated after options initialization to preserve the exact order.
/// </summary> /// </summary>
public IList<OpenIddictServerHandlerDescriptor> CustomHandlers { get; } = public List<OpenIddictServerHandlerDescriptor> Handlers { get; } =
new List<OpenIddictServerHandlerDescriptor>();
/// <summary>
/// Gets the list of the built-in handlers responsible of processing the OpenIddict server requests
/// </summary>
public IList<OpenIddictServerHandlerDescriptor> DefaultHandlers { get; } =
new List<OpenIddictServerHandlerDescriptor>(OpenIddictServerHandlers.DefaultHandlers); new List<OpenIddictServerHandlerDescriptor>(OpenIddictServerHandlers.DefaultHandlers);
/// <summary> /// <summary>
@ -244,7 +239,7 @@ namespace OpenIddict.Server
/// <summary> /// <summary>
/// Gets the OAuth 2.0/OpenID Connect claims supported by this application. /// Gets the OAuth 2.0/OpenID Connect claims supported by this application.
/// </summary> /// </summary>
public ISet<string> Claims { get; } = new HashSet<string>(StringComparer.Ordinal) public HashSet<string> Claims { get; } = new HashSet<string>(StringComparer.Ordinal)
{ {
OpenIddictConstants.Claims.Audience, OpenIddictConstants.Claims.Audience,
OpenIddictConstants.Claims.ExpiresAt, OpenIddictConstants.Claims.ExpiresAt,
@ -286,12 +281,12 @@ namespace OpenIddict.Server
/// Gets the OAuth 2.0 code challenge methods enabled for this application. /// Gets the OAuth 2.0 code challenge methods enabled for this application.
/// By default, only the S256 method is allowed (if the code flow is enabled). /// By default, only the S256 method is allowed (if the code flow is enabled).
/// </summary> /// </summary>
public ISet<string> CodeChallengeMethods { get; } = new HashSet<string>(StringComparer.Ordinal); public HashSet<string> CodeChallengeMethods { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the OAuth 2.0/OpenID Connect flows enabled for this application. /// Gets the OAuth 2.0/OpenID Connect flows enabled for this application.
/// </summary> /// </summary>
public ISet<string> GrantTypes { get; } = new HashSet<string>(StringComparer.Ordinal); public HashSet<string> GrantTypes { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the OAuth 2.0/OpenID Connect response types enabled for this application. /// Gets the OAuth 2.0/OpenID Connect response types enabled for this application.
@ -299,7 +294,7 @@ namespace OpenIddict.Server
/// but additional values can be added for advanced scenarios (e.g custom type support). /// but additional values can be added for advanced scenarios (e.g custom type support).
/// </summary> /// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public ISet<string> ResponseTypes { get; } = new HashSet<string>(StringComparer.Ordinal); public HashSet<string> ResponseTypes { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the OAuth 2.0/OpenID Connect response modes enabled for this application. /// Gets the OAuth 2.0/OpenID Connect response modes enabled for this application.
@ -307,7 +302,7 @@ namespace OpenIddict.Server
/// but additional values can be added for advanced scenarios (e.g custom mode support). /// but additional values can be added for advanced scenarios (e.g custom mode support).
/// </summary> /// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)] [EditorBrowsable(EditorBrowsableState.Advanced)]
public ISet<string> ResponseModes { get; } = new HashSet<string>(StringComparer.Ordinal); public HashSet<string> ResponseModes { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets or sets a boolean indicating whether endpoint permissions should be ignored. /// Gets or sets a boolean indicating whether endpoint permissions should be ignored.
@ -333,7 +328,7 @@ namespace OpenIddict.Server
/// <summary> /// <summary>
/// Gets the OAuth 2.0/OpenID Connect scopes enabled for this application. /// Gets the OAuth 2.0/OpenID Connect scopes enabled for this application.
/// </summary> /// </summary>
public ISet<string> Scopes { get; } = new HashSet<string>(StringComparer.Ordinal) public HashSet<string> Scopes { get; } = new HashSet<string>(StringComparer.Ordinal)
{ {
OpenIddictConstants.Scopes.OpenId OpenIddictConstants.Scopes.OpenId
}; };

5
src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreConfiguration.cs

@ -52,10 +52,7 @@ namespace OpenIddict.Validation.AspNetCore
} }
// Register the built-in event handlers used by the OpenIddict ASP.NET Core validation components. // Register the built-in event handlers used by the OpenIddict ASP.NET Core validation components.
foreach (var handler in OpenIddictValidationAspNetCoreHandlers.DefaultHandlers) options.Handlers.AddRange(OpenIddictValidationAspNetCoreHandlers.DefaultHandlers);
{
options.DefaultHandlers.Add(handler);
}
} }
/// <summary> /// <summary>

23
src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandler.cs

@ -26,19 +26,24 @@ namespace OpenIddict.Validation.AspNetCore
public class OpenIddictValidationAspNetCoreHandler : AuthenticationHandler<OpenIddictValidationAspNetCoreOptions>, public class OpenIddictValidationAspNetCoreHandler : AuthenticationHandler<OpenIddictValidationAspNetCoreOptions>,
IAuthenticationRequestHandler IAuthenticationRequestHandler
{ {
private readonly IOpenIddictValidationProvider _provider; private readonly IOpenIddictValidationDispatcher _dispatcher;
private readonly IOpenIddictValidationFactory _factory;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictValidationAspNetCoreHandler"/> class. /// Creates a new instance of the <see cref="OpenIddictValidationAspNetCoreHandler"/> class.
/// </summary> /// </summary>
public OpenIddictValidationAspNetCoreHandler( public OpenIddictValidationAspNetCoreHandler(
[NotNull] IOpenIddictValidationProvider provider, [NotNull] IOpenIddictValidationDispatcher dispatcher,
[NotNull] IOpenIddictValidationFactory factory,
[NotNull] IOptionsMonitor<OpenIddictValidationAspNetCoreOptions> options, [NotNull] IOptionsMonitor<OpenIddictValidationAspNetCoreOptions> options,
[NotNull] ILoggerFactory logger, [NotNull] ILoggerFactory logger,
[NotNull] UrlEncoder encoder, [NotNull] UrlEncoder encoder,
[NotNull] ISystemClock clock) [NotNull] ISystemClock clock)
: base(options, logger, encoder, clock) : base(options, logger, encoder, clock)
=> _provider = provider; {
_dispatcher = dispatcher;
_factory = factory;
}
public async Task<bool> HandleRequestAsync() public async Task<bool> HandleRequestAsync()
{ {
@ -48,7 +53,7 @@ namespace OpenIddict.Validation.AspNetCore
if (transaction == null) if (transaction == null)
{ {
// Create a new transaction and attach the HTTP request to make it available to the ASP.NET Core handlers. // 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<HttpRequest>(Request); transaction.Properties[typeof(HttpRequest).FullName] = new WeakReference<HttpRequest>(Request);
// Attach the OpenIddict validation transaction to the ASP.NET Core features // Attach the OpenIddict validation transaction to the ASP.NET Core features
@ -57,7 +62,7 @@ namespace OpenIddict.Validation.AspNetCore
} }
var context = new ProcessRequestContext(transaction); var context = new ProcessRequestContext(transaction);
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled) if (context.IsRequestHandled)
{ {
@ -81,7 +86,7 @@ namespace OpenIddict.Validation.AspNetCore
} }
}; };
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -115,7 +120,7 @@ namespace OpenIddict.Validation.AspNetCore
if (context == null) if (context == null)
{ {
context = new ProcessAuthenticationContext(transaction); 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 // 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. // that want to access the authentication result without triggering a new authentication flow.
@ -179,7 +184,7 @@ namespace OpenIddict.Validation.AspNetCore
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) if (context.IsRequestHandled || context.IsRequestSkipped)
{ {
@ -198,7 +203,7 @@ namespace OpenIddict.Validation.AspNetCore
} }
}; };
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {

9
src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreHandlers.cs

@ -74,6 +74,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<InferIssuerFromHost>() .UseSingletonHandler<InferIssuerFromHost>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -144,6 +145,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ExtractGetOrPostRequest>() .UseSingletonHandler<ExtractGetOrPostRequest>()
.SetOrder(InferIssuerFromHost.Descriptor.Order + 1_000) .SetOrder(InferIssuerFromHost.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -200,6 +202,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ExtractAccessToken>() .UseSingletonHandler<ExtractAccessToken>()
.SetOrder(ExtractGetOrPostRequest.Descriptor.Order + 1_000) .SetOrder(ExtractGetOrPostRequest.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -251,6 +254,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachHostChallengeError>() .UseSingletonHandler<AttachHostChallengeError>()
.SetOrder(int.MinValue + 50_000) .SetOrder(int.MinValue + 50_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -294,6 +298,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachHttpResponseCode<TContext>>() .UseSingletonHandler<AttachHttpResponseCode<TContext>>()
.SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -349,6 +354,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachCacheControlHeader<TContext>>() .UseSingletonHandler<AttachCacheControlHeader<TContext>>()
.SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -401,6 +407,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>() .UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>()
.SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -509,6 +516,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>() .UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>()
.SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -560,6 +568,7 @@ namespace OpenIddict.Validation.AspNetCore
.AddFilter<RequireHttpRequest>() .AddFilter<RequireHttpRequest>()
.UseSingletonHandler<ProcessJsonResponse<TContext>>() .UseSingletonHandler<ProcessJsonResponse<TContext>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

5
src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionConfiguration.cs

@ -35,10 +35,7 @@ namespace OpenIddict.Validation.DataProtection
} }
// Register the built-in event handlers used by the OpenIddict Data Protection validation components. // Register the built-in event handlers used by the OpenIddict Data Protection validation components.
foreach (var handler in OpenIddictValidationDataProtectionHandlers.DefaultHandlers) options.Handlers.AddRange(OpenIddictValidationDataProtectionHandlers.DefaultHandlers);
{
options.DefaultHandlers.Add(handler);
}
} }
/// <summary> /// <summary>

1
src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.cs

@ -50,6 +50,7 @@ namespace OpenIddict.Validation.DataProtection
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateDataProtectionToken>() .UseSingletonHandler<ValidateDataProtectionToken>()
.SetOrder(ValidateIdentityModelToken.Descriptor.Order + 500) .SetOrder(ValidateIdentityModelToken.Descriptor.Order + 500)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

5
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinConfiguration.cs

@ -23,10 +23,7 @@ namespace OpenIddict.Validation.Owin
} }
// Register the built-in event handlers used by the OpenIddict OWIN validation components. // Register the built-in event handlers used by the OpenIddict OWIN validation components.
foreach (var handler in OpenIddictValidationOwinHandlers.DefaultHandlers) options.Handlers.AddRange(OpenIddictValidationOwinHandlers.DefaultHandlers);
{
options.DefaultHandlers.Add(handler);
}
} }
} }
} }

27
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs

@ -24,14 +24,21 @@ namespace OpenIddict.Validation.Owin
/// </summary> /// </summary>
public class OpenIddictValidationOwinHandler : AuthenticationHandler<OpenIddictValidationOwinOptions> public class OpenIddictValidationOwinHandler : AuthenticationHandler<OpenIddictValidationOwinOptions>
{ {
private readonly IOpenIddictValidationProvider _provider; private readonly IOpenIddictValidationDispatcher _dispatcher;
private readonly IOpenIddictValidationFactory _factory;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictValidationOwinHandler"/> class. /// Creates a new instance of the <see cref="OpenIddictValidationOwinHandler"/> class.
/// </summary> /// </summary>
/// <param name="provider">The OpenIddict validation OWIN provider used by this instance.</param> /// <param name="dispatcher">The OpenIddict validation provider used by this instance.</param>
public OpenIddictValidationOwinHandler([NotNull] IOpenIddictValidationProvider provider) /// <param name="factory">The OpenIddict validation factory used by this instance.</param>
=> _provider = provider; public OpenIddictValidationOwinHandler(
[NotNull] IOpenIddictValidationDispatcher dispatcher,
[NotNull] IOpenIddictValidationFactory factory)
{
_dispatcher = dispatcher;
_factory = factory;
}
protected override async Task InitializeCoreAsync() protected override async Task InitializeCoreAsync()
{ {
@ -41,7 +48,7 @@ namespace OpenIddict.Validation.Owin
if (transaction == null) if (transaction == null)
{ {
// Create a new transaction and attach the OWIN request to make it available to the OWIN handlers. // 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<IOwinRequest>(Request); transaction.Properties[typeof(IOwinRequest).FullName] = new WeakReference<IOwinRequest>(Request);
// Attach the OpenIddict validation transaction to the OWIN shared dictionary // Attach the OpenIddict validation transaction to the OWIN shared dictionary
@ -50,7 +57,7 @@ namespace OpenIddict.Validation.Owin
} }
var context = new ProcessRequestContext(transaction); 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(). // Store the context in the transaction so that it can be retrieved from InvokeAsync().
transaction.SetProperty(typeof(ProcessRequestContext).FullName, context); transaction.SetProperty(typeof(ProcessRequestContext).FullName, context);
@ -90,7 +97,7 @@ namespace OpenIddict.Validation.Owin
} }
}; };
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled) if (notification.IsRequestHandled)
{ {
@ -124,7 +131,7 @@ namespace OpenIddict.Validation.Owin
if (context == null) if (context == null)
{ {
context = new ProcessAuthenticationContext(transaction); 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 // 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. // that want to access the authentication result without triggering a new authentication flow.
@ -199,7 +206,7 @@ namespace OpenIddict.Validation.Owin
Response = new OpenIddictResponse() Response = new OpenIddictResponse()
}; };
await _provider.DispatchAsync(context); await _dispatcher.DispatchAsync(context);
if (context.IsRequestHandled || context.IsRequestSkipped) if (context.IsRequestHandled || context.IsRequestSkipped)
{ {
@ -218,7 +225,7 @@ namespace OpenIddict.Validation.Owin
} }
}; };
await _provider.DispatchAsync(notification); await _dispatcher.DispatchAsync(notification);
if (notification.IsRequestHandled || context.IsRequestSkipped) if (notification.IsRequestHandled || context.IsRequestSkipped)
{ {

9
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandlers.cs

@ -71,6 +71,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<InferIssuerFromHost>() .UseSingletonHandler<InferIssuerFromHost>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -141,6 +142,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ExtractGetOrPostRequest>() .UseSingletonHandler<ExtractGetOrPostRequest>()
.SetOrder(InferIssuerFromHost.Descriptor.Order + 1_000) .SetOrder(InferIssuerFromHost.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -198,6 +200,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ExtractAccessToken>() .UseSingletonHandler<ExtractAccessToken>()
.SetOrder(ExtractGetOrPostRequest.Descriptor.Order + 1_000) .SetOrder(ExtractGetOrPostRequest.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -249,6 +252,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachHostChallengeError>() .UseSingletonHandler<AttachHostChallengeError>()
.SetOrder(int.MinValue + 50_000) .SetOrder(int.MinValue + 50_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -295,6 +299,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachHttpResponseCode<TContext>>() .UseSingletonHandler<AttachHttpResponseCode<TContext>>()
.SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachCacheControlHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -350,6 +355,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachCacheControlHeader<TContext>>() .UseSingletonHandler<AttachCacheControlHeader<TContext>>()
.SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000) .SetOrder(AttachWwwAuthenticateHeader<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -402,6 +408,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>() .UseSingletonHandler<AttachWwwAuthenticateHeader<TContext>>()
.SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessChallengeErrorResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -515,6 +522,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>() .UseSingletonHandler<ProcessChallengeErrorResponse<TContext>>()
.SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000) .SetOrder(ProcessJsonResponse<TContext>.Descriptor.Order - 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -566,6 +574,7 @@ namespace OpenIddict.Validation.Owin
.AddFilter<RequireOwinRequest>() .AddFilter<RequireOwinRequest>()
.UseSingletonHandler<ProcessJsonResponse<TContext>>() .UseSingletonHandler<ProcessJsonResponse<TContext>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

16
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddleware.cs

@ -19,26 +19,32 @@ namespace OpenIddict.Validation.Owin
/// </summary> /// </summary>
public class OpenIddictValidationOwinMiddleware : AuthenticationMiddleware<OpenIddictValidationOwinOptions> public class OpenIddictValidationOwinMiddleware : AuthenticationMiddleware<OpenIddictValidationOwinOptions>
{ {
private readonly IOpenIddictValidationProvider _provider; private readonly IOpenIddictValidationDispatcher _dispatcher;
private readonly IOpenIddictValidationFactory _factory;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictValidationOwinMiddleware"/> class. /// Creates a new instance of the <see cref="OpenIddictValidationOwinMiddleware"/> class.
/// </summary> /// </summary>
/// <param name="next">The next middleware in the pipeline, if applicable.</param> /// <param name="next">The next middleware in the pipeline, if applicable.</param>
/// <param name="options">The OpenIddict validation OWIN options.</param> /// <param name="options">The OpenIddict validation OWIN options.</param>
/// <param name="provider">The OpenIddict validation provider.</param> /// <param name="dispatcher">The OpenIddict validation dispatcher.</param>
/// <param name="factory">The OpenIddict validation factory.</param>
public OpenIddictValidationOwinMiddleware( public OpenIddictValidationOwinMiddleware(
[CanBeNull] OwinMiddleware next, [CanBeNull] OwinMiddleware next,
[NotNull] IOptionsMonitor<OpenIddictValidationOwinOptions> options, [NotNull] IOptionsMonitor<OpenIddictValidationOwinOptions> options,
[NotNull] IOpenIddictValidationProvider provider) [NotNull] IOpenIddictValidationDispatcher dispatcher,
[NotNull] IOpenIddictValidationFactory factory)
: base(next, options.CurrentValue) : base(next, options.CurrentValue)
=> _provider = provider; {
_dispatcher = dispatcher;
_factory = factory;
}
/// <summary> /// <summary>
/// Creates and returns a new <see cref="OpenIddictValidationOwinHandler"/> instance. /// Creates and returns a new <see cref="OpenIddictValidationOwinHandler"/> instance.
/// </summary> /// </summary>
/// <returns>A new instance of the <see cref="OpenIddictValidationOwinHandler"/> class.</returns> /// <returns>A new instance of the <see cref="OpenIddictValidationOwinHandler"/> class.</returns>
protected override AuthenticationHandler<OpenIddictValidationOwinOptions> CreateHandler() protected override AuthenticationHandler<OpenIddictValidationOwinOptions> CreateHandler()
=> new OpenIddictValidationOwinHandler(_provider); => new OpenIddictValidationOwinHandler(_dispatcher, _factory);
} }
} }

5
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinMiddlewareFactory.cs

@ -64,13 +64,14 @@ namespace OpenIddict.Validation.Owin
var middleware = new OpenIddictValidationOwinMiddleware( var middleware = new OpenIddictValidationOwinMiddleware(
next: Next, next: Next,
options: GetRequiredService<IOptionsMonitor<OpenIddictValidationOwinOptions>>(provider), options: GetRequiredService<IOptionsMonitor<OpenIddictValidationOwinOptions>>(provider),
provider: GetRequiredService<IOpenIddictValidationProvider>(provider)); dispatcher: GetRequiredService<IOpenIddictValidationDispatcher>(provider),
factory: GetRequiredService<IOpenIddictValidationFactory>(provider));
return middleware.Invoke(context); return middleware.Invoke(context);
static T GetRequiredService<T>(IServiceProvider provider) static T GetRequiredService<T>(IServiceProvider provider)
=> provider.GetService<T>() ?? throw new InvalidOperationException(new StringBuilder() => provider.GetService<T>() ?? throw new InvalidOperationException(new StringBuilder()
.AppendLine("The OpenIddict validation authentication services cannot be resolved from the DI container.") .AppendLine("The OpenIddict validation services cannot be resolved from the DI container.")
.Append("To register the OWIN services, use 'services.AddOpenIddict().AddValidation().UseOwin()'.") .Append("To register the OWIN services, use 'services.AddOpenIddict().AddValidation().UseOwin()'.")
.ToString()); .ToString());
} }

5
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs

@ -35,10 +35,7 @@ namespace OpenIddict.Validation.SystemNetHttp
} }
// Register the built-in event handlers used by the OpenIddict System.Net.Http validation components. // Register the built-in event handlers used by the OpenIddict System.Net.Http validation components.
foreach (var handler in OpenIddictValidationSystemNetHttpHandlers.DefaultHandlers) options.Handlers.AddRange(OpenIddictValidationSystemNetHttpHandlers.DefaultHandlers);
{
options.DefaultHandlers.Add(handler);
}
} }
public void Configure([NotNull] HttpClientFactoryOptions options) public void Configure([NotNull] HttpClientFactoryOptions options)

6
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs

@ -41,6 +41,7 @@ namespace OpenIddict.Validation.SystemNetHttp
.AddFilter<RequireHttpMetadataAddress>() .AddFilter<RequireHttpMetadataAddress>()
.UseSingletonHandler<PrepareGetHttpRequest<TContext>>() .UseSingletonHandler<PrepareGetHttpRequest<TContext>>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public ValueTask HandleAsync([NotNull] TContext context) public ValueTask HandleAsync([NotNull] TContext context)
@ -74,6 +75,7 @@ namespace OpenIddict.Validation.SystemNetHttp
.AddFilter<RequireHttpMetadataAddress>() .AddFilter<RequireHttpMetadataAddress>()
.UseSingletonHandler<PreparePostHttpRequest<TContext>>() .UseSingletonHandler<PreparePostHttpRequest<TContext>>()
.SetOrder(PrepareGetHttpRequest<TContext>.Descriptor.Order + 1_000) .SetOrder(PrepareGetHttpRequest<TContext>.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public ValueTask HandleAsync([NotNull] TContext context) public ValueTask HandleAsync([NotNull] TContext context)
@ -107,6 +109,7 @@ namespace OpenIddict.Validation.SystemNetHttp
.AddFilter<RequireHttpMetadataAddress>() .AddFilter<RequireHttpMetadataAddress>()
.UseSingletonHandler<AttachQueryStringParameters<TContext>>() .UseSingletonHandler<AttachQueryStringParameters<TContext>>()
.SetOrder(AttachFormParameters<TContext>.Descriptor.Order - 100_000) .SetOrder(AttachFormParameters<TContext>.Descriptor.Order - 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] TContext context) public async ValueTask HandleAsync([NotNull] TContext context)
@ -156,6 +159,7 @@ namespace OpenIddict.Validation.SystemNetHttp
.AddFilter<RequireHttpMetadataAddress>() .AddFilter<RequireHttpMetadataAddress>()
.UseSingletonHandler<AttachFormParameters<TContext>>() .UseSingletonHandler<AttachFormParameters<TContext>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public ValueTask HandleAsync([NotNull] TContext context) public ValueTask HandleAsync([NotNull] TContext context)
@ -202,6 +206,7 @@ namespace OpenIddict.Validation.SystemNetHttp
.AddFilter<RequireHttpMetadataAddress>() .AddFilter<RequireHttpMetadataAddress>()
.UseSingletonHandler<SendHttpRequest<TContext>>() .UseSingletonHandler<SendHttpRequest<TContext>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] TContext context) public async ValueTask HandleAsync([NotNull] TContext context)
@ -250,6 +255,7 @@ namespace OpenIddict.Validation.SystemNetHttp
.AddFilter<RequireHttpMetadataAddress>() .AddFilter<RequireHttpMetadataAddress>()
.UseSingletonHandler<ExtractJsonHttpResponse<TContext>>() .UseSingletonHandler<ExtractJsonHttpResponse<TContext>>()
.SetOrder(int.MaxValue - 100_000) .SetOrder(int.MaxValue - 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] TContext context) public async ValueTask HandleAsync([NotNull] TContext context)

3
src/OpenIddict.Validation/IOpenIddictValidationProvider.cs → src/OpenIddict.Validation/IOpenIddictValidationDispatcher.cs

@ -10,9 +10,8 @@ using static OpenIddict.Validation.OpenIddictValidationEvents;
namespace OpenIddict.Validation namespace OpenIddict.Validation
{ {
public interface IOpenIddictValidationProvider public interface IOpenIddictValidationDispatcher
{ {
ValueTask<OpenIddictValidationTransaction> CreateTransactionAsync();
ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext; ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext;
} }
} }

15
src/OpenIddict.Validation/IOpenIddictValidationFactory.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.Validation
{
public interface IOpenIddictValidationFactory
{
ValueTask<OpenIddictValidationTransaction> CreateTransactionAsync();
}
}

21
src/OpenIddict.Validation/OpenIddictValidationBuilder.cs

@ -55,7 +55,10 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(configuration)); throw new ArgumentNullException(nameof(configuration));
} }
var builder = OpenIddictValidationHandlerDescriptor.CreateBuilder<TContext>(); // Note: handlers registered using this API are assumed to be custom handlers by default.
var builder = OpenIddictValidationHandlerDescriptor.CreateBuilder<TContext>()
.SetType(OpenIddictValidationHandlerType.Custom);
configuration(builder); configuration(builder);
return AddEventHandler(builder.Build()); return AddEventHandler(builder.Build());
@ -77,7 +80,7 @@ namespace Microsoft.Extensions.DependencyInjection
// Register the handler in the services collection. // Register the handler in the services collection.
Services.Add(descriptor.ServiceDescriptor); Services.Add(descriptor.ServiceDescriptor);
return Configure(options => options.CustomHandlers.Add(descriptor)); return Configure(options => options.Handlers.Add(descriptor));
} }
/// <summary> /// <summary>
@ -97,19 +100,11 @@ namespace Microsoft.Extensions.DependencyInjection
Services.PostConfigure<OpenIddictValidationOptions>(options => Services.PostConfigure<OpenIddictValidationOptions>(options =>
{ {
for (var index = options.CustomHandlers.Count - 1; index >= 0; index--) for (var index = options.Handlers.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--)
{ {
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);
} }
} }
}); });

9
src/OpenIddict.Validation/OpenIddictValidationConfiguration.cs

@ -60,7 +60,7 @@ namespace OpenIddict.Validation
if (options.ValidationType == OpenIddictValidationType.Introspection) if (options.ValidationType == OpenIddictValidationType.Introspection)
{ {
if (!options.DefaultHandlers.Any(descriptor => descriptor.ContextType == typeof(ApplyIntrospectionRequestContext))) if (!options.Handlers.Any(descriptor => descriptor.ContextType == typeof(ApplyIntrospectionRequestContext)))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("An introspection client must be registered when using introspection.") .AppendLine("An introspection client must be registered when using introspection.")
@ -98,8 +98,8 @@ namespace OpenIddict.Validation
if (options.Configuration == null && options.ConfigurationManager == null) if (options.Configuration == null && options.ConfigurationManager == null)
{ {
if (!options.DefaultHandlers.Any(descriptor => descriptor.ContextType == typeof(ApplyConfigurationRequestContext)) || if (!options.Handlers.Any(descriptor => descriptor.ContextType == typeof(ApplyConfigurationRequestContext)) ||
!options.DefaultHandlers.Any(descriptor => descriptor.ContextType == typeof(ApplyCryptographyRequestContext))) !options.Handlers.Any(descriptor => descriptor.ContextType == typeof(ApplyCryptographyRequestContext)))
{ {
throw new InvalidOperationException(new StringBuilder() throw new InvalidOperationException(new StringBuilder()
.AppendLine("A discovery client must be registered when using server discovery.") .AppendLine("A discovery client must be registered when using server discovery.")
@ -159,6 +159,9 @@ namespace OpenIddict.Validation
} }
} }
// Sort the handlers collection using the order associated with each handler.
options.Handlers.Sort((left, right) => left.Order.CompareTo(right.Order));
// Attach the encryption credentials to the token validation parameters. // Attach the encryption credentials to the token validation parameters.
options.TokenValidationParameters.TokenDecryptionKeys = options.TokenValidationParameters.TokenDecryptionKeys =
from credentials in options.EncryptionCredentials from credentials in options.EncryptionCredentials

32
src/OpenIddict.Validation/OpenIddictValidationProvider.cs → src/OpenIddict.Validation/OpenIddictValidationDispatcher.cs

@ -15,17 +15,17 @@ using static OpenIddict.Validation.OpenIddictValidationEvents;
namespace OpenIddict.Validation namespace OpenIddict.Validation
{ {
public class OpenIddictValidationProvider : IOpenIddictValidationProvider public class OpenIddictValidationDispatcher : IOpenIddictValidationDispatcher
{ {
private readonly ILogger<OpenIddictValidationProvider> _logger; private readonly ILogger<OpenIddictValidationDispatcher> _logger;
private readonly IOptionsMonitor<OpenIddictValidationOptions> _options; private readonly IOptionsMonitor<OpenIddictValidationOptions> _options;
private readonly IServiceProvider _provider; private readonly IServiceProvider _provider;
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="OpenIddictValidationProvider"/> class. /// Creates a new instance of the <see cref="OpenIddictValidationDispatcher"/> class.
/// </summary> /// </summary>
public OpenIddictValidationProvider( public OpenIddictValidationDispatcher(
[NotNull] ILogger<OpenIddictValidationProvider> logger, [NotNull] ILogger<OpenIddictValidationDispatcher> logger,
[NotNull] IOptionsMonitor<OpenIddictValidationOptions> options, [NotNull] IOptionsMonitor<OpenIddictValidationOptions> options,
[NotNull] IServiceProvider provider) [NotNull] IServiceProvider provider)
{ {
@ -34,14 +34,6 @@ namespace OpenIddict.Validation
_provider = provider; _provider = provider;
} }
public ValueTask<OpenIddictValidationTransaction> CreateTransactionAsync()
=> new ValueTask<OpenIddictValidationTransaction>(new OpenIddictValidationTransaction
{
Issuer = _options.CurrentValue.Issuer,
Logger = _logger,
Options = _options.CurrentValue
});
public async ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext public async ValueTask DispatchAsync<TContext>([NotNull] TContext context) where TContext : BaseContext
{ {
if (context == null) if (context == null)
@ -82,14 +74,12 @@ namespace OpenIddict.Validation
async IAsyncEnumerable<IOpenIddictValidationHandler<TContext>> GetHandlersAsync() async IAsyncEnumerable<IOpenIddictValidationHandler<TContext>> GetHandlersAsync()
{ {
var descriptors = new List<OpenIddictValidationHandlerDescriptor>( // Note: the descriptors collection is sorted during options initialization for performance reasons.
capacity: _options.CurrentValue.CustomHandlers.Count + var descriptors = _options.CurrentValue.Handlers;
_options.CurrentValue.DefaultHandlers.Count); if (descriptors.Count == 0)
{
descriptors.AddRange(_options.CurrentValue.CustomHandlers); yield break;
descriptors.AddRange(_options.CurrentValue.DefaultHandlers); }
descriptors.Sort((left, right) => left.Order.CompareTo(right.Order));
for (var index = 0; index < descriptors.Count; index++) for (var index = 0; index < descriptors.Count; index++)
{ {

3
src/OpenIddict.Validation/OpenIddictValidationExtensions.cs

@ -37,7 +37,8 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.AddOptions(); builder.Services.AddOptions();
builder.Services.TryAddSingleton<OpenIddictValidationService>(); builder.Services.TryAddSingleton<OpenIddictValidationService>();
builder.Services.TryAddScoped<IOpenIddictValidationProvider, OpenIddictValidationProvider>(); builder.Services.TryAddScoped<IOpenIddictValidationDispatcher, OpenIddictValidationDispatcher>();
builder.Services.TryAddScoped<IOpenIddictValidationFactory, OpenIddictValidationFactory>();
// Register the built-in validation event handlers used by the OpenIddict validation components. // Register the built-in validation event handlers used by the OpenIddict validation components.
// Note: the order used here is not important, as the actual order is set in the options. // Note: the order used here is not important, as the actual order is set in the options.

38
src/OpenIddict.Validation/OpenIddictValidationFactory.cs

@ -0,0 +1,38 @@
/*
* 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;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace OpenIddict.Validation
{
public class OpenIddictValidationFactory : IOpenIddictValidationFactory
{
private readonly ILogger<OpenIddictValidationDispatcher> _logger;
private readonly IOptionsMonitor<OpenIddictValidationOptions> _options;
/// <summary>
/// Creates a new instance of the <see cref="OpenIddictValidationFactory"/> class.
/// </summary>
public OpenIddictValidationFactory(
[NotNull] ILogger<OpenIddictValidationDispatcher> logger,
[NotNull] IOptionsMonitor<OpenIddictValidationOptions> options)
{
_logger = logger;
_options = options;
}
public ValueTask<OpenIddictValidationTransaction> CreateTransactionAsync()
=> new ValueTask<OpenIddictValidationTransaction>(new OpenIddictValidationTransaction
{
Issuer = _options.CurrentValue.Issuer,
Logger = _logger,
Options = _options.CurrentValue
});
}
}

27
src/OpenIddict.Validation/OpenIddictValidationHandlerDescriptor.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
@ -47,6 +48,11 @@ namespace OpenIddict.Validation
/// </summary> /// </summary>
public ServiceDescriptor ServiceDescriptor { get; private set; } public ServiceDescriptor ServiceDescriptor { get; private set; }
/// <summary>
/// Gets the type associated with the handler.
/// </summary>
public OpenIddictValidationHandlerType Type { get; private set; }
/// <summary> /// <summary>
/// Creates a builder allowing to initialize an immutable descriptor. /// Creates a builder allowing to initialize an immutable descriptor.
/// </summary> /// </summary>
@ -64,6 +70,7 @@ namespace OpenIddict.Validation
private ServiceDescriptor _descriptor; private ServiceDescriptor _descriptor;
private readonly List<Type> _filterTypes = new List<Type>(); private readonly List<Type> _filterTypes = new List<Type>();
private int _order; private int _order;
private OpenIddictValidationHandlerType _type;
/// <summary> /// <summary>
/// Adds the type of a handler filter to the filters list. /// Adds the type of a handler filter to the filters list.
@ -131,6 +138,23 @@ namespace OpenIddict.Validation
return this; return this;
} }
/// <summary>
/// Sets the type associated to the handler.
/// </summary>
/// <param name="type">The handler type.</param>
/// <returns>The builder instance, so that calls can be easily chained.</returns>
public Builder<TContext> SetType(OpenIddictValidationHandlerType type)
{
if (!Enum.IsDefined(typeof(OpenIddictValidationHandlerType), type))
{
throw new InvalidEnumArgumentException(nameof(type), (int) type, typeof(OpenIddictValidationHandlerType));
}
_type = type;
return this;
}
/// <summary> /// <summary>
/// Configures the descriptor to use the specified inline handler. /// Configures the descriptor to use the specified inline handler.
/// </summary> /// </summary>
@ -192,7 +216,8 @@ namespace OpenIddict.Validation
ContextType = typeof(TContext), ContextType = typeof(TContext),
FilterTypes = _filterTypes.ToImmutableArray(), FilterTypes = _filterTypes.ToImmutableArray(),
Order = _order, Order = _order,
ServiceDescriptor = _descriptor ?? throw new InvalidOperationException("No service descriptor was set.") ServiceDescriptor = _descriptor ?? throw new InvalidOperationException("No service descriptor was set."),
Type = _type
}; };
} }
} }

29
src/OpenIddict.Validation/OpenIddictValidationHandlerType.cs

@ -0,0 +1,29 @@
/*
* 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.
*/
namespace OpenIddict.Validation
{
/// <summary>
/// Represents the type of an OpenIddict validation handler.
/// </summary>
public enum OpenIddictValidationHandlerType
{
/// <summary>
/// The handler is of an unspecified type.
/// </summary>
Unknown = 0,
/// <summary>
/// The handler is a built-in handler, provided as part of the official OpenIddict packages.
/// </summary>
BuiltIn = 1,
/// <summary>
/// The handler is a custom handler, registered by the end user or a third-party package.
/// </summary>
Custom = 2
}
}

14
src/OpenIddict.Validation/OpenIddictValidationHandlers.cs

@ -63,6 +63,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateAccessTokenParameter>() .UseSingletonHandler<ValidateAccessTokenParameter>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -121,6 +122,7 @@ namespace OpenIddict.Validation
.AddFilter<RequireTokenEntryValidationEnabled>() .AddFilter<RequireTokenEntryValidationEnabled>()
.UseScopedHandler<ValidateReferenceTokenIdentifier>() .UseScopedHandler<ValidateReferenceTokenIdentifier>()
.SetOrder(ValidateAccessTokenParameter.Descriptor.Order + 1_000) .SetOrder(ValidateAccessTokenParameter.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -185,6 +187,7 @@ namespace OpenIddict.Validation
.AddFilter<RequireLocalValidation>() .AddFilter<RequireLocalValidation>()
.UseSingletonHandler<ValidateIdentityModelToken>() .UseSingletonHandler<ValidateIdentityModelToken>()
.SetOrder(ValidateReferenceTokenIdentifier.Descriptor.Order + 1_000) .SetOrder(ValidateReferenceTokenIdentifier.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -291,6 +294,7 @@ namespace OpenIddict.Validation
.AddFilter<RequireIntrospectionValidation>() .AddFilter<RequireIntrospectionValidation>()
.UseSingletonHandler<IntrospectToken>() .UseSingletonHandler<IntrospectToken>()
.SetOrder(ValidateIdentityModelToken.Descriptor.Order + 1_000) .SetOrder(ValidateIdentityModelToken.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -362,6 +366,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<NormalizeScopeClaims>() .UseSingletonHandler<NormalizeScopeClaims>()
.SetOrder(IntrospectToken.Descriptor.Order + 1_000) .SetOrder(IntrospectToken.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -412,6 +417,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<MapInternalClaims>() .UseSingletonHandler<MapInternalClaims>()
.SetOrder(NormalizeScopeClaims.Descriptor.Order + 1_000) .SetOrder(NormalizeScopeClaims.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -534,6 +540,7 @@ namespace OpenIddict.Validation
.AddFilter<RequireTokenEntryValidationEnabled>() .AddFilter<RequireTokenEntryValidationEnabled>()
.UseScopedHandler<RestoreReferenceTokenProperties>() .UseScopedHandler<RestoreReferenceTokenProperties>()
.SetOrder(MapInternalClaims.Descriptor.Order + 1_000) .SetOrder(MapInternalClaims.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -581,6 +588,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidatePrincipal>() .UseSingletonHandler<ValidatePrincipal>()
.SetOrder(RestoreReferenceTokenProperties.Descriptor.Order + 1_000) .SetOrder(RestoreReferenceTokenProperties.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -647,6 +655,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateExpirationDate>() .UseSingletonHandler<ValidateExpirationDate>()
.SetOrder(ValidatePrincipal.Descriptor.Order + 1_000) .SetOrder(ValidatePrincipal.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -692,6 +701,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.UseSingletonHandler<ValidateAudience>() .UseSingletonHandler<ValidateAudience>()
.SetOrder(ValidateExpirationDate.Descriptor.Order + 1_000) .SetOrder(ValidateExpirationDate.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -771,6 +781,7 @@ namespace OpenIddict.Validation
.AddFilter<RequireTokenEntryValidationEnabled>() .AddFilter<RequireTokenEntryValidationEnabled>()
.UseScopedHandler<ValidateTokenEntry>() .UseScopedHandler<ValidateTokenEntry>()
.SetOrder(ValidateAudience.Descriptor.Order + 1_000) .SetOrder(ValidateAudience.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -834,6 +845,7 @@ namespace OpenIddict.Validation
.AddFilter<RequireAuthorizationEntryValidationEnabled>() .AddFilter<RequireAuthorizationEntryValidationEnabled>()
.UseScopedHandler<ValidateAuthorizationEntry>() .UseScopedHandler<ValidateAuthorizationEntry>()
.SetOrder(ValidateTokenEntry.Descriptor.Order + 1_000) .SetOrder(ValidateTokenEntry.Descriptor.Order + 1_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context) public async ValueTask HandleAsync([NotNull] ProcessAuthenticationContext context)
@ -875,6 +887,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessChallengeContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<ProcessChallengeContext>()
.UseSingletonHandler<AttachDefaultChallengeError>() .UseSingletonHandler<AttachDefaultChallengeError>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>
@ -938,6 +951,7 @@ namespace OpenIddict.Validation
= OpenIddictValidationHandlerDescriptor.CreateBuilder<TContext>() = OpenIddictValidationHandlerDescriptor.CreateBuilder<TContext>()
.UseSingletonHandler<HandleErrorResponse<TContext>>() .UseSingletonHandler<HandleErrorResponse<TContext>>()
.SetOrder(int.MinValue + 100_000) .SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictValidationHandlerType.BuiltIn)
.Build(); .Build();
/// <summary> /// <summary>

17
src/OpenIddict.Validation/OpenIddictValidationOptions.cs

@ -24,7 +24,7 @@ namespace OpenIddict.Validation
/// Gets the list of credentials used to encrypt the tokens issued by the /// Gets the list of credentials used to encrypt the tokens issued by the
/// OpenIddict validation services. Note: only symmetric credentials are supported. /// OpenIddict validation services. Note: only symmetric credentials are supported.
/// </summary> /// </summary>
public IList<EncryptingCredentials> EncryptionCredentials { get; } = new List<EncryptingCredentials>(); public List<EncryptingCredentials> EncryptionCredentials { get; } = new List<EncryptingCredentials>();
/// <summary> /// <summary>
/// Gets or sets the JWT handler used to protect and unprotect tokens. /// Gets or sets the JWT handler used to protect and unprotect tokens.
@ -35,16 +35,11 @@ namespace OpenIddict.Validation
}; };
/// <summary> /// <summary>
/// Gets the list of the user-defined/custom handlers responsible of processing the OpenIddict validation requests. /// Gets the list of the handlers responsible of processing the OpenIddict validation operations.
/// Note: the handlers added to this list must be also registered in the DI container using an appropriate lifetime. /// Note: the list is automatically sorted based on the order assigned to each handler descriptor.
/// As such, it MUST NOT be mutated after options initialization to preserve the exact order.
/// </summary> /// </summary>
public IList<OpenIddictValidationHandlerDescriptor> CustomHandlers { get; } = public List<OpenIddictValidationHandlerDescriptor> Handlers { get; } =
new List<OpenIddictValidationHandlerDescriptor>();
/// <summary>
/// Gets the list of the built-in handlers responsible of processing the OpenIddict validation requests
/// </summary>
public IList<OpenIddictValidationHandlerDescriptor> DefaultHandlers { get; } =
new List<OpenIddictValidationHandlerDescriptor>(OpenIddictValidationHandlers.DefaultHandlers); new List<OpenIddictValidationHandlerDescriptor>(OpenIddictValidationHandlers.DefaultHandlers);
/// <summary> /// <summary>
@ -106,7 +101,7 @@ namespace OpenIddict.Validation
/// Setting this property is recommended when the authorization /// Setting this property is recommended when the authorization
/// server issues access tokens for multiple distinct resource servers. /// server issues access tokens for multiple distinct resource servers.
/// </summary> /// </summary>
public ISet<string> Audiences { get; } = new HashSet<string>(StringComparer.Ordinal); public HashSet<string> Audiences { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary> /// <summary>
/// Gets the token validation parameters used by the OpenIddict validation services. /// Gets the token validation parameters used by the OpenIddict validation services.

39
src/OpenIddict.Validation/OpenIddictValidationService.cs

@ -59,8 +59,9 @@ namespace OpenIddict.Validation
// can be disposed of asynchronously if it implements IAsyncDisposable. // can be disposed of asynchronously if it implements IAsyncDisposable.
try try
{ {
var provider = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationProvider>(); var dispatcher = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationDispatcher>();
var transaction = await provider.CreateTransactionAsync(); var factory = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationFactory>();
var transaction = await factory.CreateTransactionAsync();
var request = new OpenIddictRequest(); var request = new OpenIddictRequest();
request = await PrepareConfigurationRequestAsync(); request = await PrepareConfigurationRequestAsync();
@ -83,7 +84,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -110,7 +111,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -137,7 +138,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -165,7 +166,7 @@ namespace OpenIddict.Validation
Response = response Response = response
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -230,8 +231,9 @@ namespace OpenIddict.Validation
// can be disposed of asynchronously if it implements IAsyncDisposable. // can be disposed of asynchronously if it implements IAsyncDisposable.
try try
{ {
var provider = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationProvider>(); var dispatcher = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationDispatcher>();
var transaction = await provider.CreateTransactionAsync(); var factory = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationFactory>();
var transaction = await factory.CreateTransactionAsync();
var request = new OpenIddictRequest(); var request = new OpenIddictRequest();
request = await PrepareCryptographyRequestAsync(); request = await PrepareCryptographyRequestAsync();
@ -255,7 +257,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -282,7 +284,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -309,7 +311,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -337,7 +339,7 @@ namespace OpenIddict.Validation
Response = response Response = response
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -421,8 +423,9 @@ namespace OpenIddict.Validation
// can be disposed of asynchronously if it implements IAsyncDisposable. // can be disposed of asynchronously if it implements IAsyncDisposable.
try try
{ {
var provider = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationProvider>(); var dispatcher = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationDispatcher>();
var transaction = await provider.CreateTransactionAsync(); var factory = scope.ServiceProvider.GetRequiredService<IOpenIddictValidationFactory>();
var transaction = await factory.CreateTransactionAsync();
var request = new OpenIddictRequest(); var request = new OpenIddictRequest();
request = await PrepareIntrospectionRequestAsync(); request = await PrepareIntrospectionRequestAsync();
@ -447,7 +450,7 @@ namespace OpenIddict.Validation
TokenType = type TokenType = type
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -474,7 +477,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -501,7 +504,7 @@ namespace OpenIddict.Validation
Request = request Request = request
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {
@ -531,7 +534,7 @@ namespace OpenIddict.Validation
TokenType = type TokenType = type
}; };
await provider.DispatchAsync(context); await dispatcher.DispatchAsync(context);
if (context.IsRejected) if (context.IsRejected)
{ {

3
test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs

@ -197,8 +197,7 @@ namespace OpenIddict.Server.Tests
// Assert // Assert
Assert.DoesNotContain(services, x => x.ServiceType == descriptor.ServiceDescriptor.ServiceType); Assert.DoesNotContain(services, x => x.ServiceType == descriptor.ServiceDescriptor.ServiceType);
Assert.DoesNotContain(options.CustomHandlers, x => x.ServiceDescriptor.ServiceType == descriptor.ServiceDescriptor.ServiceType); Assert.DoesNotContain(options.Handlers, x => x.ServiceDescriptor.ServiceType == descriptor.ServiceDescriptor.ServiceType);
Assert.DoesNotContain(options.DefaultHandlers, x => x.ServiceDescriptor.ServiceType == descriptor.ServiceDescriptor.ServiceType);
} }
[Fact] [Fact]

Loading…
Cancel
Save