Browse Source

Backport naming changes to OpenIddict 1.x

pull/2236/head
Kévin Chalet 8 years ago
parent
commit
6634880115
  1. 4
      src/OpenIddict.Server/IOpenIddictServerEventDispatcher.cs
  2. 16
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Authentication.cs
  3. 31
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Discovery.cs
  4. 20
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Exchange.cs
  5. 4
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs
  6. 16
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Introspection.cs
  7. 16
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Revocation.cs
  8. 24
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Serialization.cs
  9. 16
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Session.cs
  10. 16
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Userinfo.cs
  11. 16
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.cs
  12. 8
      src/OpenIddict.Server/OpenIddictServerEventDispatcher.cs
  13. 2
      src/OpenIddict.Server/OpenIddictServerExtensions.cs
  14. 4
      src/OpenIddict.Validation/IOpenIddictValidationEventDispatcher.cs
  15. 24
      src/OpenIddict.Validation/Internal/OpenIddictValidationProvider.cs
  16. 8
      src/OpenIddict.Validation/OpenIddictValidationEventDispatcher.cs
  17. 2
      src/OpenIddict.Validation/OpenIddictValidationExtensions.cs
  18. 20
      test/OpenIddict.Server.Tests/OpenIddictServerEventDispatcherTests.cs
  19. 4
      test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs
  20. 20
      test/OpenIddict.Validation.Tests/OpenIddictValidationEventDispatcherTests.cs
  21. 4
      test/OpenIddict.Validation.Tests/OpenIddictValidationExtensionsTests.cs

4
src/OpenIddict.Server/IOpenIddictServerEventService.cs → src/OpenIddict.Server/IOpenIddictServerEventDispatcher.cs

@ -13,7 +13,7 @@ namespace OpenIddict.Server
/// <summary>
/// Dispatches events by invoking the corresponding handlers.
/// </summary>
public interface IOpenIddictServerEventService
public interface IOpenIddictServerEventDispatcher
{
/// <summary>
/// Publishes a new event.
@ -21,6 +21,6 @@ namespace OpenIddict.Server
/// <typeparam name="TEvent">The type of the event to publish.</typeparam>
/// <param name="notification">The event to publish.</param>
/// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
Task PublishAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictServerEvent;
Task DispatchAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictServerEvent;
}
}

16
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Authentication.cs

@ -113,8 +113,8 @@ namespace OpenIddict.Server.Internal
}
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractAuthorizationRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractAuthorizationRequest(context));
}
public override async Task ValidateAuthorizationRequest([NotNull] ValidateAuthorizationRequestContext context)
@ -441,8 +441,8 @@ namespace OpenIddict.Server.Internal
context.Validate();
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateAuthorizationRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateAuthorizationRequest(context));
}
public override async Task HandleAuthorizationRequest([NotNull] HandleAuthorizationRequestContext context)
@ -490,8 +490,8 @@ namespace OpenIddict.Server.Internal
return;
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleAuthorizationRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleAuthorizationRequest(context));
}
public override async Task ApplyAuthorizationResponse([NotNull] ApplyAuthorizationResponseContext context)
@ -535,8 +535,8 @@ namespace OpenIddict.Server.Internal
}
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyAuthorizationResponse(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyAuthorizationResponse(context));
}
}
}

31
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Discovery.cs

