/*
* 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 OpenIddict.Validation.AspNetCore;
namespace Microsoft.Extensions.DependencyInjection;
///
/// Exposes the necessary methods required to configure
/// the OpenIddict validation ASP.NET Core integration.
///
public sealed class OpenIddictValidationAspNetCoreBuilder
{
///
/// Initializes a new instance of .
///
/// The services collection.
public OpenIddictValidationAspNetCoreBuilder(IServiceCollection services)
=> Services = services ?? throw new ArgumentNullException(nameof(services));
///
/// Gets the services collection.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public IServiceCollection Services { get; }
///
/// Amends the default OpenIddict validation ASP.NET Core configuration.
///
/// The delegate used to configure the OpenIddict options.
/// This extension can be safely called multiple times.
/// The instance.
public OpenIddictValidationAspNetCoreBuilder Configure(Action configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
Services.Configure(configuration);
return this;
}
///
/// Sets the realm returned to the caller as part of the WWW-Authenticate header.
///
/// The realm.
/// The instance.
public OpenIddictValidationAspNetCoreBuilder SetRealm(string realm)
{
if (string.IsNullOrEmpty(realm))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0107), nameof(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();
}