diff --git a/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs b/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs index 9d8c3f8b..fbf50dda 100644 --- a/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs +++ b/sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs @@ -44,7 +44,7 @@ public class InteractiveService : BackgroundService // Resolve the server configuration and determine the type of flow // to use depending on the supported grants and the user selection. - var configuration = await _service.GetServerConfigurationAsync(provider, stoppingToken); + var configuration = await _service.GetServerConfigurationByProviderNameAsync(provider, stoppingToken); if (configuration.GrantTypesSupported.Contains(GrantTypes.DeviceCode) && configuration.DeviceAuthorizationEndpoint is not null && await UseDeviceAuthorizationGrantAsync(stoppingToken)) diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.cs index faef0475..588f5c80 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.cs @@ -392,11 +392,11 @@ public static partial class OpenIddictClientHandlers => await _service.GetClientRegistrationByIdAsync(identifier, context.CancellationToken), // If specified, resolve the registration using the attached issuer URI. - { Issuer: Uri issuer } => await _service.GetClientRegistrationAsync(issuer, context.CancellationToken), + { Issuer: Uri uri } => await _service.GetClientRegistrationByIssuerAsync(uri, context.CancellationToken), // If specified, resolve the registration using the attached provider name. - { ProviderName: string provider } when !string.IsNullOrEmpty(provider) - => await _service.GetClientRegistrationAsync(provider, context.CancellationToken), + { ProviderName: string name } when !string.IsNullOrEmpty(name) + => await _service.GetClientRegistrationByProviderNameAsync(name, context.CancellationToken), // Otherwise, default to the unique registration available, if possible. { Options.Registrations: [OpenIddictClientRegistration registration] } => registration, @@ -4195,11 +4195,11 @@ public static partial class OpenIddictClientHandlers => await _service.GetClientRegistrationByIdAsync(identifier, context.CancellationToken), // If specified, resolve the registration using the attached issuer URI. - { Issuer: Uri issuer } => await _service.GetClientRegistrationAsync(issuer, context.CancellationToken), + { Issuer: Uri uri } => await _service.GetClientRegistrationByIssuerAsync(uri, context.CancellationToken), // If specified, resolve the registration using the attached provider name. - { ProviderName: string provider } when !string.IsNullOrEmpty(provider) - => await _service.GetClientRegistrationAsync(provider, context.CancellationToken), + { ProviderName: string name } when !string.IsNullOrEmpty(name) + => await _service.GetClientRegistrationByProviderNameAsync(name, context.CancellationToken), // Otherwise, default to the unique registration available, if possible. { Options.Registrations: [OpenIddictClientRegistration registration] } => registration, @@ -5846,11 +5846,11 @@ public static partial class OpenIddictClientHandlers => await _service.GetClientRegistrationByIdAsync(identifier, context.CancellationToken), // If specified, resolve the registration using the attached issuer URI. - { Issuer: Uri issuer } => await _service.GetClientRegistrationAsync(issuer, context.CancellationToken), + { Issuer: Uri uri } => await _service.GetClientRegistrationByIssuerAsync(uri, context.CancellationToken), // If specified, resolve the registration using the attached provider name. - { ProviderName: string provider } when !string.IsNullOrEmpty(provider) - => await _service.GetClientRegistrationAsync(provider, context.CancellationToken), + { ProviderName: string name } when !string.IsNullOrEmpty(name) + => await _service.GetClientRegistrationByProviderNameAsync(name, context.CancellationToken), // Otherwise, default to the unique registration available, if possible. { Options.Registrations: [OpenIddictClientRegistration registration] } => registration, diff --git a/src/OpenIddict.Client/OpenIddictClientService.cs b/src/OpenIddict.Client/OpenIddictClientService.cs index 04955632..27112616 100644 --- a/src/OpenIddict.Client/OpenIddictClientService.cs +++ b/src/OpenIddict.Client/OpenIddictClientService.cs @@ -16,7 +16,10 @@ using static OpenIddict.Client.OpenIddictClientModels; namespace OpenIddict.Client; -public sealed class OpenIddictClientService +/// +/// Provides high-level APIs for performing various authentication operations. +/// +public class OpenIddictClientService { private readonly IServiceProvider _provider; @@ -28,24 +31,24 @@ public sealed class OpenIddictClientService => _provider = provider ?? throw new ArgumentNullException(nameof(provider)); /// - /// Resolves the client registration associated with the specified . + /// Resolves the client registration associated with the specified issuer . /// - /// The issuer. + /// The issuer. /// The that can be used to abort the operation. - /// The associated with the specified . - /// is . + /// The associated with the specified issuer . + /// is . /// - /// No was registered with the specified . + /// No was registered with the specified issuer . /// /// - /// Multiple instances share the same . + /// Multiple instances share the same issuer . /// - public ValueTask GetClientRegistrationAsync( - Uri issuer, CancellationToken cancellationToken = default) + public virtual ValueTask GetClientRegistrationByIssuerAsync( + Uri uri, CancellationToken cancellationToken = default) { - if (issuer is null) + if (uri is null) { - throw new ArgumentNullException(nameof(issuer)); + throw new ArgumentNullException(nameof(uri)); } if (cancellationToken.IsCancellationRequested) @@ -55,7 +58,7 @@ public sealed class OpenIddictClientService var options = _provider.GetRequiredService>(); - return options.CurrentValue.Registrations.FindAll(registration => registration.Issuer == issuer) switch + return options.CurrentValue.Registrations.FindAll(registration => registration.Issuer == uri) switch { [var registration] => new(registration), @@ -68,21 +71,24 @@ public sealed class OpenIddictClientService } /// - /// Resolves the client registration associated with the specified . + /// Resolves the client registration associated with the specified provider . /// - /// The provider name. + /// The provider name. /// The that can be used to abort the operation. - /// The associated with the specified . - /// is . + /// The associated with the specified provider . + /// is . + /// + /// No was registered with the specified provider . + /// /// - /// No was registered with the specified . + /// Multiple instances share the same provider . /// - public ValueTask GetClientRegistrationAsync( - string provider, CancellationToken cancellationToken = default) + public virtual ValueTask GetClientRegistrationByProviderNameAsync( + string name, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(provider)) + if (string.IsNullOrEmpty(name)) { - throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider)); + throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name)); } if (cancellationToken.IsCancellationRequested) @@ -93,7 +99,7 @@ public sealed class OpenIddictClientService var options = _provider.GetRequiredService>(); return options.CurrentValue.Registrations.FindAll(registration => string.Equals( - registration.ProviderName, provider, StringComparison.Ordinal)) switch + registration.ProviderName, name, StringComparison.Ordinal)) switch { [var registration] => new(registration), @@ -115,7 +121,7 @@ public sealed class OpenIddictClientService /// /// No was registered with the specified . /// - public ValueTask GetClientRegistrationByIdAsync( + public virtual ValueTask GetClientRegistrationByIdAsync( string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) @@ -136,24 +142,27 @@ public sealed class OpenIddictClientService } /// - /// Resolves the server configuration associated with the specified . + /// Resolves the server configuration associated with the specified issuer . /// - /// The issuer. + /// The issuer. /// The that can be used to abort the operation. - /// The associated with the specified . - /// is . + /// The associated with the specified issuer . + /// is . /// - /// No was registered with the specified . + /// No was registered with the specified issuer . /// - public async ValueTask GetServerConfigurationAsync( - Uri issuer, CancellationToken cancellationToken = default) + /// + /// Multiple instances share the same issuer . + /// + public virtual async ValueTask GetServerConfigurationByIssuerAsync( + Uri uri, CancellationToken cancellationToken = default) { - if (issuer is null) + if (uri is null) { - throw new ArgumentNullException(nameof(issuer)); + throw new ArgumentNullException(nameof(uri)); } - var registration = await GetClientRegistrationAsync(issuer, cancellationToken); + var registration = await GetClientRegistrationByIssuerAsync(uri, cancellationToken); if (registration.ConfigurationManager is null) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0422)); @@ -166,27 +175,27 @@ public sealed class OpenIddictClientService } /// - /// Resolves the server configuration associated with the specified . + /// Resolves the server configuration associated with the specified provider . /// - /// The provider name. + /// The provider name. /// The that can be used to abort the operation. - /// The associated with the specified . - /// is . + /// The associated with the specified provider . + /// is . /// - /// No was registered with the specified . + /// No was registered with the specified provider . /// /// - /// Multiple instances share the same . + /// Multiple instances share the same provider . /// - public async ValueTask GetServerConfigurationAsync( - string provider, CancellationToken cancellationToken = default) + public virtual async ValueTask GetServerConfigurationByProviderNameAsync( + string name, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(provider)) + if (string.IsNullOrEmpty(name)) { - throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider)); + throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name)); } - var registration = await GetClientRegistrationAsync(provider, cancellationToken); + var registration = await GetClientRegistrationByProviderNameAsync(name, cancellationToken); if (registration.ConfigurationManager is null) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0422)); @@ -208,7 +217,7 @@ public sealed class OpenIddictClientService /// /// No was registered with the specified . /// - public async ValueTask GetServerConfigurationByRegistrationIdAsync( + public virtual async ValueTask GetServerConfigurationByRegistrationIdAsync( string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) diff --git a/src/OpenIddict.Validation/OpenIddictValidationService.cs b/src/OpenIddict.Validation/OpenIddictValidationService.cs index 843950d9..8ddffeb6 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationService.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationService.cs @@ -15,7 +15,10 @@ using static OpenIddict.Abstractions.OpenIddictExceptions; namespace OpenIddict.Validation; -public sealed class OpenIddictValidationService +/// +/// Provides high-level APIs for performing various authentication operations. +/// +public class OpenIddictValidationService { private readonly IServiceProvider _provider;