@ -19,12 +19,12 @@ namespace OpenIddict.Server.Internal
public sealed partial class OpenIddictServerProvider : OpenIdConnectServerProvider
{
public override Task ExtractConfigurationRequest([NotNull] ExtractConfigurationRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractConfigurationRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractConfigurationRequest(context));
public override Task ValidateConfigurationRequest([NotNull] ValidateConfigurationRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateConfigurationRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateConfigurationRequest(context));
public override Task HandleConfigurationRequest([NotNull] HandleConfigurationRequestContext context)
{
@ -54,27 +54,28 @@ namespace OpenIddict.Server.Internal
context.Metadata[OpenIdConnectConstants.Metadata.RequestParameterSupported] = false;
context.Metadata[OpenIdConnectConstants.Metadata.RequestUriParameterSupported] = false;
return GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.HandleConfigurationRequest(context));
return GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleConfigurationRequest(context));
}
public override Task ApplyConfigurationResponse([NotNull] ApplyConfigurationResponseContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyConfigurationResponse(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyConfigurationResponse(context));
public override Task ExtractCryptographyRequest([NotNull] ExtractCryptographyRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractCryptographyRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractCryptographyRequest(context));
public override Task ValidateCryptographyRequest([NotNull] ValidateCryptographyRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateCryptographyRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateCryptographyRequest(context));
public override Task HandleCryptographyRequest([NotNull] HandleCryptographyRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleCryptographyRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleCryptographyRequest(context));
public override Task ApplyCryptographyResponse([NotNull] ApplyCryptographyResponseContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyCryptographyResponse(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyCryptographyResponse(context));
}
}

20
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Exchange.cs

@ -27,8 +27,8 @@ namespace OpenIddict.Server.Internal
public sealed partial class OpenIddictServerProvider : OpenIdConnectServerProvider
{
public override Task ExtractTokenRequest([NotNull] ExtractTokenRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractTokenRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractTokenRequest(context));
public override async Task ValidateTokenRequest([NotNull] ValidateTokenRequestContext context)
{
@ -316,8 +316,8 @@ namespace OpenIddict.Server.Internal
context.Validate();
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateTokenRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateTokenRequest(context));
}
public override async Task HandleTokenRequest([NotNull] HandleTokenRequestContext context)
@ -340,8 +340,8 @@ namespace OpenIddict.Server.Internal
// the user code to handle the token request.
context.SkipToNextMiddleware();
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleTokenRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleTokenRequest(context));
return;
}
@ -433,12 +433,12 @@ namespace OpenIddict.Server.Internal
// the user code to handle the token request.
context.SkipToNextMiddleware();
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleTokenRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleTokenRequest(context));
}
public override Task ApplyTokenResponse([NotNull] ApplyTokenResponseContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyTokenResponse(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyTokenResponse(context));
}
}

4
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs

@ -669,8 +669,8 @@ namespace OpenIddict.Server.Internal
private static ILogger GetLogger(IServiceProvider provider)
=> provider.GetRequiredService<ILogger<OpenIddictServerProvider>>();
private static IOpenIddictServerEventService GetEventService(IServiceProvider provider)
=> provider.GetRequiredService<IOpenIddictServerEventService>();
private static IOpenIddictServerEventDispatcher GetEventDispatcher(IServiceProvider provider)
=> provider.GetRequiredService<IOpenIddictServerEventDispatcher>();
private static IOpenIddictApplicationManager GetApplicationManager(IServiceProvider provider)
=> provider.GetService<IOpenIddictApplicationManager>() ?? throw new InvalidOperationException(new StringBuilder()

16
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Introspection.cs

@ -23,8 +23,8 @@ namespace OpenIddict.Server.Internal
public sealed partial class OpenIddictServerProvider : OpenIdConnectServerProvider
{
public override Task ExtractIntrospectionRequest([NotNull] ExtractIntrospectionRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractIntrospectionRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractIntrospectionRequest(context));
public override async Task ValidateIntrospectionRequest([NotNull] ValidateIntrospectionRequestContext context)
{
@ -102,8 +102,8 @@ namespace OpenIddict.Server.Internal
context.Validate();
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateIntrospectionRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateIntrospectionRequest(context));
}
public override async Task HandleIntrospectionRequest([NotNull] HandleIntrospectionRequestContext context)
@ -185,12 +185,12 @@ namespace OpenIddict.Server.Internal
}
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleIntrospectionRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleIntrospectionRequest(context));
}
public override Task ApplyIntrospectionResponse([NotNull] ApplyIntrospectionResponseContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyIntrospectionResponse(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyIntrospectionResponse(context));
}
}

