/* * 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.ComponentModel; using Microsoft.AspNetCore; using OpenIddict.Server.AspNetCore; namespace Microsoft.Extensions.DependencyInjection; /// /// Exposes the necessary methods required to configure /// the OpenIddict server ASP.NET Core integration. /// public sealed class OpenIddictServerAspNetCoreBuilder { /// /// Initializes a new instance of . /// /// The services collection. public OpenIddictServerAspNetCoreBuilder(IServiceCollection services) => Services = services ?? throw new ArgumentNullException(nameof(services)); /// /// Gets the services collection. /// [EditorBrowsable(EditorBrowsableState.Never)] public IServiceCollection Services { get; } /// /// Enables validation of options during application startup. /// /// The instance. public OpenIddictServerAspNetCoreBuilder ValidateOnStart() { Services.AddOptionsWithValidateOnStart(); return this; } /// /// Amends the default OpenIddict server ASP.NET Core configuration. /// /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The instance. public OpenIddictServerAspNetCoreBuilder Configure(Action configuration) { ArgumentNullException.ThrowIfNull(configuration); Services.Configure(configuration); return this; } /// /// Disables the transport security requirement (HTTPS). /// /// The instance. public OpenIddictServerAspNetCoreBuilder DisableTransportSecurityRequirement() => Configure(options => options.DisableTransportSecurityRequirement = true); /// /// Enables the pass-through mode for the OpenID Connect authorization endpoint. /// When the pass-through mode is used, OpenID Connect requests are initially handled by OpenIddict. /// Once validated, the rest of the request processing pipeline is invoked, so that OpenID Connect requests /// can be handled at a later stage (in a custom middleware or in a MVC controller, for instance). /// /// The instance. public OpenIddictServerAspNetCoreBuilder EnableAuthorizationEndpointPassthrough() => Configure(options => options.EnableAuthorizationEndpointPassthrough = true); /// /// Enables the pass-through mode for the OpenID Connect end session endpoint. /// When the pass-through mode is used, OpenID Connect requests are initially handled by OpenIddict. /// Once validated, the rest of the request processing pipeline is invoked, so that OpenID Connect requests /// can be handled at a later stage (in a custom middleware or in a MVC controller, for instance). /// /// The instance. public OpenIddictServerAspNetCoreBuilder EnableEndSessionEndpointPassthrough() => Configure(options => options.EnableEndSessionEndpointPassthrough = true); /// /// Enables the pass-through mode for the OpenID Connect end-user verification endpoint. /// When the pass-through mode is used, OpenID Connect requests are initially handled by OpenIddict. /// Once validated, the rest of the request processing pipeline is invoked, so that OpenID Connect requests /// can be handled at a later stage (in a custom middleware or in a MVC controller, for instance). /// /// The instance. public OpenIddictServerAspNetCoreBuilder EnableEndUserVerificationEndpointPassthrough() => Configure(options => options.EnableEndUserVerificationEndpointPassthrough = true); /// /// Enables error pass-through support, so that the rest of the request processing pipeline is /// automatically invoked when returning an error from the interactive authorization and end session endpoints. /// When this option is enabled, special logic must be added to these actions to handle errors, that can be /// retrieved using . /// /// /// Important: the error pass-through mode cannot be used when the status code pages integration is enabled. /// /// The instance. [EditorBrowsable(EditorBrowsableState.Advanced)] public OpenIddictServerAspNetCoreBuilder EnableErrorPassthrough() => Configure(options => options.EnableErrorPassthrough = true); /// /// Enables the pass-through mode for the OpenID Connect token endpoint. /// When the pass-through mode is used, OpenID Connect requests are initially handled by OpenIddict. /// Once validated, the rest of the request processing pipeline is invoked, so that OpenID Connect requests /// can be handled at a later stage (in a custom middleware or in a MVC controller, for instance). /// /// The instance. public OpenIddictServerAspNetCoreBuilder EnableTokenEndpointPassthrough() => Configure(options => options.EnableTokenEndpointPassthrough = true); /// /// Enables the pass-through mode for the OpenID Connect userinfo endpoint. /// When the pass-through mode is used, OpenID Connect requests are initially handled by OpenIddict. /// Once validated, the rest of the request processing pipeline is invoked, so that OpenID Connect requests /// can be handled at a later stage (in a custom middleware or in a MVC controller, for instance). /// /// The instance. public OpenIddictServerAspNetCoreBuilder EnableUserInfoEndpointPassthrough() => Configure(options => options.EnableUserInfoEndpointPassthrough = true); /// /// Enables status code pages integration support. Once enabled, errors /// generated by the interactive endpoints can be handled by ASP.NET Core. /// /// The instance. public OpenIddictServerAspNetCoreBuilder EnableStatusCodePagesIntegration() => Configure(options => options.EnableStatusCodePagesIntegration = true); /// /// Suppresses indentation for the JSON responses returned by the ASP.NET Core host. /// /// The instance. public OpenIddictServerAspNetCoreBuilder SuppressJsonResponseIndentation() => Configure(options => options.SuppressJsonResponseIndentation = true); /// /// Sets the realm returned to the caller as part of the WWW-Authenticate header. /// /// The realm. /// The instance. public OpenIddictServerAspNetCoreBuilder SetRealm(string realm) { ArgumentException.ThrowIfNullOrEmpty(realm); return Configure(options => options.Realm = realm); } /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => base.GetHashCode(); /// [EditorBrowsable(EditorBrowsableState.Never)] public override string? ToString() => base.ToString(); }