/*
* 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 JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Owin;
using Microsoft.Owin.Security.Infrastructure;
namespace OpenIddict.Validation.Owin
{
///
/// Provides the entry point necessary to register the OpenIddict validation in an OWIN pipeline.
/// Note: this middleware is intented to be used with dependency injection containers
/// that support middleware resolution, like Autofac. Since it depends on scoped services,
/// it is NOT recommended to instantiate it as a singleton like a regular OWIN middleware.
///
public class OpenIddictValidationOwinMiddleware : AuthenticationMiddleware
{
private readonly ILogger _logger;
private readonly IOpenIddictValidationProvider _provider;
///
/// Creates a new instance of the class.
///
/// The next middleware in the pipeline, if applicable.
/// The logger used by this middleware.
/// The OpenIddict validation OWIN options.
/// The OpenIddict validation provider.
public OpenIddictValidationOwinMiddleware(
[CanBeNull] OwinMiddleware next,
[NotNull] ILogger logger,
[NotNull] IOptionsMonitor options,
[NotNull] IOpenIddictValidationProvider provider)
: base(next, options.CurrentValue)
{
_logger = logger;
_provider = provider;
}
///
/// Creates and returns a new instance.
///
/// A new instance of the class.
protected override AuthenticationHandler CreateHandler()
=> new OpenIddictValidationOwinHandler(_logger, _provider);
}
}