16
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Revocation.cs

@ -25,8 +25,8 @@ namespace OpenIddict.Server.Internal
public sealed partial class OpenIddictServerProvider : OpenIdConnectServerProvider
{
public override Task ExtractRevocationRequest([NotNull] ExtractRevocationRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractRevocationRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractRevocationRequest(context));
public override async Task ValidateRevocationRequest([NotNull] ValidateRevocationRequestContext context)
{
@ -169,8 +169,8 @@ namespace OpenIddict.Server.Internal
context.Validate();
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateRevocationRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateRevocationRequest(context));
}
public override async Task HandleRevocationRequest([NotNull] HandleRevocationRequestContext context)
@ -242,12 +242,12 @@ namespace OpenIddict.Server.Internal
context.Revoked = true;
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleRevocationRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleRevocationRequest(context));
}
public override Task ApplyRevocationResponse([NotNull] ApplyRevocationResponseContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyRevocationResponse(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyRevocationResponse(context));
}
}

24
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Serialization.cs

@ -39,7 +39,8 @@ namespace OpenIddict.Server.Internal
context.HandleResponse();
}
await GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.DeserializeAccessToken(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.DeserializeAccessToken(context));
}
public override async Task DeserializeAuthorizationCode([NotNull] DeserializeAuthorizationCodeContext context)
@ -58,11 +59,13 @@ namespace OpenIddict.Server.Internal
// Prevent the OpenID Connect server middleware from using its default logic.
context.HandleResponse();
await GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.DeserializeAuthorizationCode(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.DeserializeAuthorizationCode(context));
}
public override Task DeserializeIdentityToken(DeserializeIdentityTokenContext context)
=> GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.DeserializeIdentityToken(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.DeserializeIdentityToken(context));
public override async Task DeserializeRefreshToken([NotNull] DeserializeRefreshTokenContext context)
{
@ -80,7 +83,8 @@ namespace OpenIddict.Server.Internal
// Prevent the OpenID Connect server middleware from using its default logic.
context.HandleResponse();
await GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.DeserializeRefreshToken(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.DeserializeRefreshToken(context));
}
public override async Task SerializeAccessToken([NotNull] SerializeAccessTokenContext context)
@ -107,7 +111,8 @@ namespace OpenIddict.Server.Internal
// Otherwise, let the OpenID Connect server middleware
// serialize the token using its default internal logic.
await GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.SerializeAccessToken(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.SerializeAccessToken(context));
}
public override async Task SerializeAuthorizationCode([NotNull] SerializeAuthorizationCodeContext context)
@ -136,11 +141,13 @@ namespace OpenIddict.Server.Internal
// Otherwise, let the OpenID Connect server middleware
// serialize the token using its default internal logic.
await GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.SerializeAuthorizationCode(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.SerializeAuthorizationCode(context));
}
public override Task SerializeIdentityToken(SerializeIdentityTokenContext context)
=> GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.SerializeIdentityToken(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.SerializeIdentityToken(context));
public override async Task SerializeRefreshToken([NotNull] SerializeRefreshTokenContext context)
{
@ -168,7 +175,8 @@ namespace OpenIddict.Server.Internal
// Otherwise, let the OpenID Connect server middleware
// serialize the token using its default internal logic.
await GetEventService(context.HttpContext.RequestServices).PublishAsync(new OpenIddictServerEvents.SerializeRefreshToken(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.SerializeRefreshToken(context));
}
}
}

16
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Session.cs

