From 05909309ca66c9914a8e6a7668cb423c204290fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Wed, 21 Feb 2024 15:23:46 +0100 Subject: [PATCH] Use List instead of Enumerable.Any() in the samples --- .../Balosar.Server/Controllers/AuthorizationController.cs | 8 ++++---- .../Controllers/AuthorizationController.cs | 8 ++++---- samples/Fornax/Fornax.Server/Connect/Authorize.aspx.cs | 8 ++++---- .../Mortis.Server/Controllers/AuthorizationController.cs | 8 ++++---- .../Velusia.Server/Controllers/AuthorizationController.cs | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/samples/Balosar/Balosar.Server/Controllers/AuthorizationController.cs b/samples/Balosar/Balosar.Server/Controllers/AuthorizationController.cs index 29e0e378..366da13b 100644 --- a/samples/Balosar/Balosar.Server/Controllers/AuthorizationController.cs +++ b/samples/Balosar/Balosar.Server/Controllers/AuthorizationController.cs @@ -116,7 +116,7 @@ public async Task Authorize() { // 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 @@ -129,8 +129,8 @@ public async Task Authorize() // 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, @@ -213,7 +213,7 @@ public async Task Accept() // 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, diff --git a/samples/Dantooine/Dantooine.Server/Controllers/AuthorizationController.cs b/samples/Dantooine/Dantooine.Server/Controllers/AuthorizationController.cs index 1f861311..dc9fe7a8 100644 --- a/samples/Dantooine/Dantooine.Server/Controllers/AuthorizationController.cs +++ b/samples/Dantooine/Dantooine.Server/Controllers/AuthorizationController.cs @@ -116,7 +116,7 @@ public async Task Authorize() { // 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 @@ -129,8 +129,8 @@ public async Task Authorize() // 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, @@ -213,7 +213,7 @@ public async Task Accept() // 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, diff --git a/samples/Fornax/Fornax.Server/Connect/Authorize.aspx.cs b/samples/Fornax/Fornax.Server/Connect/Authorize.aspx.cs index 17df67cf..599df18e 100644 --- a/samples/Fornax/Fornax.Server/Connect/Authorize.aspx.cs +++ b/samples/Fornax/Fornax.Server/Connect/Authorize.aspx.cs @@ -63,7 +63,7 @@ protected void Page_Load(object sender, EventArgs e) => RegisterAsyncTask(new Pa { // 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 @@ -78,8 +78,8 @@ protected void Page_Load(object sender, EventArgs e) => RegisterAsyncTask(new Pa // 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, @@ -191,7 +191,7 @@ protected void Accept(object sender, EventArgs e) => RegisterAsyncTask(new PageA // 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, diff --git a/samples/Mortis/Mortis.Server/Controllers/AuthorizationController.cs b/samples/Mortis/Mortis.Server/Controllers/AuthorizationController.cs index 103eac5e..714d4790 100644 --- a/samples/Mortis/Mortis.Server/Controllers/AuthorizationController.cs +++ b/samples/Mortis/Mortis.Server/Controllers/AuthorizationController.cs @@ -80,7 +80,7 @@ public async Task Authorize() { // 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 @@ -95,8 +95,8 @@ public async Task Authorize() // 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, @@ -202,7 +202,7 @@ public async Task Accept() // 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, diff --git a/samples/Velusia/Velusia.Server/Controllers/AuthorizationController.cs b/samples/Velusia/Velusia.Server/Controllers/AuthorizationController.cs index 4cf6628f..fcf1b55d 100644 --- a/samples/Velusia/Velusia.Server/Controllers/AuthorizationController.cs +++ b/samples/Velusia/Velusia.Server/Controllers/AuthorizationController.cs @@ -116,7 +116,7 @@ public async Task Authorize() { // 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 @@ -129,8 +129,8 @@ public async Task Authorize() // 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, @@ -213,7 +213,7 @@ public async Task Accept() // 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,