Browse Source

Use List<T> instead of Enumerable.Any() in the samples

pull/1997/head
Kévin Chalet 2 years ago
parent
commit
a5d2d867ba
  1. 8
      sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthorizationController.cs
  2. 8
      sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/AuthorizationController.cs
  3. 2
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.cs
  4. 4
      src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.cs
  5. 2
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
  6. 12
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
  7. 14
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  8. 4
      src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
  9. 16
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs
  10. 2
      src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs
  11. 16
      src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs
  12. 18
      src/OpenIddict.Server/OpenIddictServerHandlers.cs
  13. 2
      src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.cs
  14. 2
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs
  15. 6
      src/OpenIddict.Validation/OpenIddictValidationHandlers.cs

8
sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthorizationController.cs

@ -123,7 +123,7 @@ namespace OpenIddict.Sandbox.AspNet.Server.Controllers
{
// If the consent is external (e.g when authorizations are granted by a sysadmin),
// immediately return an error if no authorization can be found in the database.
case ConsentTypes.External when !authorizations.Any():
case ConsentTypes.External when authorizations.Count is 0:
context.Authentication.Challenge(
authenticationTypes: OpenIddictServerOwinDefaults.AuthenticationType,
properties: new AuthenticationProperties(new Dictionary<string, string>
@ -138,8 +138,8 @@ namespace OpenIddict.Sandbox.AspNet.Server.Controllers
// If the consent is implicit or if an authorization was found,
// return an authorization response without displaying the consent form.
case ConsentTypes.Implicit:
case ConsentTypes.External when authorizations.Any():
case ConsentTypes.Explicit when authorizations.Any() && !request.HasPrompt(Prompts.Consent):
case ConsentTypes.External when authorizations.Count is not 0:
case ConsentTypes.Explicit when authorizations.Count is not 0 && !request.HasPrompt(Prompts.Consent):
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
var identity = new ClaimsIdentity(
authenticationType: OpenIddictServerOwinDefaults.AuthenticationType,
@ -245,7 +245,7 @@ namespace OpenIddict.Sandbox.AspNet.Server.Controllers
// Note: the same check is already made in the other action but is repeated
// here to ensure a malicious user can't abuse this POST-only endpoint and
// force it to return a valid response without the external authorization.
if (!authorizations.Any() && await _applicationManager.HasConsentTypeAsync(application, ConsentTypes.External))
if (authorizations.Count is 0 && await _applicationManager.HasConsentTypeAsync(application, ConsentTypes.External))
{
context.Authentication.Challenge(
authenticationTypes: OpenIddictServerOwinDefaults.AuthenticationType,

8
sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/AuthorizationController.cs

@ -159,7 +159,7 @@ public class AuthorizationController : Controller
{
// If the consent is external (e.g when authorizations are granted by a sysadmin),
// immediately return an error if no authorization can be found in the database.
case ConsentTypes.External when !authorizations.Any():
case ConsentTypes.External when authorizations.Count is 0:
return Forbid(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
properties: new AuthenticationProperties(new Dictionary<string, string>
@ -172,8 +172,8 @@ public class AuthorizationController : Controller
// If the consent is implicit or if an authorization was found,
// return an authorization response without displaying the consent form.
case ConsentTypes.Implicit:
case ConsentTypes.External when authorizations.Any():
case ConsentTypes.Explicit when authorizations.Any() && !request.HasPrompt(Prompts.Consent):
case ConsentTypes.External when authorizations.Count is not 0:
case ConsentTypes.Explicit when authorizations.Count is not 0 && !request.HasPrompt(Prompts.Consent):
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
var identity = new ClaimsIdentity(
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
@ -256,7 +256,7 @@ public class AuthorizationController : Controller
// Note: the same check is already made in the other action but is repeated
// here to ensure a malicious user can't abuse this POST-only endpoint and
// force it to return a valid response without the external authorization.
if (!authorizations.Any() && await _applicationManager.HasConsentTypeAsync(application, ConsentTypes.External))
if (authorizations.Count is 0 && await _applicationManager.HasConsentTypeAsync(application, ConsentTypes.External))
{
return Forbid(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,

2
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.cs

@ -13,5 +13,5 @@ namespace OpenIddict.Client.DataProtection;
public static partial class OpenIddictClientDataProtectionHandlers
{
public static ImmutableArray<OpenIddictClientHandlerDescriptor> DefaultHandlers { get; }
= [..Protection.DefaultHandlers];
= [.. Protection.DefaultHandlers];
}

4
src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.cs

@ -66,8 +66,8 @@ public static partial class OpenIddictClientOwinHandlers
AttachCacheControlHeader<ProcessErrorContext>.Descriptor,
ProcessLocalErrorResponse<ProcessErrorContext>.Descriptor,
..Authentication.DefaultHandlers,
..Session.DefaultHandlers
.. Authentication.DefaultHandlers,
.. Session.DefaultHandlers
];
/// <summary>

2
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs

@ -82,7 +82,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
*/
AbortAuthenticationDemand.Descriptor,
..Authentication.DefaultHandlers
.. Authentication.DefaultHandlers
];
/// <summary>

12
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs

@ -22,12 +22,12 @@ namespace OpenIddict.Client.SystemNetHttp;
public static partial class OpenIddictClientSystemNetHttpHandlers
{
public static ImmutableArray<OpenIddictClientHandlerDescriptor> DefaultHandlers { get; } = [
..Device.DefaultHandlers,
..Discovery.DefaultHandlers,
..Exchange.DefaultHandlers,
..Introspection.DefaultHandlers,
..Revocation.DefaultHandlers,
..Userinfo.DefaultHandlers
.. Device.DefaultHandlers,
.. Discovery.DefaultHandlers,
.. Exchange.DefaultHandlers,
.. Introspection.DefaultHandlers,
.. Revocation.DefaultHandlers,
.. Userinfo.DefaultHandlers
];
/// <summary>

14
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

@ -55,13 +55,13 @@ public static partial class OpenIddictClientWebIntegrationHandlers
AttachNonStandardRevocationClientAssertionClaims.Descriptor,
AttachRevocationRequestNonStandardClientCredentials.Descriptor,
..Authentication.DefaultHandlers,
..Device.DefaultHandlers,
..Discovery.DefaultHandlers,
..Exchange.DefaultHandlers,
..Protection.DefaultHandlers,
..Revocation.DefaultHandlers,
..Userinfo.DefaultHandlers
.. Authentication.DefaultHandlers,
.. Device.DefaultHandlers,
.. Discovery.DefaultHandlers,
.. Exchange.DefaultHandlers,
.. Protection.DefaultHandlers,
.. Revocation.DefaultHandlers,
.. Userinfo.DefaultHandlers
];
/// <summary>

4
src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs

@ -1025,9 +1025,9 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
await Store.SetDisplayNamesAsync(application, descriptor.DisplayNames.ToImmutableDictionary(), cancellationToken);
await Store.SetJsonWebKeySetAsync(application, descriptor.JsonWebKeySet, cancellationToken);
await Store.SetPermissionsAsync(application, descriptor.Permissions.ToImmutableArray(), cancellationToken);
await Store.SetPostLogoutRedirectUrisAsync(application, [..descriptor.PostLogoutRedirectUris.Select(uri => uri.OriginalString)], cancellationToken);
await Store.SetPostLogoutRedirectUrisAsync(application, [.. descriptor.PostLogoutRedirectUris.Select(uri => uri.OriginalString)], cancellationToken);
await Store.SetPropertiesAsync(application, descriptor.Properties.ToImmutableDictionary(), cancellationToken);
await Store.SetRedirectUrisAsync(application, [..descriptor.RedirectUris.Select(uri => uri.OriginalString)], cancellationToken);
await Store.SetRedirectUrisAsync(application, [.. descriptor.RedirectUris.Select(uri => uri.OriginalString)], cancellationToken);
await Store.SetRequirementsAsync(application, descriptor.Requirements.ToImmutableArray(), cancellationToken);
await Store.SetSettingsAsync(application, descriptor.Settings.ToImmutableDictionary(), cancellationToken);
}

16
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreHandlers.cs

@ -52,14 +52,14 @@ public static partial class OpenIddictServerAspNetCoreHandlers
*/
ResolveHostSignOutProperties.Descriptor,
..Authentication.DefaultHandlers,
..Device.DefaultHandlers,
..Discovery.DefaultHandlers,
..Exchange.DefaultHandlers,
..Introspection.DefaultHandlers,
..Revocation.DefaultHandlers,
..Session.DefaultHandlers,
..Userinfo.DefaultHandlers
.. Authentication.DefaultHandlers,
.. Device.DefaultHandlers,
.. Discovery.DefaultHandlers,
.. Exchange.DefaultHandlers,
.. Introspection.DefaultHandlers,
.. Revocation.DefaultHandlers,
.. Session.DefaultHandlers,
.. Userinfo.DefaultHandlers
];
/// <summary>

2
src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionHandlers.cs

@ -13,5 +13,5 @@ namespace OpenIddict.Server.DataProtection;
public static partial class OpenIddictServerDataProtectionHandlers
{
public static ImmutableArray<OpenIddictServerHandlerDescriptor> DefaultHandlers { get; }
= [..Protection.DefaultHandlers];
= [.. Protection.DefaultHandlers];
}

16
src/OpenIddict.Server.Owin/OpenIddictServerOwinHandlers.cs

@ -47,14 +47,14 @@ public static partial class OpenIddictServerOwinHandlers
*/
ResolveHostSignOutProperties.Descriptor,
..Authentication.DefaultHandlers,
..Device.DefaultHandlers,
..Discovery.DefaultHandlers,
..Exchange.DefaultHandlers,
..Introspection.DefaultHandlers,
..Revocation.DefaultHandlers,
..Session.DefaultHandlers,
..Userinfo.DefaultHandlers
.. Authentication.DefaultHandlers,
.. Device.DefaultHandlers,
.. Discovery.DefaultHandlers,
.. Exchange.DefaultHandlers,
.. Introspection.DefaultHandlers,
.. Revocation.DefaultHandlers,
.. Session.DefaultHandlers,
.. Userinfo.DefaultHandlers
];
/// <summary>

18
src/OpenIddict.Server/OpenIddictServerHandlers.cs

@ -107,15 +107,15 @@ public static partial class OpenIddictServerHandlers
AttachErrorParameters.Descriptor,
AttachCustomErrorParameters.Descriptor,
..Authentication.DefaultHandlers,
..Device.DefaultHandlers,
..Discovery.DefaultHandlers,
..Exchange.DefaultHandlers,
..Introspection.DefaultHandlers,
..Protection.DefaultHandlers,
..Revocation.DefaultHandlers,
..Session.DefaultHandlers,
..Userinfo.DefaultHandlers
.. Authentication.DefaultHandlers,
.. Device.DefaultHandlers,
.. Discovery.DefaultHandlers,
.. Exchange.DefaultHandlers,
.. Introspection.DefaultHandlers,
.. Protection.DefaultHandlers,
.. Revocation.DefaultHandlers,
.. Session.DefaultHandlers,
.. Userinfo.DefaultHandlers
];
/// <summary>

2
src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionHandlers.cs

@ -13,5 +13,5 @@ namespace OpenIddict.Validation.DataProtection;
public static partial class OpenIddictValidationDataProtectionHandlers
{
public static ImmutableArray<OpenIddictValidationHandlerDescriptor> DefaultHandlers { get; }
= [..Protection.DefaultHandlers];
= [.. Protection.DefaultHandlers];
}

2
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs

@ -22,7 +22,7 @@ namespace OpenIddict.Validation.SystemNetHttp;
public static partial class OpenIddictValidationSystemNetHttpHandlers
{
public static ImmutableArray<OpenIddictValidationHandlerDescriptor> DefaultHandlers { get; }
= [..Discovery.DefaultHandlers, ..Introspection.DefaultHandlers];
= [.. Discovery.DefaultHandlers, .. Introspection.DefaultHandlers];
/// <summary>
/// Contains the logic responsible for creating and attaching a <see cref="HttpClient"/>.

6
src/OpenIddict.Validation/OpenIddictValidationHandlers.cs

@ -49,9 +49,9 @@ public static partial class OpenIddictValidationHandlers
AttachErrorParameters.Descriptor,
AttachCustomErrorParameters.Descriptor,
..Discovery.DefaultHandlers,
..Introspection.DefaultHandlers,
..Protection.DefaultHandlers
.. Discovery.DefaultHandlers,
.. Introspection.DefaultHandlers,
.. Protection.DefaultHandlers
];
/// <summary>

Loading…
Cancel
Save