@ -84,8 +84,8 @@ namespace OpenIddict.Server.Internal
}
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractLogoutRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractLogoutRequest(context));
}
public override async Task ValidateLogoutRequest([NotNull] ValidateLogoutRequestContext context)
@ -162,8 +162,8 @@ namespace OpenIddict.Server.Internal
context.Validate();
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateLogoutRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateLogoutRequest(context));
}
public override async Task HandleLogoutRequest([NotNull] HandleLogoutRequestContext context)
@ -211,8 +211,8 @@ namespace OpenIddict.Server.Internal
return;
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleLogoutRequest(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleLogoutRequest(context));
}
public override async Task ApplyLogoutResponse([NotNull] ApplyLogoutResponseContext context)
@ -256,8 +256,8 @@ namespace OpenIddict.Server.Internal
}
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyLogoutResponse(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyLogoutResponse(context));
}
}
}

16
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Userinfo.cs

@ -29,20 +29,20 @@ namespace OpenIddict.Server.Internal
// the user code to handle the userinfo request.
context.SkipToNextMiddleware();
return GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ExtractUserinfoRequest(context));
return GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ExtractUserinfoRequest(context));
}
public override Task ValidateUserinfoRequest([NotNull] ValidateUserinfoRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ValidateUserinfoRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ValidateUserinfoRequest(context));
public override Task HandleUserinfoRequest([NotNull] HandleUserinfoRequestContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.HandleUserinfoRequest(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.HandleUserinfoRequest(context));
public override Task ApplyUserinfoResponse([NotNull] ApplyUserinfoResponseContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ApplyUserinfoResponse(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ApplyUserinfoResponse(context));
}
}

16
src/OpenIddict.Server/Internal/OpenIddictServerProvider.cs

@ -26,8 +26,8 @@ namespace OpenIddict.Server.Internal
public sealed partial class OpenIddictServerProvider : OpenIdConnectServerProvider
{
public override Task MatchEndpoint([NotNull] MatchEndpointContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.MatchEndpoint(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.MatchEndpoint(context));
public override Task ProcessChallengeResponse([NotNull] ProcessChallengeResponseContext context)
{
@ -43,8 +43,8 @@ namespace OpenIddict.Server.Internal
context.Response.AddParameter(parameter.Item2, parameter.Item3);
}
return GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ProcessChallengeResponse(context));
return GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ProcessChallengeResponse(context));
}
public override async Task ProcessSigninResponse([NotNull] ProcessSigninResponseContext context)
@ -199,8 +199,8 @@ namespace OpenIddict.Server.Internal
context.Ticket.RemoveProperty(parameter.Item1);
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ProcessSigninResponse(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ProcessSigninResponse(context));
}
public override Task ProcessSignoutResponse([NotNull] ProcessSignoutResponseContext context)
@ -214,8 +214,8 @@ namespace OpenIddict.Server.Internal
context.Response.AddParameter(parameter.Item2, parameter.Item3);
}
return GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictServerEvents.ProcessSignoutResponse(context));
return GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictServerEvents.ProcessSignoutResponse(context));
}
}
}

8
src/OpenIddict.Server/OpenIddictServerEventService.cs → src/OpenIddict.Server/OpenIddictServerEventDispatcher.cs

