Versatile OpenID Connect stack for ASP.NET Core and Microsoft.Owin (compatible with ASP.NET 4.6.1)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
2.4 KiB

/*
* 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
{
/// <summary>
/// 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.
/// </summary>
public class OpenIddictValidationOwinMiddleware : AuthenticationMiddleware<OpenIddictValidationOwinOptions>
{
private readonly ILogger<OpenIddictValidationOwinMiddleware> _logger;
private readonly IOpenIddictValidationProvider _provider;
/// <summary>
/// Creates a new instance of the <see cref="OpenIddictValidationOwinMiddleware"/> class.
/// </summary>
/// <param name="next">The next middleware in the pipeline, if applicable.</param>
/// <param name="logger">The logger used by this middleware.</param>
/// <param name="options">The OpenIddict validation OWIN options.</param>
/// <param name="provider">The OpenIddict validation provider.</param>
public OpenIddictValidationOwinMiddleware(
[CanBeNull] OwinMiddleware next,
[NotNull] ILogger<OpenIddictValidationOwinMiddleware> logger,
[NotNull] IOptionsMonitor<OpenIddictValidationOwinOptions> options,
[NotNull] IOpenIddictValidationProvider provider)
: base(next, options.CurrentValue)
{
_logger = logger;
_provider = provider;
}
/// <summary>
/// Creates and returns a new <see cref="OpenIddictValidationOwinHandler"/> instance.
/// </summary>
/// <returns>A new instance of the <see cref="OpenIddictValidationOwinHandler"/> class.</returns>
protected override AuthenticationHandler<OpenIddictValidationOwinOptions> CreateHandler()
=> new OpenIddictValidationOwinHandler(_logger, _provider);
}
}