diff --git a/.editorconfig b/.editorconfig index e0220153..11a996a7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -105,12 +105,63 @@ dotnet_diagnostic.MA0003.severity = none dotnet_diagnostic.MA0004.severity = none dotnet_diagnostic.MA0007.severity = none dotnet_diagnostic.MA0016.severity = none +dotnet_diagnostic.MA0018.severity = none dotnet_diagnostic.MA0029.severity = none +dotnet_diagnostic.MA0036.severity = warning +dotnet_diagnostic.MA0043.severity = warning dotnet_diagnostic.MA0048.severity = none +dotnet_diagnostic.MA0050.severity = warning dotnet_diagnostic.MA0051.severity = none +dotnet_diagnostic.MA0052.severity = warning +dotnet_diagnostic.MA0053.severity = warning dotnet_diagnostic.MA0056.severity = none +dotnet_diagnostic.MA0057.severity = warning +dotnet_diagnostic.MA0058.severity = warning +dotnet_diagnostic.MA0059.severity = warning +dotnet_diagnostic.MA0067.severity = warning +dotnet_diagnostic.MA0071.severity = warning +dotnet_diagnostic.MA0073.severity = warning +dotnet_diagnostic.MA0075.severity = warning +dotnet_diagnostic.MA0076.severity = warning +dotnet_diagnostic.MA0079.severity = warning +dotnet_diagnostic.MA0080.severity = warning dotnet_diagnostic.MA0084.severity = none +dotnet_diagnostic.MA0089.severity = warning +dotnet_diagnostic.MA0090.severity = warning +dotnet_diagnostic.MA0098.severity = warning +dotnet_diagnostic.MA0098.severity = warning dotnet_diagnostic.MA0100.severity = none +dotnet_diagnostic.MA0102.severity = none +dotnet_diagnostic.MA0104.severity = warning +dotnet_diagnostic.MA0105.severity = warning +dotnet_diagnostic.MA0106.severity = warning +dotnet_diagnostic.MA0107.severity = warning +dotnet_diagnostic.MA0109.severity = none +dotnet_diagnostic.MA0111.severity = warning +dotnet_diagnostic.MA0113.severity = warning +dotnet_diagnostic.MA0114.severity = warning +dotnet_diagnostic.MA0121.severity = warning +dotnet_diagnostic.MA0128.severity = warning +dotnet_diagnostic.MA0133.severity = warning +dotnet_diagnostic.MA0140.severity = warning +dotnet_diagnostic.MA0141.severity = warning +dotnet_diagnostic.MA0142.severity = warning +dotnet_diagnostic.MA0148.severity = warning +dotnet_diagnostic.MA0149.severity = warning +dotnet_diagnostic.MA0152.severity = warning +dotnet_diagnostic.MA0156.severity = warning +dotnet_diagnostic.MA0161.severity = warning +dotnet_diagnostic.MA0162.severity = warning +dotnet_diagnostic.MA0167.severity = warning +dotnet_diagnostic.MA0168.severity = warning +dotnet_diagnostic.MA0170.severity = warning +dotnet_diagnostic.MA0171.severity = warning +dotnet_diagnostic.MA0172.severity = warning +dotnet_diagnostic.MA0174.severity = warning +dotnet_diagnostic.MA0186.severity = warning +dotnet_diagnostic.MA0187.severity = warning +dotnet_diagnostic.MA0209.severity = warning +dotnet_diagnostic.MA0210.severity = warning dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface diff --git a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs index 757d3fd6..4dd6ff28 100644 --- a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs +++ b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs @@ -741,7 +741,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/BundleConfig.cs b/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/BundleConfig.cs index 30b0acae..1bdd2177 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/BundleConfig.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/BundleConfig.cs @@ -2,7 +2,7 @@ namespace OpenIddict.Sandbox.AspNet.Client; -public class BundleConfig +public static class BundleConfig { // Pour plus d'informations sur le regroupement, visitez https://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/FilterConfig.cs b/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/FilterConfig.cs index e16ad29a..d9437fcd 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/FilterConfig.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/FilterConfig.cs @@ -2,7 +2,7 @@ namespace OpenIddict.Sandbox.AspNet.Client; -public class FilterConfig +public static class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/RouteConfig.cs b/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/RouteConfig.cs index f30c1a0c..957817cb 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/RouteConfig.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Client/App_Start/RouteConfig.cs @@ -3,7 +3,7 @@ using System.Web.Routing; namespace OpenIddict.Sandbox.AspNet.Client; -public class RouteConfig +public static class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/BundleConfig.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/BundleConfig.cs index dcdd299b..2ede228b 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/BundleConfig.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/BundleConfig.cs @@ -2,7 +2,7 @@ namespace OpenIddict.Sandbox.AspNet.Server; -public class BundleConfig +public static class BundleConfig { // Pour plus d'informations sur le regroupement, visitez https://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/FilterConfig.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/FilterConfig.cs index 71911d80..7732462f 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/FilterConfig.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/FilterConfig.cs @@ -2,7 +2,7 @@ namespace OpenIddict.Sandbox.AspNet.Server; -public class FilterConfig +public static class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/IdentityConfig.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/IdentityConfig.cs index c6c63b17..e2fbf2b2 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/IdentityConfig.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/IdentityConfig.cs @@ -66,7 +66,7 @@ public class ApplicationUserManager : UserManager manager.EmailService = new EmailService(); manager.SmsService = new SmsService(); var dataProtectionProvider = options.DataProtectionProvider; - if (dataProtectionProvider != null) + if (dataProtectionProvider is not null) { manager.UserTokenProvider = new DataProtectorTokenProvider(dataProtectionProvider.Create("ASP.NET Identity")); diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/RouteConfig.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/RouteConfig.cs index 2f3b3c11..15c1b9e9 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/RouteConfig.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/App_Start/RouteConfig.cs @@ -3,7 +3,7 @@ using System.Web.Routing; namespace OpenIddict.Sandbox.AspNet.Server; -public class RouteConfig +public static class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AccountController.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AccountController.cs index 3fb86880..219791b9 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AccountController.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AccountController.cs @@ -174,7 +174,7 @@ public class AccountController : Controller [AllowAnonymous] public async Task ConfirmEmail(string userId, string code) { - if (userId == null || code == null) + if (userId is null || code is null) { return View("Error"); } @@ -200,7 +200,7 @@ public class AccountController : Controller if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); - if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) + if (user is null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { // Ne révélez pas que l'utilisateur n'existe pas ou qu'il n'est pas confirmé return View("ForgotPasswordConfirmation"); @@ -231,7 +231,7 @@ public class AccountController : Controller [AllowAnonymous] public ActionResult ResetPassword(string code) { - return code == null ? View("Error") : View(); + return code is null ? View("Error") : View(); } // @@ -246,7 +246,7 @@ public class AccountController : Controller return View(model); } var user = await UserManager.FindByNameAsync(model.Email); - if (user == null) + if (user is null) { // Ne révélez pas que l'utilisateur n'existe pas return RedirectToAction("ResetPasswordConfirmation", "Account"); @@ -285,7 +285,7 @@ public class AccountController : Controller public async Task SendCode(string returnUrl, bool rememberMe) { var userId = await SignInManager.GetVerifiedUserIdAsync(); - if (userId == null) + if (userId is null) { return View("Error"); } @@ -320,7 +320,7 @@ public class AccountController : Controller public async Task ExternalLoginCallback(string returnUrl) { var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); - if (loginInfo == null) + if (loginInfo is null) { return RedirectToAction("Login"); } @@ -360,7 +360,7 @@ public class AccountController : Controller { // Obtenir des informations sur l'utilisateur à partir du fournisseur de connexion externe var info = await AuthenticationManager.GetExternalLoginInfoAsync(); - if (info == null) + if (info is null) { return View("ExternalLoginFailure"); } @@ -404,13 +404,13 @@ public class AccountController : Controller { if (disposing) { - if (_userManager != null) + if (_userManager is not null) { _userManager.Dispose(); _userManager = null; } - if (_signInManager != null) + if (_signInManager is not null) { _signInManager.Dispose(); _signInManager = null; @@ -449,7 +449,7 @@ public class AccountController : Controller return RedirectToAction("Index", "Home"); } - internal class ChallengeResult : HttpUnauthorizedResult + internal sealed class ChallengeResult : HttpUnauthorizedResult { public ChallengeResult(string provider, string redirectUri) : this(provider, redirectUri, null) @@ -470,7 +470,7 @@ public class AccountController : Controller public override void ExecuteResult(ControllerContext context) { var properties = new AuthenticationProperties { RedirectUri = RedirectUri }; - if (UserId != null) + if (UserId is not null) { properties.Dictionary[XsrfKey] = UserId; } diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthorizationController.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthorizationController.cs index 20be17f6..f66b2a49 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthorizationController.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/AuthorizationController.cs @@ -421,7 +421,7 @@ public class AuthorizationController : Controller // Retrieve the user profile corresponding to the authorization code/refresh token. var user = await context.GetUserManager().FindByIdAsync(result.Identity.GetClaim(Claims.Subject)); - if (user == null) + if (user is null) { context.Authentication.Challenge( authenticationTypes: OpenIddictServerOwinDefaults.AuthenticationType, diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/ManageController.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/ManageController.cs index e442c27d..b76f320c 100644 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/ManageController.cs +++ b/sandbox/OpenIddict.Sandbox.AspNet.Server/Controllers/ManageController.cs @@ -54,12 +54,12 @@ public class ManageController : Controller public async Task Index(ManageMessageId? message) { ViewBag.StatusMessage = - message == ManageMessageId.ChangePasswordSuccess ? "Votre mot de passe a été changé." - : message == ManageMessageId.SetPasswordSuccess ? "Votre mot de passe a été défini." - : message == ManageMessageId.SetTwoFactorSuccess ? "Votre fournisseur d'authentification à 2 facteurs a été défini." - : message == ManageMessageId.Error ? "Une erreur s'est produite." - : message == ManageMessageId.AddPhoneSuccess ? "Votre numéro de téléphone a été ajouté." - : message == ManageMessageId.RemovePhoneSuccess ? "Votre numéro de téléphone a été supprimé." + message is ManageMessageId.ChangePasswordSuccess ? "Votre mot de passe a été changé." + : message is ManageMessageId.SetPasswordSuccess ? "Votre mot de passe a été défini." + : message is ManageMessageId.SetTwoFactorSuccess ? "Votre fournisseur d'authentification à 2 facteurs a été défini." + : message is ManageMessageId.Error ? "Une erreur s'est produite." + : message is ManageMessageId.AddPhoneSuccess ? "Votre numéro de téléphone a été ajouté." + : message is ManageMessageId.RemovePhoneSuccess ? "Votre numéro de téléphone a été supprimé." : ""; var userId = User.Identity.GetUserId(); @@ -85,7 +85,7 @@ public class ManageController : Controller if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } @@ -117,7 +117,7 @@ public class ManageController : Controller } // Générer le jeton et l'envoyer var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number); - if (UserManager.SmsService != null) + if (UserManager.SmsService is not null) { var message = new IdentityMessage { @@ -137,7 +137,7 @@ public class ManageController : Controller { await UserManager.SetTwoFactorEnabledAsync(User.Identity.GetUserId(), true); var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } @@ -152,7 +152,7 @@ public class ManageController : Controller { await UserManager.SetTwoFactorEnabledAsync(User.Identity.GetUserId(), false); var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } @@ -165,7 +165,7 @@ public class ManageController : Controller { var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), phoneNumber); // Envoyer un SMS via le fournisseur SMS afin de vérifier le numéro de téléphone - return phoneNumber == null ? View("Error") : View(new VerifyPhoneNumberViewModel { PhoneNumber = phoneNumber }); + return phoneNumber is null ? View("Error") : View(new VerifyPhoneNumberViewModel { PhoneNumber = phoneNumber }); } // @@ -182,7 +182,7 @@ public class ManageController : Controller if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } @@ -205,7 +205,7 @@ public class ManageController : Controller return RedirectToAction("Index", new { Message = ManageMessageId.Error }); } var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } @@ -233,7 +233,7 @@ public class ManageController : Controller if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } @@ -262,7 +262,7 @@ public class ManageController : Controller if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } @@ -280,17 +280,17 @@ public class ManageController : Controller public async Task ManageLogins(ManageMessageId? message) { ViewBag.StatusMessage = - message == ManageMessageId.RemoveLoginSuccess ? "La connexion externe a été supprimée." - : message == ManageMessageId.Error ? "Une erreur s'est produite." + message is ManageMessageId.RemoveLoginSuccess ? "La connexion externe a été supprimée." + : message is ManageMessageId.Error ? "Une erreur s'est produite." : ""; var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); - if (user == null) + if (user is null) { return View("Error"); } var userLogins = await UserManager.GetLoginsAsync(User.Identity.GetUserId()); var otherLogins = AuthenticationManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => !string.Equals(auth.AuthenticationType, ul.LoginProvider, System.StringComparison.Ordinal))).ToList(); - ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1; + ViewBag.ShowRemoveButton = user.PasswordHash is not null || userLogins.Count > 1; return View(new ManageLoginsViewModel { CurrentLogins = userLogins, @@ -313,7 +313,7 @@ public class ManageController : Controller public async Task LinkLoginCallback() { var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, User.Identity.GetUserId()); - if (loginInfo == null) + if (loginInfo is null) { return RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }); } @@ -323,7 +323,7 @@ public class ManageController : Controller protected override void Dispose(bool disposing) { - if (disposing && _userManager != null) + if (disposing && _userManager is not null) { _userManager.Dispose(); _userManager = null; @@ -355,9 +355,9 @@ public class ManageController : Controller private bool HasPassword() { var user = UserManager.FindById(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { - return user.PasswordHash != null; + return user.PasswordHash is not null; } return false; } @@ -365,9 +365,9 @@ public class ManageController : Controller private bool HasPhoneNumber() { var user = UserManager.FindById(User.Identity.GetUserId()); - if (user != null) + if (user is not null) { - return user.PhoneNumber != null; + return user.PhoneNumber is not null; } return false; } diff --git a/sandbox/OpenIddict.Sandbox.AspNet.Server/Helpers/AsyncEnumerableExtensions.cs b/sandbox/OpenIddict.Sandbox.AspNet.Server/Helpers/AsyncEnumerableExtensions.cs deleted file mode 100644 index 385d9034..00000000 --- a/sandbox/OpenIddict.Sandbox.AspNet.Server/Helpers/AsyncEnumerableExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace OpenIddict.Sandbox.AspNet.Server.Helpers; - -public static class AsyncEnumerableExtensions -{ - public static Task> ToListAsync(this IAsyncEnumerable source) - { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - - return ExecuteAsync(); - - async Task> ExecuteAsync() - { - var list = new List(); - - await foreach (var element in source) - { - list.Add(element); - } - - return list; - } - } -} diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Program.cs b/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Program.cs index 4b52c395..21e31a7f 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Program.cs +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Program.cs @@ -13,7 +13,7 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext(options => { - options.UseSqlite($"Filename={Path.Combine(Path.GetTempPath(), "openiddict-sandbox-aspnetcore-client.sqlite3")}"); + options.UseSqlite($"Filename={Path.Join(Path.GetTempPath(), "openiddict-sandbox-aspnetcore-client.sqlite3")}"); // Developers who prefer using Microsoft SQL Server instead of SQLite can remove // the previous line and configure OpenIddict to use the specified database: diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ManageController.cs b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ManageController.cs index 13771b63..09d4f1cd 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ManageController.cs +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ManageController.cs @@ -38,12 +38,12 @@ public class ManageController : Controller public async Task Index(ManageMessageId? message = null) { ViewData["StatusMessage"] = - message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." - : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." - : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set." - : message == ManageMessageId.Error ? "An error has occurred." - : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added." - : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed." + message is ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." + : message is ManageMessageId.SetPasswordSuccess ? "Your password has been set." + : message is ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set." + : message is ManageMessageId.Error ? "An error has occurred." + : message is ManageMessageId.AddPhoneSuccess ? "Your phone number was added." + : message is ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed." : ""; var user = await GetCurrentUserAsync(); @@ -261,9 +261,9 @@ public class ManageController : Controller public async Task ManageLogins(ManageMessageId? message = null) { ViewData["StatusMessage"] = - message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed." - : message == ManageMessageId.AddLoginSuccess ? "The external login was added." - : message == ManageMessageId.Error ? "An error has occurred." + message is ManageMessageId.RemoveLoginSuccess ? "The external login was removed." + : message is ManageMessageId.AddLoginSuccess ? "The external login was added." + : message is ManageMessageId.Error ? "An error has occurred." : ""; var user = await GetCurrentUserAsync(); if (user is null) diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Program.cs b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Program.cs index 80e5f2cf..869066cc 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Program.cs +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Program.cs @@ -19,7 +19,7 @@ builder.Services.AddMvc(); builder.Services.AddDbContext(options => { - options.UseSqlite($"Filename={Path.Combine(Path.GetTempPath(), "openiddict-sandbox-aspnetcore-server.sqlite3")}"); + options.UseSqlite($"Filename={Path.Join(Path.GetTempPath(), "openiddict-sandbox-aspnetcore-server.sqlite3")}"); // Developers who prefer using Microsoft SQL Server instead of SQLite can remove // the previous line and configure OpenIddict to use the specified database: diff --git a/sandbox/OpenIddict.Sandbox.Console.Client/Models/ApplicationDbContext.cs b/sandbox/OpenIddict.Sandbox.Console.Client/Models/ApplicationDbContext.cs index 04d0d8c1..7c7d4b0f 100644 --- a/sandbox/OpenIddict.Sandbox.Console.Client/Models/ApplicationDbContext.cs +++ b/sandbox/OpenIddict.Sandbox.Console.Client/Models/ApplicationDbContext.cs @@ -24,7 +24,7 @@ public class ApplicationDbContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite($"Filename={Path.Combine(Path.GetTempPath(), "openiddict-sandbox-console-client.sqlite3")}"); + optionsBuilder.UseSqlite($"Filename={Path.Join(Path.GetTempPath(), "openiddict-sandbox-console-client.sqlite3")}"); } #else public ApplicationDbContext() diff --git a/sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs b/sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs index b160b43a..0fa1c993 100644 --- a/sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs +++ b/sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs @@ -19,7 +19,7 @@ public static class MauiProgram builder.Services.AddDbContext(options => { - options.UseSqlite($"Filename={Path.Combine(Path.GetTempPath(), "openiddict-sandbox-maui-client.sqlite3")}"); + options.UseSqlite($"Filename={Path.Join(Path.GetTempPath(), "openiddict-sandbox-maui-client.sqlite3")}"); options.UseOpenIddict(); }); diff --git a/sandbox/OpenIddict.Sandbox.WinForms.Client/Models/ApplicationDbContext.cs b/sandbox/OpenIddict.Sandbox.WinForms.Client/Models/ApplicationDbContext.cs index e7c6840e..58858e1c 100644 --- a/sandbox/OpenIddict.Sandbox.WinForms.Client/Models/ApplicationDbContext.cs +++ b/sandbox/OpenIddict.Sandbox.WinForms.Client/Models/ApplicationDbContext.cs @@ -24,7 +24,7 @@ public class ApplicationDbContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite($"Filename={Path.Combine(Path.GetTempPath(), "openiddict-sandbox-winforms-client.sqlite3")}"); + optionsBuilder.UseSqlite($"Filename={Path.Join(Path.GetTempPath(), "openiddict-sandbox-winforms-client.sqlite3")}"); } #else public ApplicationDbContext() diff --git a/sandbox/OpenIddict.Sandbox.Wpf.Client/Models/ApplicationDbContext.cs b/sandbox/OpenIddict.Sandbox.Wpf.Client/Models/ApplicationDbContext.cs index e4964e78..779e1f60 100644 --- a/sandbox/OpenIddict.Sandbox.Wpf.Client/Models/ApplicationDbContext.cs +++ b/sandbox/OpenIddict.Sandbox.Wpf.Client/Models/ApplicationDbContext.cs @@ -25,7 +25,7 @@ public class ApplicationDbContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite($"Filename={Path.Combine(Path.GetTempPath(), "openiddict-sandbox-wpf-client.sqlite3")}"); + optionsBuilder.UseSqlite($"Filename={Path.Join(Path.GetTempPath(), "openiddict-sandbox-wpf-client.sqlite3")}"); } #else public ApplicationDbContext() diff --git a/shared/OpenIddict.Extensions/OpenIddictHelpers.cs b/shared/OpenIddict.Extensions/OpenIddictHelpers.cs index 9bacb851..f645056a 100644 --- a/shared/OpenIddict.Extensions/OpenIddictHelpers.cs +++ b/shared/OpenIddict.Extensions/OpenIddictHelpers.cs @@ -557,7 +557,7 @@ internal static class OpenIddictHelpers /// /// Note: this implementation was taken from ASP.NET Core. /// - private class FormReader + private sealed class FormReader { public const int DefaultValueCountLimit = 1024; public const int DefaultKeyLengthLimit = 1024 * 2; @@ -598,7 +598,7 @@ internal static class OpenIddictHelpers while (!_endOfStream) { // Empty - if (_bufferCount == 0) + if (_bufferCount is 0) { Buffer(); } @@ -611,7 +611,7 @@ internal static class OpenIddictHelpers public async Task?> ReadNextPairAsync(CancellationToken cancellationToken = new CancellationToken()) { - await ReadNextPairAsyncImpl(cancellationToken); + await ReadNextPairAsyncImplAsync(cancellationToken); if (ReadSucceeded()) { return KeyValuePair.Create(_currentKey, _currentValue); @@ -619,12 +619,12 @@ internal static class OpenIddictHelpers return null; } - private async Task ReadNextPairAsyncImpl(CancellationToken cancellationToken = new CancellationToken()) + private async Task ReadNextPairAsyncImplAsync(CancellationToken cancellationToken = new CancellationToken()) { StartReadNextPair(); while (!_endOfStream) { - if (_bufferCount == 0) + if (_bufferCount is 0) { await BufferAsync(cancellationToken); } @@ -643,20 +643,20 @@ internal static class OpenIddictHelpers private bool TryReadNextPair() { - if (_currentKey == null) + if (_currentKey is null) { if (!TryReadWord('=', KeyLengthLimit, out _currentKey)) { return false; } - if (_bufferCount == 0) + if (_bufferCount is 0) { return false; } } - if (_currentValue == null) + if (_currentValue is null) { if (!TryReadWord('&', ValueLengthLimit, out _currentValue)) { @@ -680,7 +680,7 @@ internal static class OpenIddictHelpers private bool ReadChar(char separator, int limit, [NotNullWhen(true)] out string? word) { - if (_bufferCount == 0) + if (_bufferCount is 0) { word = BuildWord(); return true; @@ -696,7 +696,8 @@ internal static class OpenIddictHelpers } if (_builder.Length >= limit) { - throw new InvalidDataException($"Form key or value length limit {limit} exceeded."); + throw new InvalidDataException(string.Create(CultureInfo.InvariantCulture, + $"Form key or value length limit {limit} exceeded.")); } _builder.Append(c); word = null; @@ -715,7 +716,7 @@ internal static class OpenIddictHelpers { _bufferOffset = 0; _bufferCount = _reader.Read(_buffer, 0, _buffer.Length); - _endOfStream = _bufferCount == 0; + _endOfStream = _bufferCount is 0; } private async Task BufferAsync(CancellationToken cancellationToken) @@ -723,7 +724,7 @@ internal static class OpenIddictHelpers cancellationToken.ThrowIfCancellationRequested(); _bufferOffset = 0; _bufferCount = await _reader.ReadAsync(_buffer, 0, _buffer.Length); - _endOfStream = _bufferCount == 0; + _endOfStream = _bufferCount is 0; } public Dictionary ReadForm() @@ -742,7 +743,7 @@ internal static class OpenIddictHelpers var accumulator = new KeyValueAccumulator(); while (!_endOfStream) { - await ReadNextPairAsyncImpl(cancellationToken); + await ReadNextPairAsyncImplAsync(cancellationToken); Append(ref accumulator); } return accumulator.GetResults(); @@ -751,7 +752,7 @@ internal static class OpenIddictHelpers [MemberNotNullWhen(true, nameof(_currentKey), nameof(_currentValue))] private bool ReadSucceeded() { - return _currentKey != null && _currentValue != null; + return _currentKey is not null && _currentValue is not null; } private void Append(ref KeyValueAccumulator accumulator) @@ -761,7 +762,8 @@ internal static class OpenIddictHelpers accumulator.Append(_currentKey, _currentValue); if (accumulator.ValueCount > ValueCountLimit) { - throw new InvalidDataException($"Form value count limit {ValueCountLimit} exceeded."); + throw new InvalidDataException(string.Create(CultureInfo.InvariantCulture, + $"Form value count limit {ValueCountLimit} exceeded.")); } } } @@ -777,7 +779,7 @@ internal static class OpenIddictHelpers public void Append(string key, string value) { - if (_accumulator == null) + if (_accumulator is null) { _accumulator = new Dictionary(StringComparer.OrdinalIgnoreCase); } @@ -785,11 +787,11 @@ internal static class OpenIddictHelpers StringValues values; if (_accumulator.TryGetValue(key, out values)) { - if (values.Count == 0) + if (values.Count is 0) { _expandingAccumulator[key].Add(value); } - else if (values.Count == 1) + else if (values.Count is 1) { _accumulator[key] = new string[] { values[0]!, value }; } @@ -797,7 +799,7 @@ internal static class OpenIddictHelpers { _accumulator[key] = default(StringValues); - if (_expandingAccumulator == null) + if (_expandingAccumulator is null) { _expandingAccumulator = new Dictionary>(StringComparer.OrdinalIgnoreCase); } @@ -826,7 +828,7 @@ internal static class OpenIddictHelpers public Dictionary GetResults() { - if (_expandingAccumulator != null) + if (_expandingAccumulator is not null) { foreach (var entry in _expandingAccumulator) { diff --git a/src/OpenIddict.Abstractions/OpenIddictBuilder.cs b/src/OpenIddict.Abstractions/OpenIddictBuilder.cs index 09df8777..1f213151 100644 --- a/src/OpenIddict.Abstractions/OpenIddictBuilder.cs +++ b/src/OpenIddict.Abstractions/OpenIddictBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.Extensions.DependencyInjection; @@ -28,7 +29,7 @@ public sealed class OpenIddictBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs index fa528998..0d0ae2bc 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs @@ -6,6 +6,7 @@ using System.Collections.Immutable; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -290,7 +291,8 @@ public readonly struct OpenIddictParameter : IEquatable /// if the two instances have both the same representation /// (e.g ) and value, otherwise. /// - public override bool Equals(object? obj) => obj is OpenIddictParameter parameter && Equals(parameter); + public override bool Equals([NotNullWhen(true)] object? obj) + => obj is OpenIddictParameter parameter && Equals(parameter); /// /// Returns the hash code of the current instance. @@ -615,7 +617,7 @@ public readonly struct OpenIddictParameter : IEquatable }; value = result.GetValueOrDefault(); - return result.HasValue; + return result is not null; } /// @@ -651,7 +653,7 @@ public readonly struct OpenIddictParameter : IEquatable }; value = result.GetValueOrDefault(); - return result.HasValue; + return result is not null; } /// diff --git a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs index 26fe2286..84e87225 100644 --- a/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs +++ b/src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore; using OpenIddict.Client; using OpenIddict.Client.AspNetCore; @@ -140,7 +141,7 @@ public sealed class OpenIddictClientAspNetCoreBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs index 961f31b9..a4ddb16f 100644 --- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs +++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.DataProtection; using OpenIddict.Client.DataProtection; @@ -90,7 +91,7 @@ public sealed class OpenIddictClientDataProtectionBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs index b0abdf99..bfb141c2 100644 --- a/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs +++ b/src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs @@ -131,7 +131,7 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD { // Read the version of the format used to serialize the properties. var version = reader.ReadInt32(); - if (version != 1) + if (version is not 1) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0287)); } diff --git a/src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs b/src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs index 25d62f7c..b95e7c0e 100644 --- a/src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs +++ b/src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using OpenIddict.Client; using OpenIddict.Client.Owin; using Owin; @@ -153,7 +154,7 @@ public sealed class OpenIddictClientOwinBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs index 292ca2c2..8c851a26 100644 --- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs +++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.IO.Pipes; using System.Net; using System.Runtime.Versioning; @@ -277,7 +278,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs index ff210830..2545cdda 100644 --- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs +++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs @@ -281,7 +281,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers } #if IOS || MACCATALYST || MACOS - class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject, + sealed class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject, IASWebAuthenticationPresentationContextProviding { NativeWindow IASWebAuthenticationPresentationContextProviding.GetPresentationAnchor( @@ -564,7 +564,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers return; } #endif - if (await TryLaunchBrowserWithShellExecuteAsync(uri)) + if (await TryLaunchBrowserWithShellExecuteAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; @@ -581,7 +581,8 @@ public static partial class OpenIddictClientSystemIntegrationHandlers } #endif #if IOS || MACCATALYST - if ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) && await TryLaunchBrowserWithUIApplicationAsync(uri)) + if ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) && + await TryLaunchBrowserWithUIApplicationAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; @@ -594,13 +595,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers return; } #endif - if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri)) + if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; } - if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri)) + if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs index 7f2ecade..cccd0b07 100644 --- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs +++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs @@ -281,7 +281,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers } #if IOS || MACCATALYST || MACOS - class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject, + sealed class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject, IASWebAuthenticationPresentationContextProviding { NativeWindow IASWebAuthenticationPresentationContextProviding.GetPresentationAnchor( @@ -564,7 +564,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers return; } #endif - if (await TryLaunchBrowserWithShellExecuteAsync(uri)) + if (await TryLaunchBrowserWithShellExecuteAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; @@ -581,7 +581,8 @@ public static partial class OpenIddictClientSystemIntegrationHandlers } #endif #if IOS || MACCATALYST - if ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) && await TryLaunchBrowserWithUIApplicationAsync(uri)) + if ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) && + await TryLaunchBrowserWithUIApplicationAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; @@ -594,13 +595,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers return; } #endif - if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri)) + if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; } - if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri)) + if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri, context.CancellationToken)) { context.HandleRequest(); return; diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs index ad1e4dfd..3214be16 100644 --- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs +++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs @@ -359,9 +359,10 @@ public static class OpenIddictClientSystemIntegrationHelpers /// Starts the system browser using the operating system shell. /// /// The to use. + /// The that can be used to abort the operation. /// if the browser could be started, otherwise. [SupportedOSPlatform("windows")] - internal static async ValueTask TryLaunchBrowserWithShellExecuteAsync(Uri uri) + internal static async ValueTask TryLaunchBrowserWithShellExecuteAsync(Uri uri, CancellationToken cancellationToken) { try { @@ -369,7 +370,7 @@ public static class OpenIddictClientSystemIntegrationHelpers { FileName = uri.AbsoluteUri, UseShellExecute = true - })); + }), cancellationToken); return true; } @@ -438,11 +439,14 @@ public static class OpenIddictClientSystemIntegrationHelpers /// Starts the system browser using . /// /// The to use. + /// The that can be used to abort the operation. /// if the browser could be started, otherwise. [SupportedOSPlatform("ios")] [SupportedOSPlatform("maccatalyst")] - internal static async ValueTask TryLaunchBrowserWithUIApplicationAsync(Uri uri) + internal static async ValueTask TryLaunchBrowserWithUIApplicationAsync(Uri uri, CancellationToken cancellationToken) { + cancellationToken.ThrowIfCancellationRequested(); + try { return await UIApplication.SharedApplication.OpenUrlAsync(new NSUrl(uri.AbsoluteUri), new UIApplicationOpenUrlOptions()); @@ -460,8 +464,9 @@ public static class OpenIddictClientSystemIntegrationHelpers /// /// The to use. /// if the browser could be started, otherwise. + /// The that can be used to abort the operation. [SupportedOSPlatform("macos")] - internal static async ValueTask TryLaunchBrowserWithOpenAsync(Uri uri) + internal static async ValueTask TryLaunchBrowserWithOpenAsync(Uri uri, CancellationToken cancellationToken) { try { @@ -477,7 +482,7 @@ public static class OpenIddictClientSystemIntegrationHelpers RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true - })); + }), cancellationToken); return true; } @@ -492,9 +497,10 @@ public static class OpenIddictClientSystemIntegrationHelpers /// Starts the system browser using the "xdg-open" executable. /// /// The to use. + /// The that can be used to abort the operation. /// if the browser could be started, otherwise. [SupportedOSPlatform("linux")] - internal static async ValueTask TryLaunchBrowserWithXdgOpenAsync(Uri uri) + internal static async ValueTask TryLaunchBrowserWithXdgOpenAsync(Uri uri, CancellationToken cancellationToken) { try { @@ -510,7 +516,7 @@ public static class OpenIddictClientSystemIntegrationHelpers RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true - })); + }), cancellationToken); return true; } diff --git a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs index 6a75d3db..8c623143 100644 --- a/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs +++ b/src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs @@ -157,19 +157,21 @@ public sealed class OpenIddictClientSystemIntegrationHttpListener : BackgroundSe { if (Socket.OSSupportsIPv4) { - listener.Prefixes.Add($"http://{IPAddress.Loopback}:{port.ToString(CultureInfo.InvariantCulture)}/"); + listener.Prefixes.Add(string.Create(CultureInfo.InvariantCulture, + $"http://{IPAddress.Loopback}:{port}/")); } if (Socket.OSSupportsIPv6) { - listener.Prefixes.Add($"http://[{IPAddress.IPv6Loopback}]:{port.ToString(CultureInfo.InvariantCulture)}/"); + listener.Prefixes.Add(string.Create(CultureInfo.InvariantCulture, + $"http://[{IPAddress.IPv6Loopback}]:{port}/")); } } // On older versions, listening on 127.0.0.1 and ::1 requires administrator rights. else { - listener.Prefixes.Add($"http://localhost:{port.ToString(CultureInfo.InvariantCulture)}/"); + listener.Prefixes.Add(string.Create(CultureInfo.InvariantCulture, $"http://localhost:{port}/")); } } @@ -182,7 +184,7 @@ public sealed class OpenIddictClientSystemIntegrationHttpListener : BackgroundSe // on "localhost" on platforms that use the managed HttpListener implementation. // // See https://github.com/dotnet/runtime/issues/34399 for more information. - listener.Prefixes.Add($"http://localhost:{port.ToString(CultureInfo.InvariantCulture)}/"); + listener.Prefixes.Add(string.Create(CultureInfo.InvariantCulture, $"http://localhost:{port}/")); } try diff --git a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs index ce43518d..ff6b83fb 100644 --- a/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs +++ b/src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Net.Http.Headers; using System.Net.Mail; @@ -300,7 +301,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs index 4b119e4f..bab8c6a5 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using OpenIddict.Client.WebIntegration; namespace Microsoft.Extensions.DependencyInjection; @@ -58,7 +59,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Client/OpenIddictClientBuilder.cs b/src/OpenIddict.Client/OpenIddictClientBuilder.cs index cca360ed..b9134263 100644 --- a/src/OpenIddict.Client/OpenIddictClientBuilder.cs +++ b/src/OpenIddict.Client/OpenIddictClientBuilder.cs @@ -1180,7 +1180,7 @@ public sealed class OpenIddictClientBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs index e26f6747..66e3951a 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs @@ -920,17 +920,17 @@ public static partial class OpenIddictClientHandlers => context.Registration.EncryptionCredentials.FirstOrDefault(), // For other types of tokens, use the global encryption credentials. - _ => context.Options.EncryptionCredentials.First() + _ => context.Options.EncryptionCredentials[0] }; context.SigningCredentials = context.TokenType switch { // For client assertions, use the signing credentials configured for the client registration. TokenTypeIdentifiers.Private.ClientAssertion - => context.Registration.SigningCredentials.First(), + => context.Registration.SigningCredentials[0], // For other types of tokens, use the global signing credentials. - _ => context.Options.SigningCredentials.First() + _ => context.Options.SigningCredentials[0] }; return ValueTask.CompletedTask; diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.cs index 389bd25c..7e454b65 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.cs @@ -2828,7 +2828,7 @@ public static partial class OpenIddictClientHandlers principal.SetCreationDate(context.Options.TimeProvider.GetUtcNow()); var lifetime = context.Options.ClientAssertionLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -5741,7 +5741,7 @@ public static partial class OpenIddictClientHandlers principal.SetCreationDate(context.Options.TimeProvider.GetUtcNow()); var lifetime = context.Principal.GetStateTokenLifetime() ?? context.Options.StateTokenLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -6672,7 +6672,7 @@ public static partial class OpenIddictClientHandlers principal.SetCreationDate(context.Options.TimeProvider.GetUtcNow()); var lifetime = context.Options.ClientAssertionLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -7835,7 +7835,7 @@ public static partial class OpenIddictClientHandlers principal.SetCreationDate(context.Options.TimeProvider.GetUtcNow()); var lifetime = context.Options.ClientAssertionLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -8640,7 +8640,7 @@ public static partial class OpenIddictClientHandlers principal.SetCreationDate(context.Options.TimeProvider.GetUtcNow()); var lifetime = context.Options.ClientAssertionLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -9272,7 +9272,7 @@ public static partial class OpenIddictClientHandlers principal.SetCreationDate(context.Options.TimeProvider.GetUtcNow()); var lifetime = context.Principal.GetStateTokenLifetime() ?? context.Options.StateTokenLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } diff --git a/src/OpenIddict.Client/OpenIddictClientService.cs b/src/OpenIddict.Client/OpenIddictClientService.cs index ec2f5ef4..da9a3507 100644 --- a/src/OpenIddict.Client/OpenIddictClientService.cs +++ b/src/OpenIddict.Client/OpenIddictClientService.cs @@ -599,6 +599,7 @@ public class OpenIddictClientService var dispatcher = scope.ServiceProvider.GetRequiredService(); var factory = scope.ServiceProvider.GetRequiredService(); + var options = scope.ServiceProvider.GetRequiredService>(); var transaction = await factory.CreateTransactionAsync(request.CancellationToken); @@ -670,7 +671,11 @@ public class OpenIddictClientService { // Default to a standard 5-second interval if no explicit value was configured. // See https://www.rfc-editor.org/rfc/rfc8628#section-3.5 for more information. +#if NET + await Task.Delay(interval, TimeProvider.System, source.Token); +#else await Task.Delay(interval, source.Token); +#endif } catch (ProtocolException exception) when (exception.Error is Errors.SlowDown) @@ -679,7 +684,11 @@ public class OpenIddictClientService // slow down the token redeeming process by increasing the interval. // // See https://www.rfc-editor.org/rfc/rfc8628#section-3.5 for more information. +#if NET + await Task.Delay(interval += TimeSpan.FromSeconds(5), TimeProvider.System, source.Token); +#else await Task.Delay(interval += TimeSpan.FromSeconds(5), source.Token); +#endif } } } diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs index 49f9fbd8..2df50355 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs @@ -195,7 +195,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication } var results = await GetValidationResultsAsync(application, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0207)); @@ -382,7 +382,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var application in applications) + await foreach (var application in applications.WithCancellation(cancellationToken)) { var uris = await Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken); if (uris.Contains(uri, StringComparer.Ordinal)) @@ -421,7 +421,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var application in applications) + await foreach (var application in applications.WithCancellation(cancellationToken)) { var uris = await Store.GetRedirectUrisAsync(application, cancellationToken); if (uris.Contains(uri, StringComparer.Ordinal)) @@ -1129,7 +1129,7 @@ public class OpenIddictApplicationManager : IOpenIddictApplication ArgumentNullException.ThrowIfNull(application); var results = await GetValidationResultsAsync(application, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0215)); diff --git a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs index fd823537..67676ff6 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs @@ -134,7 +134,7 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori } var results = await GetValidationResultsAsync(authorization, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0207)); @@ -238,7 +238,7 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var authorization in authorizations) + await foreach (var authorization in authorizations.WithCancellation(cancellationToken)) { if (!string.IsNullOrEmpty(query.Subject) && !string.Equals(await Store.GetSubjectAsync(authorization, cancellationToken), query.Subject, StringComparison.Ordinal)) @@ -285,7 +285,7 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var authorization in authorizations) + await foreach (var authorization in authorizations.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetApplicationIdAsync(authorization, cancellationToken), identifier, StringComparison.Ordinal)) { @@ -357,7 +357,7 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var authorization in authorizations) + await foreach (var authorization in authorizations.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetSubjectAsync(authorization, cancellationToken), subject, StringComparison.Ordinal)) { @@ -796,7 +796,7 @@ public class OpenIddictAuthorizationManager : IOpenIddictAuthori ArgumentNullException.ThrowIfNull(authorization); var results = await GetValidationResultsAsync(authorization, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0215)); diff --git a/src/OpenIddict.Core/Managers/OpenIddictResourceManager.cs b/src/OpenIddict.Core/Managers/OpenIddictResourceManager.cs index a24d0929..93961e65 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictResourceManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictResourceManager.cs @@ -129,7 +129,7 @@ public class OpenIddictResourceManager : IOpenIddictResourceManager w ArgumentNullException.ThrowIfNull(resource); var results = await GetValidationResultsAsync(resource, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0207)); @@ -306,7 +306,7 @@ public class OpenIddictResourceManager : IOpenIddictResourceManager w async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var resource in resources) + await foreach (var resource in resources.WithCancellation(cancellationToken)) { var name = await Store.GetNameAsync(resource, cancellationToken); if (!string.IsNullOrEmpty(name) && names.Contains(name, StringComparer.Ordinal)) @@ -696,7 +696,7 @@ public class OpenIddictResourceManager : IOpenIddictResourceManager w ArgumentNullException.ThrowIfNull(resource); var results = await GetValidationResultsAsync(resource, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0215)); diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index 832fd58c..57fc4124 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -128,7 +128,7 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco ArgumentNullException.ThrowIfNull(scope); var results = await GetValidationResultsAsync(scope, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0207)); @@ -305,7 +305,7 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var scope in scopes) + await foreach (var scope in scopes.WithCancellation(cancellationToken)) { var name = await Store.GetNameAsync(scope, cancellationToken); if (!string.IsNullOrEmpty(name) && names.Contains(name, StringComparer.Ordinal)) @@ -344,7 +344,7 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var scope in scopes) + await foreach (var scope in scopes.WithCancellation(cancellationToken)) { var resources = await Store.GetResourcesAsync(scope, cancellationToken); if (resources.Contains(resource, StringComparer.Ordinal)) @@ -777,7 +777,7 @@ public class OpenIddictScopeManager : IOpenIddictScopeManager where TSco ArgumentNullException.ThrowIfNull(scope); var results = await GetValidationResultsAsync(scope, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0215)); diff --git a/src/OpenIddict.Core/Managers/OpenIddictSessionManager.cs b/src/OpenIddict.Core/Managers/OpenIddictSessionManager.cs index f8d02ef5..819f1987 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictSessionManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictSessionManager.cs @@ -133,7 +133,7 @@ public class OpenIddictSessionManager : IOpenIddictSessionManager wher } var results = await GetValidationResultsAsync(session, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0207)); @@ -237,7 +237,7 @@ public class OpenIddictSessionManager : IOpenIddictSessionManager wher async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var session in sessions) + await foreach (var session in sessions.WithCancellation(cancellationToken)) { if (string.IsNullOrEmpty(query.Subject) || string.Equals(await Store.GetSubjectAsync(session, cancellationToken), query.Subject, StringComparison.Ordinal)) @@ -276,7 +276,7 @@ public class OpenIddictSessionManager : IOpenIddictSessionManager wher async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var session in sessions) + await foreach (var session in sessions.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetApplicationIdAsync(session, cancellationToken), identifier, StringComparison.Ordinal)) { @@ -314,7 +314,7 @@ public class OpenIddictSessionManager : IOpenIddictSessionManager wher async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var session in sessions) + await foreach (var session in sessions.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetAuthorizationIdAsync(session, cancellationToken), identifier, StringComparison.Ordinal)) { @@ -385,7 +385,7 @@ public class OpenIddictSessionManager : IOpenIddictSessionManager wher async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var session in sessions) + await foreach (var session in sessions.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetLoginIdAsync(session, cancellationToken), identifier, StringComparison.Ordinal)) { @@ -423,7 +423,7 @@ public class OpenIddictSessionManager : IOpenIddictSessionManager wher async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var session in sessions) + await foreach (var session in sessions.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetSubjectAsync(session, cancellationToken), subject, StringComparison.Ordinal)) { @@ -712,7 +712,7 @@ public class OpenIddictSessionManager : IOpenIddictSessionManager wher ArgumentNullException.ThrowIfNull(session); var results = await GetValidationResultsAsync(session, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0215)); diff --git a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs index eec8b69b..abeec969 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs @@ -143,7 +143,7 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok } var results = await GetValidationResultsAsync(token, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0207)); @@ -247,7 +247,7 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var token in tokens) + await foreach (var token in tokens.WithCancellation(cancellationToken)) { if (string.IsNullOrEmpty(query.Subject) || string.Equals(await Store.GetSubjectAsync(token, cancellationToken), query.Subject, StringComparison.Ordinal)) @@ -286,7 +286,7 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var token in tokens) + await foreach (var token in tokens.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetApplicationIdAsync(token, cancellationToken), identifier, StringComparison.Ordinal)) { @@ -324,7 +324,7 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var token in tokens) + await foreach (var token in tokens.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetAuthorizationIdAsync(token, cancellationToken), identifier, StringComparison.Ordinal)) { @@ -436,7 +436,7 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok async IAsyncEnumerable ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) { - await foreach (var token in tokens) + await foreach (var token in tokens.WithCancellation(cancellationToken)) { if (string.Equals(await Store.GetSubjectAsync(token, cancellationToken), subject, StringComparison.Ordinal)) { @@ -1048,7 +1048,7 @@ public class OpenIddictTokenManager : IOpenIddictTokenManager where TTok ArgumentNullException.ThrowIfNull(token); var results = await GetValidationResultsAsync(token, cancellationToken); - if (results.Any(result => result != ValidationResult.Success)) + if (results.Any(static result => result != ValidationResult.Success)) { var builder = new StringBuilder(); builder.AppendLine(SR.GetResourceString(SR.ID0215)); diff --git a/src/OpenIddict.Core/OpenIddictCoreBuilder.cs b/src/OpenIddict.Core/OpenIddictCoreBuilder.cs index c0b49cf6..353eca76 100644 --- a/src/OpenIddict.Core/OpenIddictCoreBuilder.cs +++ b/src/OpenIddict.Core/OpenIddictCoreBuilder.cs @@ -721,7 +721,7 @@ public sealed class OpenIddictCoreBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs index a585cf67..a37c5ba5 100644 --- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs +++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs @@ -143,7 +143,7 @@ public sealed class OpenIddictEntityFrameworkBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs index 339eb36e..00a642da 100644 --- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs +++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs @@ -78,7 +78,9 @@ public static class OpenIddictEntityFrameworkHelpers /// The query source. /// The that can be used to abort the operation. /// The streamed async enumeration containing the results. +#pragma warning disable MA0156 internal static IAsyncEnumerable AsAsyncEnumerable(this IQueryable source, CancellationToken cancellationToken) +#pragma warning restore MA0156 { ArgumentNullException.ThrowIfNull(source); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs index 1a668a7d..ec76682e 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs @@ -241,7 +241,7 @@ public class OpenIddictEntityFrameworkApplicationStore< where application.PostLogoutRedirectUris!.Contains(uri) select application).AsAsyncEnumerable(cancellationToken); - await foreach (var application in applications) + await foreach (var application in applications.WithCancellation(cancellationToken)) { var uris = await GetPostLogoutRedirectUrisAsync(application, cancellationToken); if (uris.Contains(uri, StringComparer.Ordinal)) @@ -274,7 +274,7 @@ public class OpenIddictEntityFrameworkApplicationStore< where application.RedirectUris!.Contains(uri) select application).AsAsyncEnumerable(cancellationToken); - await foreach (var application in applications) + await foreach (var application in applications.WithCancellation(cancellationToken)) { var uris = await GetRedirectUrisAsync(application, cancellationToken); if (uris.Contains(uri, StringComparer.Ordinal)) @@ -660,12 +660,12 @@ public class OpenIddictEntityFrameworkApplicationStore< IQueryable query = context.Set().OrderBy(application => application.Id!); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs index 6519f5ed..502eedca 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs @@ -432,12 +432,12 @@ public class OpenIddictEntityFrameworkAuthorizationStore< .Include(authorization => authorization.Application) .OrderBy(authorization => authorization.Id!); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs index afa49a1f..104a3c4a 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs @@ -358,12 +358,12 @@ public class OpenIddictEntityFrameworkResourceStore< IQueryable query = context.Set().OrderBy(resource => resource.Id!); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs index 7c339a04..1d9f32e8 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs @@ -204,7 +204,7 @@ public class OpenIddictEntityFrameworkScopeStore< where scope.Resources!.Contains(resource) select scope).AsAsyncEnumerable(cancellationToken); - await foreach (var scope in scopes) + await foreach (var scope in scopes.WithCancellation(cancellationToken)) { var resources = await GetResourcesAsync(scope, cancellationToken); if (resources.Contains(resource, StringComparer.Ordinal)) @@ -428,12 +428,12 @@ public class OpenIddictEntityFrameworkScopeStore< IQueryable query = context.Set().OrderBy(scope => scope.Id!); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkSessionStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkSessionStore.cs index 52cf53fc..c423fc56 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkSessionStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkSessionStore.cs @@ -433,12 +433,12 @@ public class OpenIddictEntityFrameworkSessionStore< IQueryable query = context.Set().OrderBy(session => session.Id!); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs index ee6307ff..894701d7 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs @@ -467,12 +467,12 @@ public class OpenIddictEntityFrameworkTokenStore< .Include(token => token.Authorization) .OrderBy(token => token.Id!); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs index 08d57259..4bd58a9c 100644 --- a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs +++ b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs @@ -153,7 +153,7 @@ public sealed class OpenIddictEntityFrameworkCoreBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs index c8caaa2b..e90e4899 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs @@ -483,12 +483,12 @@ public class OpenIddictEntityFrameworkCoreApplicationStore< var query = context.Set().OrderBy(application => application.Id!).AsTracking(); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs index 7f6939eb..87c7fd64 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs @@ -438,12 +438,12 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore< .OrderBy(authorization => authorization.Id!) .AsTracking(); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs index eb35b1bc..60d71bf2 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs @@ -281,12 +281,12 @@ public class OpenIddictEntityFrameworkCoreResourceStore< var query = context.Set().OrderBy(resource => resource.Id!).AsTracking(); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs index e8187855..4694c4d9 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs @@ -309,12 +309,12 @@ public class OpenIddictEntityFrameworkCoreScopeStore< var query = context.Set().OrderBy(scope => scope.Id!).AsTracking(); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreSessionStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreSessionStore.cs index 95e45734..9855b4e7 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreSessionStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreSessionStore.cs @@ -430,12 +430,12 @@ public class OpenIddictEntityFrameworkCoreSessionStore< var query = context.Set().OrderBy(session => session.Id!).AsTracking(); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs index 1b4050e4..09202eb6 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs @@ -460,12 +460,12 @@ public class OpenIddictEntityFrameworkCoreTokenStore< .OrderBy(token => token.Id!) .AsTracking(); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs b/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs index afe8b8b6..53628fb2 100644 --- a/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs +++ b/src/OpenIddict.MongoDb/OpenIddictMongoDbBuilder.cs @@ -247,7 +247,7 @@ public sealed class OpenIddictMongoDbBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs index aa85878e..ac6ac5e8 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs @@ -354,12 +354,12 @@ public class OpenIddictMongoDbApplicationStore< var query = (IQueryable) collection.AsQueryable().OrderBy(application => application.Id); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs index 87076cef..a52f1735 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs @@ -317,12 +317,12 @@ public class OpenIddictMongoDbAuthorizationStore< var query = (IQueryable) collection.AsQueryable().OrderBy(authorization => authorization.Id); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs index 6f727f8f..24ca8893 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs @@ -259,12 +259,12 @@ public class OpenIddictMongoDbResourceStore< var query = (IQueryable) collection.AsQueryable().OrderBy(resource => resource.Id); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs index b887392c..76ccd999 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs @@ -286,12 +286,12 @@ public class OpenIddictMongoDbScopeStore< var query = (IQueryable) collection.AsQueryable().OrderBy(scope => scope.Id); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbSessionStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbSessionStore.cs index a40e6e6e..81e53ff6 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbSessionStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbSessionStore.cs @@ -343,12 +343,12 @@ public class OpenIddictMongoDbSessionStore< var query = (IQueryable) collection.AsQueryable().OrderBy(session => session.Id); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs index d44e9ed1..f9444701 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs @@ -367,12 +367,12 @@ public class OpenIddictMongoDbTokenStore< var query = (IQueryable) collection.AsQueryable().OrderBy(token => token.Id); - if (offset.HasValue) + if (offset is not null) { query = query.Skip(offset.Value); } - if (count.HasValue) + if (count is not null) { query = query.Take(count.Value); } diff --git a/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs b/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs index 5a75e43e..4f78eb21 100644 --- a/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs +++ b/src/OpenIddict.Quartz/OpenIddictQuartzBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using OpenIddict.Quartz; namespace Microsoft.Extensions.DependencyInjection; @@ -106,7 +107,7 @@ public sealed class OpenIddictQuartzBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs index 43d1d42e..8e2733ff 100644 --- a/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs +++ b/src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore; using OpenIddict.Server.AspNetCore; @@ -156,7 +157,7 @@ public sealed class OpenIddictServerAspNetCoreBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs index 82ebe2b2..c5dc17ff 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.DataProtection; using OpenIddict.Server.DataProtection; @@ -125,7 +126,7 @@ public sealed class OpenIddictServerDataProtectionBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs index 4c5d347e..52f1b939 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs @@ -141,7 +141,7 @@ public sealed class OpenIddictServerDataProtectionFormatter : IOpenIddictServerD { // Read the version of the format used to serialize the properties. var version = reader.ReadInt32(); - if (version != 1) + if (version is not 1) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0287)); } diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs index 6e1b0e71..7350b326 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using OpenIddict.Server.Owin; using Owin; @@ -145,7 +146,7 @@ public sealed class OpenIddictServerOwinBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Server/OpenIddictServerBuilder.cs b/src/OpenIddict.Server/OpenIddictServerBuilder.cs index 1d5265af..b728be24 100644 --- a/src/OpenIddict.Server/OpenIddictServerBuilder.cs +++ b/src/OpenIddict.Server/OpenIddictServerBuilder.cs @@ -2453,7 +2453,7 @@ public sealed class OpenIddictServerBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs index fb84140c..110015d2 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Authentication.cs @@ -1833,7 +1833,7 @@ public static partial class OpenIddictServerHandlers return; } - async ValueTask HasPermissionAsync(IEnumerable types) + async ValueTask HasPermissionAsync(ImmutableArray types) { // Note: response type permissions are always prefixed with "rst:". const string prefix = Permissions.Prefixes.ResponseType; @@ -1849,7 +1849,7 @@ public static partial class OpenIddictServerHandlers // Note: response types can be specified in any order. To ensure permissions are correctly // checked even if the order differs from the one specified in the request, a HashSet is used. var values = permission[prefix.Length..].Split(Separators.Space, StringSplitOptions.RemoveEmptyEntries); - if (values.Length is not 0 && values.ToHashSet(StringComparer.Ordinal).SetEquals(types)) + if (values is not [] && values.ToHashSet(StringComparer.Ordinal).SetEquals(types)) { return true; } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs index 5c4cf8cb..73d12657 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Protection.cs @@ -1475,7 +1475,7 @@ public static partial class OpenIddictServerHandlers TokenTypeIdentifiers.AccessToken when context.Options.DisableAccessTokenEncryption => null, TokenTypeIdentifiers.IdentityToken => null, - _ => context.Options.EncryptionCredentials.First() + _ => context.Options.EncryptionCredentials[0] }; context.SigningCredentials = context.TokenType switch @@ -1485,7 +1485,7 @@ public static partial class OpenIddictServerHandlers TokenTypeIdentifiers.IdentityToken => context.Options.SigningCredentials.First(static credentials => credentials.Key is AsymmetricSecurityKey), - _ => context.Options.SigningCredentials.First() + _ => context.Options.SigningCredentials[0] }; return ValueTask.CompletedTask; diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs index 5fc9a54e..dec4ad85 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Session.cs @@ -831,7 +831,8 @@ public static partial class OpenIddictServerHandlers throw new InvalidOperationException(SR.GetResourceString(SR.ID0016)); } - if (!await ValidateAuthorizedParty(context.IdentityTokenHintPrincipal, context.PostLogoutRedirectUri)) + if (!await ValidateAuthorizedPartyAsync(context.IdentityTokenHintPrincipal, + context.PostLogoutRedirectUri, context.CancellationToken)) { context.Logger.LogWarning(6198, SR.GetResourceString(SR.ID6198)); @@ -846,8 +847,8 @@ public static partial class OpenIddictServerHandlers return; } - async ValueTask ValidateAuthorizedParty(ClaimsPrincipal principal, - [StringSyntax(StringSyntaxAttribute.Uri)] string uri) + async ValueTask ValidateAuthorizedPartyAsync(ClaimsPrincipal principal, + [StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken) { // To be considered valid, the specified post_logout_redirect_uri must // be considered valid for one of the listed audiences/presenters. @@ -858,7 +859,7 @@ public static partial class OpenIddictServerHandlers foreach (var identifier in identifiers) { - var application = await _applicationManager.FindByClientIdAsync(identifier, context.CancellationToken); + var application = await _applicationManager.FindByClientIdAsync(identifier, cancellationToken); if (application is null) { continue; @@ -866,13 +867,13 @@ public static partial class OpenIddictServerHandlers // Note: the legacy "ept:logout" permission is still allowed for backward compatibility. if (!context.Options.IgnoreEndpointPermissions && - !await _applicationManager.HasPermissionAsync(application, Permissions.Endpoints.EndSession, context.CancellationToken) && - !await _applicationManager.HasPermissionAsync(application, "ept:logout", context.CancellationToken)) + !await _applicationManager.HasPermissionAsync(application, Permissions.Endpoints.EndSession, cancellationToken) && + !await _applicationManager.HasPermissionAsync(application, "ept:logout", cancellationToken)) { continue; } - if (await _applicationManager.ValidatePostLogoutRedirectUriAsync(application, uri, context.CancellationToken)) + if (await _applicationManager.ValidatePostLogoutRedirectUriAsync(application, uri, cancellationToken)) { return true; } diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.cs index 5ef3669a..2f5703ec 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.cs @@ -3625,7 +3625,7 @@ public static partial class OpenIddictServerHandlers // Otherwise, fall back to the global value. lifetime ??= context.Options.AccessTokenLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -3759,7 +3759,7 @@ public static partial class OpenIddictServerHandlers // Otherwise, fall back to the global value. lifetime ??= context.Options.AuthorizationCodeLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -3883,7 +3883,7 @@ public static partial class OpenIddictServerHandlers // Otherwise, fall back to the global value. lifetime ??= context.Options.DeviceCodeLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -4117,7 +4117,7 @@ public static partial class OpenIddictServerHandlers _ => context.Options.IssuedTokenLifetime }; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -4291,7 +4291,7 @@ public static partial class OpenIddictServerHandlers // Otherwise, fall back to the global value. lifetime ??= context.Options.RequestTokenLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -4436,7 +4436,7 @@ public static partial class OpenIddictServerHandlers // Otherwise, fall back to the global value. lifetime ??= context.Options.RefreshTokenLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -4612,7 +4612,7 @@ public static partial class OpenIddictServerHandlers // Otherwise, fall back to the global value. lifetime ??= context.Options.IdentityTokenLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -4739,7 +4739,7 @@ public static partial class OpenIddictServerHandlers // Otherwise, fall back to the global value. lifetime ??= context.Options.UserCodeLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } @@ -5696,7 +5696,7 @@ public static partial class OpenIddictServerHandlers { var uri = OpenIddictHelpers.CreateAbsoluteUri( left : context.BaseUri ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0127)), - right: context.Options.EndUserVerificationEndpointUris.First()); + right: context.Options.EndUserVerificationEndpointUris[0]); context.Response.VerificationUri = uri.AbsoluteUri; diff --git a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs index 0b21a04d..7206c77d 100644 --- a/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs +++ b/src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using OpenIddict.Validation.AspNetCore; namespace Microsoft.Extensions.DependencyInjection; @@ -93,7 +94,7 @@ public sealed class OpenIddictValidationAspNetCoreBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs index 2fda3027..f2877905 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.DataProtection; using OpenIddict.Validation.DataProtection; @@ -83,7 +84,7 @@ public sealed class OpenIddictValidationDataProtectionBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs index 1fe35d51..4902b88b 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs @@ -124,7 +124,7 @@ public sealed class OpenIddictValidationDataProtectionFormatter : IOpenIddictVal { // Read the version of the format used to serialize the properties. var version = reader.ReadInt32(); - if (version != 1) + if (version is not 1) { throw new InvalidOperationException(SR.GetResourceString(SR.ID0287)); } diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs index 5cfa6aca..89bf2183 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using OpenIddict.Validation.Owin; namespace Microsoft.Extensions.DependencyInjection; @@ -107,7 +108,7 @@ public sealed class OpenIddictValidationOwinBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs index be1ffb3d..76159d03 100644 --- a/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs +++ b/src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using OpenIddict.Validation.ServerIntegration; namespace Microsoft.Extensions.DependencyInjection; @@ -56,7 +57,7 @@ public sealed class OpenIddictValidationServerIntegrationBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs index 4b703a7d..26fc46d7 100644 --- a/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs +++ b/src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs @@ -5,6 +5,7 @@ */ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Net.Http.Headers; using System.Net.Mail; @@ -208,7 +209,7 @@ public sealed class OpenIddictValidationSystemNetHttpBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs b/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs index 6682059c..bd8937fc 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationBuilder.cs @@ -711,7 +711,7 @@ public sealed class OpenIddictValidationBuilder /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => base.Equals(obj); + public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs index e9d241ec..04170aaf 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlers.Protection.cs @@ -1007,7 +1007,7 @@ public static partial class OpenIddictValidationHandlers { ArgumentNullException.ThrowIfNull(context); - context.SecurityTokenDescriptor.SigningCredentials = context.Options.SigningCredentials.First(); + context.SecurityTokenDescriptor.SigningCredentials = context.Options.SigningCredentials[0]; context.SecurityTokenHandler = context.Options.JsonWebTokenHandler; return ValueTask.CompletedTask; diff --git a/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs b/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs index 5705a8a9..f560168c 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationHandlers.cs @@ -531,7 +531,7 @@ public static partial class OpenIddictValidationHandlers principal.SetCreationDate(context.Options.TimeProvider.GetUtcNow()); var lifetime = context.Options.ClientAssertionLifetime; - if (lifetime.HasValue) + if (lifetime is not null) { principal.SetExpirationDate(principal.GetCreationDate() + lifetime.Value); } diff --git a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs index 4bb020f1..08391150 100644 --- a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs +++ b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs @@ -150,8 +150,8 @@ public class OpenIddictConverterTests Assert.NotNull(message.GetParameter("array")); Assert.NotNull(message.GetParameter("object")); Assert.Empty(((string?) message.GetParameter("string"))!); - Assert.True(((JsonElement?) message.GetParameter("array")).HasValue); - Assert.True(((JsonElement?) message.GetParameter("object")).HasValue); + Assert.True((JsonElement?) message.GetParameter("array") is not null); + Assert.True((JsonElement?) message.GetParameter("object") is not null); Assert.NotNull((JsonNode?) message.GetParameter("array")); Assert.NotNull((JsonNode?) message.GetParameter("object")); } diff --git a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictMessageTests.cs b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictMessageTests.cs index 896e6756..de63acab 100644 --- a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictMessageTests.cs +++ b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictMessageTests.cs @@ -193,9 +193,9 @@ public class OpenIddictMessageTests // Assert Assert.Empty(((string?) message.GetParameter("string"))!); - Assert.True(((JsonElement?) message.GetParameter("array")).HasValue); - Assert.True(((JsonElement?) message.GetParameter("object")).HasValue); - Assert.True(((JsonElement?) message.GetParameter("value")).HasValue); + Assert.True((JsonElement?) message.GetParameter("array") is not null); + Assert.True((JsonElement?) message.GetParameter("object") is not null); + Assert.True((JsonElement?) message.GetParameter("value") is not null); Assert.NotNull((JsonNode?) message.GetParameter("node_array")); Assert.NotNull((JsonNode?) message.GetParameter("node_object")); Assert.NotNull((JsonNode?) message.GetParameter("node_value")); diff --git a/test/OpenIddict.Client.Tests/OpenIddictClientBuilderTests.cs b/test/OpenIddict.Client.Tests/OpenIddictClientBuilderTests.cs index ce9b43c1..308d2916 100644 --- a/test/OpenIddict.Client.Tests/OpenIddictClientBuilderTests.cs +++ b/test/OpenIddict.Client.Tests/OpenIddictClientBuilderTests.cs @@ -88,7 +88,7 @@ public class OpenIddictClientBuilderTests Assert.Contains(services, service => service.ServiceType == typeof(CustomHandler) && service.ImplementationInstance?.GetType() == typeof(CustomHandler) && - service.Lifetime == ServiceLifetime.Singleton); + service.Lifetime is ServiceLifetime.Singleton); } [Fact] @@ -1510,12 +1510,12 @@ public class OpenIddictClientBuilderTests return options.Value; } - private class CustomContext : BaseContext + private sealed class CustomContext : BaseContext { public CustomContext(OpenIddictClientTransaction transaction) : base(transaction) { } } - private class CustomHandler : IOpenIddictClientHandler + private sealed class CustomHandler : IOpenIddictClientHandler { public ValueTask HandleAsync(CustomContext context) => ValueTask.CompletedTask; } diff --git a/test/OpenIddict.Core.Tests/Managers/OpenIddictApplicationManagerTests.cs b/test/OpenIddict.Core.Tests/Managers/OpenIddictApplicationManagerTests.cs index 045c53b9..a1ac1914 100644 --- a/test/OpenIddict.Core.Tests/Managers/OpenIddictApplicationManagerTests.cs +++ b/test/OpenIddict.Core.Tests/Managers/OpenIddictApplicationManagerTests.cs @@ -3539,7 +3539,7 @@ public class OpenIddictApplicationManagerTests public class CustomApplication; - private class CustomApplicationManagerWithProtectedAccess : OpenIddictApplicationManager + private sealed class CustomApplicationManagerWithProtectedAccess : OpenIddictApplicationManager { public CustomApplicationManagerWithProtectedAccess( IOpenIddictApplicationCache cache, diff --git a/test/OpenIddict.Core.Tests/OpenIddictCoreBuilderTests.cs b/test/OpenIddict.Core.Tests/OpenIddictCoreBuilderTests.cs index ebdea32e..762f5c63 100644 --- a/test/OpenIddict.Core.Tests/OpenIddictCoreBuilderTests.cs +++ b/test/OpenIddict.Core.Tests/OpenIddictCoreBuilderTests.cs @@ -65,7 +65,7 @@ public class OpenIddictCoreBuilderTests // Assert var descriptor = Assert.Single(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(OpenIddictApplicationManager<>)); Assert.Equal(typeof(OpenGenericApplicationManager<>), descriptor.ImplementationType); } @@ -110,7 +110,7 @@ public class OpenIddictCoreBuilderTests // Assert var descriptor = Assert.Single(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(OpenIddictAuthorizationManager<>)); Assert.Equal(typeof(OpenGenericAuthorizationManager<>), descriptor.ImplementationType); } @@ -155,7 +155,7 @@ public class OpenIddictCoreBuilderTests // Assert var descriptor = Assert.Single(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(OpenIddictResourceManager<>)); Assert.Equal(typeof(OpenGenericResourceManager<>), descriptor.ImplementationType); } @@ -200,7 +200,7 @@ public class OpenIddictCoreBuilderTests // Assert var descriptor = Assert.Single(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(OpenIddictScopeManager<>)); Assert.Equal(typeof(OpenGenericScopeManager<>), descriptor.ImplementationType); } @@ -245,7 +245,7 @@ public class OpenIddictCoreBuilderTests // Assert var descriptor = Assert.Single(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(OpenIddictSessionManager<>)); Assert.Equal(typeof(OpenGenericSessionManager<>), descriptor.ImplementationType); } @@ -290,7 +290,7 @@ public class OpenIddictCoreBuilderTests // Assert var descriptor = Assert.Single(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(OpenIddictTokenManager<>)); Assert.Equal(typeof(OpenGenericTokenManager<>), descriptor.ImplementationType); } @@ -540,7 +540,7 @@ public class OpenIddictCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationManager) && service.ImplementationFactory is not null); } @@ -557,7 +557,7 @@ public class OpenIddictCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationManager) && service.ImplementationFactory is not null); } @@ -574,7 +574,7 @@ public class OpenIddictCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceManager) && service.ImplementationFactory is not null); } @@ -591,7 +591,7 @@ public class OpenIddictCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeManager) && service.ImplementationFactory is not null); } @@ -608,7 +608,7 @@ public class OpenIddictCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictSessionManager) && service.ImplementationFactory is not null); } @@ -625,7 +625,7 @@ public class OpenIddictCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenManager) && service.ImplementationFactory is not null); } @@ -640,14 +640,14 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) return services; } - private class CustomApplication; - private class CustomAuthorization; - private class CustomResource; - private class CustomScope; - private class CustomSession; - private class CustomToken; + private sealed class CustomApplication; + private sealed class CustomAuthorization; + private sealed class CustomResource; + private sealed class CustomScope; + private sealed class CustomSession; + private sealed class CustomToken; - private class ClosedGenericApplicationManager : OpenIddictApplicationManager + private sealed class ClosedGenericApplicationManager : OpenIddictApplicationManager { public ClosedGenericApplicationManager( IOpenIddictApplicationCache cache, @@ -659,7 +659,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class OpenGenericApplicationManager : OpenIddictApplicationManager + private sealed class OpenGenericApplicationManager : OpenIddictApplicationManager where TApplication : class { public OpenGenericApplicationManager( @@ -672,7 +672,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class ClosedGenericAuthorizationManager : OpenIddictAuthorizationManager + private sealed class ClosedGenericAuthorizationManager : OpenIddictAuthorizationManager { public ClosedGenericAuthorizationManager( IOpenIddictAuthorizationCache cache, @@ -684,7 +684,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class OpenGenericAuthorizationManager : OpenIddictAuthorizationManager + private sealed class OpenGenericAuthorizationManager : OpenIddictAuthorizationManager where TAuthorization : class { public OpenGenericAuthorizationManager( @@ -697,7 +697,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class ClosedGenericResourceManager : OpenIddictResourceManager + private sealed class ClosedGenericResourceManager : OpenIddictResourceManager { public ClosedGenericResourceManager( IOpenIddictResourceCache cache, @@ -709,7 +709,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class OpenGenericResourceManager : OpenIddictResourceManager + private sealed class OpenGenericResourceManager : OpenIddictResourceManager where TResource : class { public OpenGenericResourceManager( @@ -722,7 +722,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class ClosedGenericScopeManager : OpenIddictScopeManager + private sealed class ClosedGenericScopeManager : OpenIddictScopeManager { public ClosedGenericScopeManager( IOpenIddictScopeCache cache, @@ -734,7 +734,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class OpenGenericScopeManager : OpenIddictScopeManager + private sealed class OpenGenericScopeManager : OpenIddictScopeManager where TScope : class { public OpenGenericScopeManager( @@ -747,7 +747,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class ClosedGenericSessionManager : OpenIddictSessionManager + private sealed class ClosedGenericSessionManager : OpenIddictSessionManager { public ClosedGenericSessionManager( IOpenIddictSessionCache cache, @@ -759,7 +759,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class OpenGenericSessionManager : OpenIddictSessionManager + private sealed class OpenGenericSessionManager : OpenIddictSessionManager where TSession : class { public OpenGenericSessionManager( @@ -772,7 +772,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class ClosedGenericTokenManager : OpenIddictTokenManager + private sealed class ClosedGenericTokenManager : OpenIddictTokenManager { public ClosedGenericTokenManager( IOpenIddictTokenCache cache, @@ -784,7 +784,7 @@ private static OpenIddictCoreBuilder CreateBuilder(IServiceCollection services) } } - private class OpenGenericTokenManager : OpenIddictTokenManager + private sealed class OpenGenericTokenManager : OpenIddictTokenManager where TToken : class { public OpenGenericTokenManager( diff --git a/test/OpenIddict.Core.Tests/OpenIddictCoreConfigurationTests.cs b/test/OpenIddict.Core.Tests/OpenIddictCoreConfigurationTests.cs index 1ca78758..39d9eaaa 100644 --- a/test/OpenIddict.Core.Tests/OpenIddictCoreConfigurationTests.cs +++ b/test/OpenIddict.Core.Tests/OpenIddictCoreConfigurationTests.cs @@ -297,7 +297,7 @@ public class OpenIddictCoreConfigurationTests // Assert Assert.True(result.Succeeded); } - private class CustomTimeProvider : TimeProvider + private sealed class CustomTimeProvider : TimeProvider { } } diff --git a/test/OpenIddict.Core.Tests/OpenIddictCoreOptionsTests.cs b/test/OpenIddict.Core.Tests/OpenIddictCoreOptionsTests.cs index ac8814c5..0621cfe3 100644 --- a/test/OpenIddict.Core.Tests/OpenIddictCoreOptionsTests.cs +++ b/test/OpenIddict.Core.Tests/OpenIddictCoreOptionsTests.cs @@ -146,7 +146,7 @@ public class OpenIddictCoreOptionsTests Assert.Same(customTimeProvider, options.TimeProvider); } - private class CustomTimeProvider : TimeProvider + private sealed class CustomTimeProvider : TimeProvider { } } diff --git a/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkBuilderTests.cs b/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkBuilderTests.cs index 2c76a8fd..051f04d3 100644 --- a/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkBuilderTests.cs +++ b/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkBuilderTests.cs @@ -37,27 +37,27 @@ public class OpenIddictEntityFrameworkBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkApplicationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkAuthorizationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkResourceStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkScopeStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictSessionStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkSessionStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkTokenStore)); } @@ -74,7 +74,7 @@ public class OpenIddictEntityFrameworkBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictEntityFrameworkContext) && service.ImplementationType == typeof(OpenIddictEntityFrameworkContext)); } diff --git a/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs b/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs index 46ce8854..5384f255 100644 --- a/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs +++ b/test/OpenIddict.EntityFramework.Tests/OpenIddictEntityFrameworkExtensionsTests.cs @@ -49,23 +49,23 @@ public class OpenIddictEntityFrameworkExtensionsTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenManager) && service.ImplementationFactory is not null); } @@ -82,23 +82,23 @@ public class OpenIddictEntityFrameworkExtensionsTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkApplicationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkAuthorizationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkResourceStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkScopeStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkTokenStore)); } diff --git a/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreBuilderTests.cs b/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreBuilderTests.cs index 01f66986..496d31c5 100644 --- a/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreBuilderTests.cs +++ b/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreBuilderTests.cs @@ -37,27 +37,27 @@ public class OpenIddictEntityFrameworkCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreApplicationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreAuthorizationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreResourceStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreScopeStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictSessionStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreSessionStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreTokenStore)); } @@ -74,7 +74,7 @@ public class OpenIddictEntityFrameworkCoreBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictEntityFrameworkCoreContext) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreContext)); } diff --git a/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs b/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs index ad1fbd2b..6843fb35 100644 --- a/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs +++ b/test/OpenIddict.EntityFrameworkCore.Tests/OpenIddictEntityFrameworkCoreExtensionsTests.cs @@ -49,23 +49,23 @@ public class OpenIddictEntityFrameworkCoreExtensionsTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenManager) && service.ImplementationFactory is not null); } @@ -82,23 +82,23 @@ public class OpenIddictEntityFrameworkCoreExtensionsTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreApplicationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreAuthorizationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreResourceStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreScopeStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenStore) && service.ImplementationType == typeof(OpenIddictEntityFrameworkCoreTokenStore)); } diff --git a/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbBuilderTests.cs b/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbBuilderTests.cs index 7ca3cde7..c0887793 100644 --- a/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbBuilderTests.cs +++ b/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbBuilderTests.cs @@ -39,7 +39,7 @@ public class OpenIddictMongoDbBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationStore) && service.ImplementationType == typeof(OpenIddictMongoDbApplicationStore)); } @@ -56,7 +56,7 @@ public class OpenIddictMongoDbBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationStore) && service.ImplementationType == typeof(OpenIddictMongoDbAuthorizationStore)); } @@ -73,7 +73,7 @@ public class OpenIddictMongoDbBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceStore) && service.ImplementationType == typeof(OpenIddictMongoDbResourceStore)); } @@ -90,7 +90,7 @@ public class OpenIddictMongoDbBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeStore) && service.ImplementationType == typeof(OpenIddictMongoDbScopeStore)); } @@ -107,7 +107,7 @@ public class OpenIddictMongoDbBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictSessionStore) && service.ImplementationType == typeof(OpenIddictMongoDbSessionStore)); } @@ -124,7 +124,7 @@ public class OpenIddictMongoDbBuilderTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenStore) && service.ImplementationType == typeof(OpenIddictMongoDbTokenStore)); } diff --git a/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs b/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs index 05b83e5c..ce0e7d92 100644 --- a/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs +++ b/test/OpenIddict.MongoDb.Tests/OpenIddictMongoDbExtensionsTests.cs @@ -49,23 +49,23 @@ public class OpenIddictMongoDbExtensionsTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictApplicationManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictAuthorizationManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictResourceManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictScopeManager) && service.ImplementationFactory is not null); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Scoped && + service.Lifetime is ServiceLifetime.Scoped && service.ServiceType == typeof(IOpenIddictTokenManager) && service.ImplementationFactory is not null); } @@ -82,23 +82,23 @@ public class OpenIddictMongoDbExtensionsTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Singleton && + service.Lifetime is ServiceLifetime.Singleton && service.ServiceType == typeof(IOpenIddictApplicationStore) && service.ImplementationType == typeof(OpenIddictMongoDbApplicationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Singleton && + service.Lifetime is ServiceLifetime.Singleton && service.ServiceType == typeof(IOpenIddictAuthorizationStore) && service.ImplementationType == typeof(OpenIddictMongoDbAuthorizationStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Singleton && + service.Lifetime is ServiceLifetime.Singleton && service.ServiceType == typeof(IOpenIddictResourceStore) && service.ImplementationType == typeof(OpenIddictMongoDbResourceStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Singleton && + service.Lifetime is ServiceLifetime.Singleton && service.ServiceType == typeof(IOpenIddictScopeStore) && service.ImplementationType == typeof(OpenIddictMongoDbScopeStore)); Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Singleton && + service.Lifetime is ServiceLifetime.Singleton && service.ServiceType == typeof(IOpenIddictTokenStore) && service.ImplementationType == typeof(OpenIddictMongoDbTokenStore)); } @@ -115,7 +115,7 @@ public class OpenIddictMongoDbExtensionsTests // Assert Assert.Contains(services, service => - service.Lifetime == ServiceLifetime.Singleton && + service.Lifetime is ServiceLifetime.Singleton && service.ServiceType == typeof(IOpenIddictMongoDbContext) && service.ImplementationType == typeof(OpenIddictMongoDbContext)); } diff --git a/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs b/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs index d72a54b3..41e0b540 100644 --- a/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs +++ b/test/OpenIddict.Quartz.Tests/OpenIddictQuartzExtensionsTests.cs @@ -45,7 +45,7 @@ public class OpenIddictQuartzExtensionsTests // Assert Assert.Contains(services, service => service.ServiceType == typeof(OpenIddictQuartzJob) && service.ImplementationType == typeof(OpenIddictQuartzJob) && - service.Lifetime == ServiceLifetime.Transient); + service.Lifetime is ServiceLifetime.Transient); } [Fact] @@ -63,10 +63,10 @@ public class OpenIddictQuartzExtensionsTests // Assert Assert.Single(services, service => service.ServiceType == typeof(OpenIddictQuartzJob) && service.ImplementationType == typeof(OpenIddictQuartzJob) && - service.Lifetime == ServiceLifetime.Transient); + service.Lifetime is ServiceLifetime.Transient); Assert.Single(services, service => service.ServiceType == typeof(IConfigureOptions) && service.ImplementationType == typeof(OpenIddictQuartzConfiguration) && - service.Lifetime == ServiceLifetime.Singleton); + service.Lifetime is ServiceLifetime.Singleton); } } diff --git a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs index 9a13d0cf..071bce07 100644 --- a/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs +++ b/test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs @@ -364,17 +364,17 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable .Select(static grouping => KeyValuePair.Create(grouping.Key, new StringValues([.. grouping])))); } - if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(message.Content.Headers.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase)) { - return (await message.Content!.ReadFromJsonAsync())!; + return (await message.Content.ReadFromJsonAsync())!; } - if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/html", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(message.Content.Headers.ContentType?.MediaType, "text/html", StringComparison.OrdinalIgnoreCase)) { // Note: this test client is only used with OpenIddict's ASP.NET Core or OWIN hosts, // that always return their HTTP responses encoded using UTF-8. As such, the stream // returned by ReadAsStreamAsync() is always assumed to contain UTF-8 encoded payloads. - using var stream = await message.Content!.ReadAsStreamAsync(); + using var stream = await message.Content.ReadAsStreamAsync(); using var document = await HtmlParser.ParseDocumentAsync(stream); if (document.Body is null) @@ -405,12 +405,12 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable .Select(static grouping => KeyValuePair.Create(grouping.Key, new StringValues([.. grouping])))); } - if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(message.Content.Headers.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase)) { // Note: this test client is only used with OpenIddict's ASP.NET Core or OWIN hosts, // that always return their HTTP responses encoded using UTF-8. As such, the stream // returned by ReadAsStreamAsync() is always assumed to contain UTF-8 encoded payloads. - using var stream = await message.Content!.ReadAsStreamAsync(); + using var stream = await message.Content.ReadAsStreamAsync(); using var reader = new StreamReader(stream); // Note: a dictionary is deliberately not used here to allow multiple parameters with the diff --git a/test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs b/test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs index a4fe86d4..af90279b 100644 --- a/test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs +++ b/test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs @@ -94,7 +94,7 @@ public class OpenIddictServerBuilderTests Assert.Contains(services, service => service.ServiceType == typeof(CustomHandler) && service.ImplementationInstance?.GetType() == typeof(CustomHandler) && - service.Lifetime == ServiceLifetime.Singleton); + service.Lifetime is ServiceLifetime.Singleton); } [Fact] @@ -113,7 +113,7 @@ public class OpenIddictServerBuilderTests // Assert Assert.Contains(services, service => service.ServiceType == typeof(CustomHandler) && - service.Lifetime == ServiceLifetime.Singleton); + service.Lifetime is ServiceLifetime.Singleton); } [Fact] @@ -132,7 +132,7 @@ public class OpenIddictServerBuilderTests // Assert Assert.Contains(services, service => service.ServiceType == typeof(CustomHandler) && - service.Lifetime == ServiceLifetime.Scoped); + service.Lifetime is ServiceLifetime.Scoped); } [Fact] @@ -3823,7 +3823,7 @@ public class OpenIddictServerBuilderTests return options.Value; } - private class CustomContext : BaseContext + private sealed class CustomContext : BaseContext { /// /// Creates a new instance of the class. @@ -3831,7 +3831,7 @@ public class OpenIddictServerBuilderTests public CustomContext(OpenIddictServerTransaction transaction) : base(transaction) { } } - private class CustomHandler : IOpenIddictServerHandler + private sealed class CustomHandler : IOpenIddictServerHandler { public ValueTask HandleAsync(CustomContext context) => ValueTask.CompletedTask; } diff --git a/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs b/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs index 3624237d..b8de9d76 100644 --- a/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs +++ b/test/OpenIddict.Server.Tests/OpenIddictServerExtensionsTests.cs @@ -79,7 +79,7 @@ public class OpenIddictServerExtensionsTests // Assert Assert.Contains(services, service => service.ServiceType == typeof(IOpenIddictServerDispatcher) && service.ImplementationType == typeof(OpenIddictServerDispatcher) && - service.Lifetime == ServiceLifetime.Scoped); + service.Lifetime is ServiceLifetime.Scoped); } [Fact] @@ -95,7 +95,7 @@ public class OpenIddictServerExtensionsTests // Assert Assert.Contains(services, service => service.ServiceType == typeof(IOpenIddictServerFactory) && service.ImplementationType == typeof(OpenIddictServerFactory) && - service.Lifetime == ServiceLifetime.Scoped); + service.Lifetime is ServiceLifetime.Scoped); } public static IEnumerable DefaultHandlers @@ -153,7 +153,7 @@ public class OpenIddictServerExtensionsTests // Assert Assert.Contains(services, service => service.ServiceType == type && service.ImplementationType == type && - service.Lifetime == ServiceLifetime.Singleton); + service.Lifetime is ServiceLifetime.Singleton); } [Fact] diff --git a/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs b/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs index 7105fb75..b0a6ffec 100644 --- a/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs +++ b/test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs @@ -364,17 +364,17 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable .Select(static grouping => KeyValuePair.Create(grouping.Key, new StringValues([.. grouping])))); } - if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(message.Content.Headers.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase)) { - return (await message.Content!.ReadFromJsonAsync())!; + return (await message.Content.ReadFromJsonAsync())!; } - if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/html", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(message.Content.Headers.ContentType?.MediaType, "text/html", StringComparison.OrdinalIgnoreCase)) { // Note: this test client is only used with OpenIddict's ASP.NET Core or OWIN hosts, // that always return their HTTP responses encoded using UTF-8. As such, the stream // returned by ReadAsStreamAsync() is always assumed to contain UTF-8 encoded payloads. - using var stream = await message.Content!.ReadAsStreamAsync(); + using var stream = await message.Content.ReadAsStreamAsync(); using var document = await HtmlParser.ParseDocumentAsync(stream); if (document.Body is null) @@ -405,12 +405,12 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable .Select(static grouping => KeyValuePair.Create(grouping.Key, new StringValues([.. grouping])))); } - if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(message.Content.Headers.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase)) { // Note: this test client is only used with OpenIddict's ASP.NET Core or OWIN hosts, // that always return their HTTP responses encoded using UTF-8. As such, the stream // returned by ReadAsStreamAsync() is always assumed to contain UTF-8 encoded payloads. - using var stream = await message.Content!.ReadAsStreamAsync(); + using var stream = await message.Content.ReadAsStreamAsync(); using var reader = new StreamReader(stream); // Note: a dictionary is deliberately not used here to allow multiple parameters with the diff --git a/test/OpenIddict.Validation.Tests/OpenIddictValidationBuilderTests.cs b/test/OpenIddict.Validation.Tests/OpenIddictValidationBuilderTests.cs index 09dfbec7..35fdfa7c 100644 --- a/test/OpenIddict.Validation.Tests/OpenIddictValidationBuilderTests.cs +++ b/test/OpenIddict.Validation.Tests/OpenIddictValidationBuilderTests.cs @@ -88,7 +88,7 @@ public class OpenIddictValidationBuilderTests Assert.Contains(services, service => service.ServiceType == typeof(CustomHandler) && service.ImplementationInstance?.GetType() == typeof(CustomHandler) && - service.Lifetime == ServiceLifetime.Singleton); + service.Lifetime is ServiceLifetime.Singleton); } [Fact] @@ -1113,12 +1113,12 @@ public class OpenIddictValidationBuilderTests return options.Value; } - private class CustomContext : BaseContext + private sealed class CustomContext : BaseContext { public CustomContext(OpenIddictValidationTransaction transaction) : base(transaction) { } } - private class CustomHandler : IOpenIddictValidationHandler + private sealed class CustomHandler : IOpenIddictValidationHandler { public ValueTask HandleAsync(CustomContext context) => ValueTask.CompletedTask; }