@ -14,14 +14,14 @@ namespace OpenIddict.Server
/// <summary>
/// Dispatches events by invoking the corresponding notification handlers.
/// </summary>
public class OpenIddictServerEventService : IOpenIddictServerEventService
public class OpenIddictServerEventDispatcher : IOpenIddictServerEventDispatcher
{
private readonly IServiceProvider _provider;
/// <summary>
/// Creates a new instance of the <see cref="OpenIddictServerEventService"/> class.
/// Creates a new instance of the <see cref="OpenIddictServerEventDispatcher"/> class.
/// </summary>
public OpenIddictServerEventService([NotNull] IServiceProvider provider)
public OpenIddictServerEventDispatcher([NotNull] IServiceProvider provider)
=> _provider = provider;
/// <summary>
@ -30,7 +30,7 @@ namespace OpenIddict.Server
/// <typeparam name="TEvent">The type of the event to publish.</typeparam>
/// <param name="notification">The event to publish.</param>
/// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
public async Task PublishAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictServerEvent
public async Task DispatchAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictServerEvent
{
if (notification == null)
{

2
src/OpenIddict.Server/OpenIddictServerExtensions.cs

@ -46,7 +46,7 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.AddMemoryCache();
builder.Services.AddOptions();
builder.Services.TryAddScoped<IOpenIddictServerEventService, OpenIddictServerEventService>();
builder.Services.TryAddScoped<IOpenIddictServerEventDispatcher, OpenIddictServerEventDispatcher>();
return new OpenIddictServerBuilder(builder.Services);
}

4
src/OpenIddict.Validation/IOpenIddictValidationEventService.cs → src/OpenIddict.Validation/IOpenIddictValidationEventDispatcher.cs

@ -12,7 +12,7 @@ namespace OpenIddict.Validation
/// <summary>
/// Dispatches events by invoking the corresponding handlers.
/// </summary>
public interface IOpenIddictValidationEventService
public interface IOpenIddictValidationEventDispatcher
{
/// <summary>
/// Publishes a new event.
@ -20,6 +20,6 @@ namespace OpenIddict.Validation
/// <typeparam name="TEvent">The type of the event to publish.</typeparam>
/// <param name="notification">The event to publish.</param>
/// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
Task PublishAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictValidationEvent;
Task DispatchAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictValidationEvent;
}
}

24
src/OpenIddict.Validation/Internal/OpenIddictValidationProvider.cs

@ -24,12 +24,12 @@ namespace OpenIddict.Validation.Internal
public sealed class OpenIddictValidationProvider : OAuthValidationEvents
{
public override Task ApplyChallenge([NotNull] ApplyChallengeContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictValidationEvents.ApplyChallenge(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictValidationEvents.ApplyChallenge(context));
public override Task CreateTicket([NotNull] CreateTicketContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictValidationEvents.CreateTicket(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictValidationEvents.CreateTicket(context));
public override async Task DecryptToken([NotNull] DecryptTokenContext context)
{
@ -113,13 +113,13 @@ namespace OpenIddict.Validation.Internal
context.HandleResponse();
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictValidationEvents.DecryptToken(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictValidationEvents.DecryptToken(context));
}
public override Task RetrieveToken([NotNull] RetrieveTokenContext context)
=> GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictValidationEvents.RetrieveToken(context));
=> GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictValidationEvents.RetrieveToken(context));
public override async Task ValidateToken([NotNull] ValidateTokenContext context)
{
@ -183,14 +183,14 @@ namespace OpenIddict.Validation.Internal
}
}
await GetEventService(context.HttpContext.RequestServices)
.PublishAsync(new OpenIddictValidationEvents.ValidateToken(context));
await GetEventDispatcher(context.HttpContext.RequestServices)
.DispatchAsync(new OpenIddictValidationEvents.ValidateToken(context));
}
private static ILogger GetLogger(IServiceProvider provider)
=> provider.GetRequiredService<ILogger<OpenIddictValidationProvider>>();
private static IOpenIddictValidationEventService GetEventService(IServiceProvider provider)
=> provider.GetRequiredService<IOpenIddictValidationEventService>();
private static IOpenIddictValidationEventDispatcher GetEventDispatcher(IServiceProvider provider)
=> provider.GetRequiredService<IOpenIddictValidationEventDispatcher>();
}
}

8
src/OpenIddict.Validation/OpenIddictValidationEventService.cs → src/OpenIddict.Validation/OpenIddictValidationEventDispatcher.cs

@ -14,14 +14,14 @@ namespace OpenIddict.Validation
/// <summary>
/// Dispatches events by invoking the corresponding notification handlers.
/// </summary>
public class OpenIddictValidationEventService : IOpenIddictValidationEventService
public class OpenIddictValidationEventDispatcher : IOpenIddictValidationEventDispatcher
{
private readonly IServiceProvider _provider;
/// <summary>
/// Creates a new instance of the <see cref="OpenIddictValidationEventService"/> class.
/// Creates a new instance of the <see cref="OpenIddictValidationEventDispatcher"/> class.
/// </summary>
public OpenIddictValidationEventService([NotNull] IServiceProvider provider)
public OpenIddictValidationEventDispatcher([NotNull] IServiceProvider provider)
=> _provider = provider;
/// <summary>
@ -30,7 +30,7 @@ namespace OpenIddict.Validation
/// <typeparam name="TEvent">The type of the event to publish.</typeparam>
/// <param name="notification">The event to publish.</param>
/// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
public async Task PublishAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictValidationEvent
public async Task DispatchAsync<TEvent>([NotNull] TEvent notification) where TEvent : class, IOpenIddictValidationEvent
{
if (notification == null)
{

2
src/OpenIddict.Validation/OpenIddictValidationExtensions.cs

@ -42,7 +42,7 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.AddLogging();
builder.Services.AddOptions();
builder.Services.TryAddScoped<IOpenIddictValidationEventService, OpenIddictValidationEventService>();
builder.Services.TryAddScoped<IOpenIddictValidationEventDispatcher, OpenIddictValidationEventDispatcher>();
return new OpenIddictValidationBuilder(builder.Services);
}

20
test/OpenIddict.Server.Tests/OpenIddictServerEventServiceTests.cs → test/OpenIddict.Server.Tests/OpenIddictServerEventDispatcherTests.cs

@ -12,24 +12,24 @@ using Xunit;
namespace OpenIddict.Server.Tests
{
public class OpenIddictServerEventServiceTests
public class OpenIddictServerEventDispatcherTests
{
[Fact]
public async Task PublishAsync_ThrowsAnExceptionForNullNotification()
public async Task DispatchAsync_ThrowsAnExceptionForNullNotification()
{
// Arrange
var provider = Mock.Of<IServiceProvider>();
var service = new OpenIddictServerEventService(provider);
var dispatcher = new OpenIddictServerEventDispatcher(provider);
// Act and assert
var exception = await Assert.ThrowsAsync<ArgumentNullException>(()
=> service.PublishAsync<Event>(notification: null));
=> dispatcher.DispatchAsync<Event>(notification: null));
Assert.Equal("notification", exception.ParamName);
}
[Fact]
public async Task PublishAsync_InvokesHandlers()
public async Task DispatchAsync_InvokesHandlers()
{
// Arrange
var handlers = new List<IOpenIddictServerEventHandler<Event>>
@ -42,12 +42,12 @@ namespace OpenIddict.Server.Tests
provider.Setup(mock => mock.GetService(typeof(IEnumerable<IOpenIddictServerEventHandler<Event>>)))
.Returns(handlers);
var service = new OpenIddictServerEventService(provider.Object);
var dispatcher = new OpenIddictServerEventDispatcher(provider.Object);
var notification = new Event();
// Act
await service.PublishAsync(notification);
await dispatcher.DispatchAsync(notification);
// Assert
Mock.Get(handlers[0]).Verify(mock => mock.HandleAsync(notification), Times.Once());
@ -55,7 +55,7 @@ namespace OpenIddict.Server.Tests
}
[Fact]
public async Task PublishAsync_StopsInvokingHandlersWhenHandledIsReturned()
public async Task DispatchAsync_StopsInvokingHandlersWhenHandledIsReturned()
{
// Arrange
var handlers = new List<IOpenIddictServerEventHandler<Event>>
@ -73,12 +73,12 @@ namespace OpenIddict.Server.Tests
provider.Setup(mock => mock.GetService(typeof(IEnumerable<IOpenIddictServerEventHandler<Event>>)))
.Returns(handlers);
var service = new OpenIddictServerEventService(provider.Object);
var dispatcher = new OpenIddictServerEventDispatcher(provider.Object);
var notification = new Event();
// Act
await service.PublishAsync(notification);
await dispatcher.DispatchAsync(notification);
// Assert
Mock.Get(handlers[0]).Verify(mock => mock.HandleAsync(notification), Times.Once());

4
test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs

@ -104,8 +104,8 @@ namespace OpenIddict.Server.Tests
// Assert
Assert.Contains(services, service => service.Lifetime == ServiceLifetime.Scoped &&
service.ServiceType == typeof(IOpenIddictServerEventService) &&
service.ImplementationType == typeof(OpenIddictServerEventService));
service.ServiceType == typeof(IOpenIddictServerEventDispatcher) &&
service.ImplementationType == typeof(OpenIddictServerEventDispatcher));
}
[Fact]

20
test/OpenIddict.Validation.Tests/OpenIddictValidationEventServiceTests.cs → test/OpenIddict.Validation.Tests/OpenIddictValidationEventDispatcherTests.cs

@ -12,24 +12,24 @@ using Xunit;
namespace OpenIddict.Validation.Tests
{
public class OpenIddictValidationEventServiceTests
public class OpenIddictValidationEventDispatcherTests
{
[Fact]
public async Task PublishAsync_ThrowsAnExceptionForNullNotification()
public async Task DispatchAsync_ThrowsAnExceptionForNullNotification()
{
// Arrange
var provider = Mock.Of<IServiceProvider>();
var service = new OpenIddictValidationEventService(provider);
var dispatcher = new OpenIddictValidationEventDispatcher(provider);
// Act and assert
var exception = await Assert.ThrowsAsync<ArgumentNullException>(()
=> service.PublishAsync<Event>(notification: null));
=> dispatcher.DispatchAsync<Event>(notification: null));
Assert.Equal("notification", exception.ParamName);
}
[Fact]
public async Task PublishAsync_InvokesHandlers()
public async Task DispatchAsync_InvokesHandlers()
{
// Arrange
var handlers = new List<IOpenIddictValidationEventHandler<Event>>
@ -42,12 +42,12 @@ namespace OpenIddict.Validation.Tests
provider.Setup(mock => mock.GetService(typeof(IEnumerable<IOpenIddictValidationEventHandler<Event>>)))
.Returns(handlers);
var service = new OpenIddictValidationEventService(provider.Object);
var dispatcher = new OpenIddictValidationEventDispatcher(provider.Object);
var notification = new Event();
// Act
await service.PublishAsync(notification);
await dispatcher.DispatchAsync(notification);
// Assert
Mock.Get(handlers[0]).Verify(mock => mock.HandleAsync(notification), Times.Once());
@ -55,7 +55,7 @@ namespace OpenIddict.Validation.Tests
}
[Fact]
public async Task PublishAsync_StopsInvokingHandlersWhenHandledIsReturned()
public async Task DispatchAsync_StopsInvokingHandlersWhenHandledIsReturned()
{
// Arrange
var handlers = new List<IOpenIddictValidationEventHandler<Event>>
@ -73,12 +73,12 @@ namespace OpenIddict.Validation.Tests
provider.Setup(mock => mock.GetService(typeof(IEnumerable<IOpenIddictValidationEventHandler<Event>>)))
.Returns(handlers);
var service = new OpenIddictValidationEventService(provider.Object);
var dispatcher = new OpenIddictValidationEventDispatcher(provider.Object);
var notification = new Event();
// Act
await service.PublishAsync(notification);
await dispatcher.DispatchAsync(notification);
// Assert
Mock.Get(handlers[0]).Verify(mock => mock.HandleAsync(notification), Times.Once());

4
test/OpenIddict.Validation.Tests/OpenIddictValidationExtensionsTests.cs

@ -83,8 +83,8 @@ namespace OpenIddict.Validation.Tests
// Assert
Assert.Contains(services, service => service.Lifetime == ServiceLifetime.Scoped &&
service.ServiceType == typeof(IOpenIddictValidationEventService) &&
service.ImplementationType == typeof(OpenIddictValidationEventService));
service.ServiceType == typeof(IOpenIddictValidationEventDispatcher) &&
service.ImplementationType == typeof(OpenIddictValidationEventDispatcher));
}
[Fact]

Loading…
Cancel
Save