Browse Source

Replace PolySharp by the Polyfill source package and adopt ArgumentNullException.ThrowIfNull()/ArgumentException.ThrowIfNullOrEmpty()

pull/2408/head
Kévin Chalet 1 month ago
parent
commit
9797f86194
  1. 2
      .editorconfig
  2. 7
      Directory.Build.props
  3. 41
      Directory.Build.targets
  4. 144
      Directory.Packages.props
  5. 117
      gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
  6. 2
      sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj
  7. 2
      sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj
  8. 47
      sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs
  9. 1
      shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj
  10. 150
      shared/OpenIddict.Extensions/OpenIddictHelpers.cs
  11. 170
      shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
  12. 40
      src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
  13. 16
      src/OpenIddict.Abstractions/OpenIddictExtensions.cs
  14. 21
      src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs
  15. 916
      src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs
  16. 60
      src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs
  17. 15
      src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
  18. 1
      src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj
  19. 10
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs
  20. 20
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs
  21. 17
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs
  22. 2
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs
  23. 30
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs
  24. 5
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs
  25. 5
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs
  26. 110
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs
  27. 20
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs
  28. 15
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs
  29. 10
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs
  30. 16
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs
  31. 27
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs
  32. 5
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs
  33. 10
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs
  34. 5
      src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs
  35. 1
      src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj
  36. 5
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs
  37. 25
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs
  38. 66
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
  39. 53
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
  40. 50
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs
  41. 36
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs
  42. 36
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs
  43. 215
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
  44. 39
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs
  45. 5
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs
  46. 3
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs
  47. 10
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs
  48. 21
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs
  49. 1
      src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj
  50. 97
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs
  51. 20
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs
  52. 16
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs
  53. 5
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs
  54. 10
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs
  55. 118
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
  56. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs
  57. 15
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs
  58. 16
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs
  59. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs
  60. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs
  61. 30
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs
  62. 30
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs
  63. 5
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs
  64. 10
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs
  65. 25
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs
  66. 40
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  67. 132
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  68. 203
      src/OpenIddict.Client/OpenIddictClientBuilder.cs
  69. 5
      src/OpenIddict.Client/OpenIddictClientConfiguration.cs
  70. 5
      src/OpenIddict.Client/OpenIddictClientDispatcher.cs
  71. 16
      src/OpenIddict.Client/OpenIddictClientExtensions.cs
  72. 10
      src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs
  73. 210
      src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs
  74. 65
      src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs
  75. 20
      src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs
  76. 170
      src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs
  77. 10
      src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs
  78. 40
      src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs
  79. 85
      src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs
  80. 10
      src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs
  81. 40
      src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs
  82. 15
      src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs
  83. 700
      src/OpenIddict.Client/OpenIddictClientHandlers.cs
  84. 22
      src/OpenIddict.Client/OpenIddictClientHelpers.cs
  85. 5
      src/OpenIddict.Client/OpenIddictClientRetriever.cs
  86. 232
      src/OpenIddict.Client/OpenIddictClientService.cs
  87. 45
      src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs
  88. 40
      src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs
  89. 40
      src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs
  90. 50
      src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs
  91. 301
      src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
  92. 203
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  93. 160
      src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
  94. 230
      src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
  95. 10
      src/OpenIddict.Core/OpenIddictCoreBuilder.cs
  96. 16
      src/OpenIddict.Core/OpenIddictCoreExtensions.cs
  97. 4
      src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj
  98. 5
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs
  99. 16
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs
  100. 15
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs

2
.editorconfig

@ -95,7 +95,7 @@ csharp_using_directive_placement = outside_namespace
[*.{cs,vb}]
dotnet_code_quality_unused_parameters = all
dotnet_diagnostic.CA1510.severity = none
dotnet_diagnostic.CA1510.severity = suggestion
dotnet_diagnostic.CA2254.severity = none
dotnet_diagnostic.IDE0002.severity = none
dotnet_diagnostic.IDE0305.severity = none

7
Directory.Build.props

@ -16,12 +16,15 @@
<DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<SuppressSymbolPackageFormatValidation>true</SuppressSymbolPackageFormatValidation>
<EmbedAllSources>true</EmbedAllSources>
<EnableXlfLocalization>false</EnableXlfLocalization>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
<RestoreEnablePackagePruning>false</RestoreEnablePackagePruning>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
<PolyArgumentExceptions>true</PolyArgumentExceptions>
</PropertyGroup>
<PropertyGroup>
@ -207,10 +210,6 @@
<IncludeInternalExtensions Condition=" '$(IncludeInternalExtensions)' == '' ">true</IncludeInternalExtensions>
</PropertyGroup>
<PropertyGroup>
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="DynamicDependentFile" />
<ProjectCapability Include="DynamicFileNesting" />

41
Directory.Build.targets

@ -55,30 +55,24 @@
<PropertyGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">
<DefineConstants>$(DefineConstants);SUPPORTS_APPLICATION_CONFIGURATION_INITIALIZATION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_HANDLER_SELECTION_FALLBACK</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_HANDLER_TIME_PROVIDER_ARGUMENT</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHORIZATION_MIDDLEWARE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_BCL_ASYNC_ENUMERABLE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_BULK_DBSET_OPERATIONS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CHUNK_LINQ_EXTENSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_DBSET_VALUETASK_FINDASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENDPOINT_ROUTING</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENVIRONMENT_PROCESS_PATH</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HEXADECIMAL_STRING_CONVERSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_RESILIENCE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_INT32_RANDOM_NUMBER_GENERATOR_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_MULTIPLE_VALUES_IN_QUERYHELPERS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_HASHING_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_KEY_DERIVATION_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_RANDOM_NUMBER_GENERATOR_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_PEM_ENCODED_KEY_IMPORT</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_REDIRECTION_ON_SIGN_IN</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TASK_WAIT_ASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TEXT_ELEMENT_ENUMERATOR</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TIME_PROVIDER</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_VALUETASK_COMPLETED_TASK</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_WINFORMS_TASK_DIALOG</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ZLIB_COMPRESSION</DefineConstants>
</PropertyGroup>
@ -98,7 +92,6 @@
<DefineConstants>$(DefineConstants);SUPPORTS_EPHEMERAL_KEY_SETS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_RSA_KEY_CREATION_WITH_SPECIFIED_SIZE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TOHASHSET_LINQ_EXTENSION</DefineConstants>
</PropertyGroup>
<PropertyGroup
@ -107,8 +100,6 @@
<DefineConstants>$(DefineConstants);SUPPORTS_BROTLI_COMPRESSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_SERVICE_PROVIDER_IN_HTTP_MESSAGE_HANDLER_BUILDER</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_STATIC_RANDOM_NUMBER_GENERATOR_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_STREAM_MEMORY_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TIME_CONSTANT_COMPARISONS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_WEB_INTEGRATION_IN_GENERIC_HOST</DefineConstants>
</PropertyGroup>
@ -164,6 +155,19 @@
<DefineConstants>$(DefineConstants);SUPPORTS_WINDOWS_RUNTIME</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCore') Or
('$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '4.7'))) ">
<!--
Note: Polyfill only generates the OperatingSystem APIs if the System.Runtime.InteropServices.RuntimeInformation
package is referenced. Yet, this package isn't necessary on UWP and .NET Framework 4.7+ and is deliberately not
referenced by OpenIddict due to its problematic dependencies graph. To ensure the OperatingSystem APIs are
still correctly generated, the FeatureRuntimeInformation compilation flag is manually added here.
-->
<DefineConstants>$(DefineConstants);FeatureRuntimeInformation</DefineConstants>
</PropertyGroup>
<!--
Note: Entity Framework Core 2.x references System.Interactive.Async 3.x, that includes
its own IAsyncEnumerable. To work around collisions between this type and the new type
@ -219,4 +223,21 @@
<Target Name="_CalculateXbfSupport"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCore' And '$(TargetPlatformIdentifier)' == 'UAP' " />
<!--
Note: Polyfill internally references RequiredMemberAttribute without using "global::", which collides with
the type of the same name exposed by the iOS/Mac Catalyst/macOS reference assemblies. To work around that,
the RequiredMemberAttribute.cs file imported by Polyfill is excluded from compilation on these platforms.
-->
<Target Name="RemoveRequiredMemberAttribute" BeforeTargets="CoreCompile">
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And
('$(TargetPlatformIdentifier)' == 'iOS' Or
'$(TargetPlatformIdentifier)' == 'MacCatalyst' Or
'$(TargetPlatformIdentifier)' == 'macOS' ) ">
<Compile Remove="@(Compile)"
Condition=" %(Compile.NuGetPackageId) == 'Polyfill' And
'%(Compile.Filename)%(Compile.Extension)' == 'RequiredMemberAttribute.cs' " />
</ItemGroup>
</Target>
</Project>

144
Directory.Packages.props

@ -11,15 +11,117 @@
-->
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▀▄▄▀████ ▄ ██████
█▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀█ ▀▀██▀▀██▀▄█▀ ▀██
█▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄█▄▀▀▄█▄▄█ ▀▀██▄███
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▀▄▄▀████ ▄ ██
█▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀█ ▀▀██▀▀██▀▄██
█▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄█▄▀▀▄█▄▄█ ▀▀██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<ItemGroup Label="Package versions for .NET Framework 4.6.2 and higher"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '4.6.2')) ">
<ItemGroup Label="Package versions for .NET Framework 4.6.2"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.6.2')) ">
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageVersion Include="EntityFramework" Version="6.5.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="2.3.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="2.3.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.21" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.WebEncoders" Version="8.0.21" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.Net.Http.Headers" Version="2.3.4" />
<PackageVersion Include="Microsoft.Owin.Security" Version="4.2.3" />
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.17763.1000" />
<PackageVersion Include="MongoDB.Bson" Version="3.5.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.5.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.15.1" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Interactive.Async" Version="3.2.0" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<!--
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▄▄▄ ████ ▄ ██
█▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀███ ██▀▀██▀▄██
█▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄██▌▐██▄▄█ ▀▀██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<ItemGroup Label="Package versions for .NET Framework 4.7.2"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.7.2')) ">
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageVersion Include="EntityFramework" Version="6.5.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="2.3.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="2.3.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.21" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.WebEncoders" Version="8.0.21" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols" Version="8.14.0" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
<PackageVersion Include="Microsoft.Net.Http.Headers" Version="2.3.4" />
<PackageVersion Include="Microsoft.Owin.Security" Version="4.2.3" />
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.17763.1000" />
<PackageVersion Include="MongoDB.Bson" Version="3.5.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.5.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.15.1" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Interactive.Async" Version="3.2.0" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<!--
Note: the following references are exclusively used in the test projects:
-->
<PackageVersion Include="AngleSharp" Version="1.3.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.6.0" />
<PackageVersion Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.3.6" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="2.3.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Owin.Testing" Version="4.2.3" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<!--
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█████ ▀██ ██ ▄▄▄█▄▄ ▄▄████ ▄▄▄██ ▄▄▀█ ▄▄▀██ ▄▀▄ ██ ▄▄▄██ ███ ██ ▄▄▄ ██ ▄▄▀██ █▀▄████ ▄ █████▀▄▄▀██
█▀▀██ █ █ ██ ▄▄▄███ ██████ ▄▄███ ▀▀▄█ ▀▀ ██ █ █ ██ ▄▄▄██ █ █ ██ ███ ██ ▀▀▄██ ▄▀████ ▀▀ ▀█▀▀█▀▄▄▀██
█▄▄██ ██▄ ██ ▀▀▀███ ██████ █████ ██ █ ██ ██ ███ ██ ▀▀▀██▄▀▄▀▄██ ▀▀▀ ██ ██ ██ ██ ██████ ██▄▄█▄▀▀▄██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<ItemGroup Label="Package versions for .NET Framework 4.8"
Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.8.0')) ">
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageVersion Include="EntityFramework" Version="6.5.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
@ -96,10 +198,10 @@
<PackageVersion Include="WebGrease" Version="1.6.0" />
<!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" />
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
@ -143,10 +245,10 @@
<PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" />
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
@ -189,10 +291,10 @@
<PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" />
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
@ -248,10 +350,10 @@
<PackageVersion Include="Spectre.Console" Version="0.53.0" />
<!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" />
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
@ -299,10 +401,10 @@
<PackageVersion Include="System.Interactive" Version="6.0.3" />
<!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" />
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
@ -340,10 +442,10 @@
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<!--
Note: OpenIddict uses PolySharp to dynamically generate polyfills for types that are not available on
Note: OpenIddict uses Polyfill to dynamically generate polyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" />
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
<!--
@ -362,10 +464,10 @@
<PackageVersion Include="NamedPipeServerStream.NetFrameworkVersion" Version="1.1.7" />
<!--
Note: OpenIddict uses PolySharp to dynamically generate pstring?[]olyfills for types that are not available on
Note: OpenIddict uses Polyfill to dynamically generate pstring?[]olyfills for types that are not available on
some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="PolySharp" Condition=" '$(DisablePolySharp)' != 'true' " Version="1.15.0" />
<GlobalPackageReference Include="Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="9.5.0" />
</ItemGroup>
</Project>

117
gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs

@ -241,10 +241,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetClaimsIssuer(string issuer)
{
if (string.IsNullOrEmpty(issuer))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(issuer));
}
ArgumentException.ThrowIfNullOrEmpty(issuer);
return Set(registration => registration.ClaimsIssuer = issuer);
}
@ -256,10 +253,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetProviderName(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
return Set(registration => registration.ProviderName = name);
}
@ -271,10 +265,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetProviderDisplayName(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
return Set(registration => registration.ProviderDisplayName = name);
}
@ -286,10 +277,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetRegistrationId(string identifier)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return Set(registration => registration.RegistrationId = identifier);
}
@ -301,10 +289,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetClientId(string identifier)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return Set(registration => registration.ClientId = identifier);
}
@ -316,10 +301,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetClientSecret(string secret)
{
if (string.IsNullOrEmpty(secret))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0125), nameof(secret));
}
ArgumentException.ThrowIfNullOrEmpty(secret);
return Set(registration => registration.ClientSecret = secret);
}
@ -335,10 +317,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetPostLogoutRedirectUri(Uri uri)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
return Set(registration => registration.PostLogoutRedirectUri = uri);
}
@ -354,10 +333,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetPostLogoutRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentException.ThrowIfNullOrEmpty(uri);
return SetPostLogoutRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute));
}
@ -373,10 +349,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetRedirectUri(Uri uri)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
return Set(registration => registration.RedirectUri = uri);
}
@ -392,10 +365,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
public {{ provider.name }} SetRedirectUri([StringSyntax(StringSyntaxAttribute.Uri)] string uri)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentException.ThrowIfNullOrEmpty(uri);
return SetRedirectUri(new Uri(uri, UriKind.RelativeOrAbsolute));
}
@ -421,10 +391,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Add{{ setting.property_name }}(params {{ setting.clr_type }}[] {{ setting.parameter_name }})
{
if ({{ setting.parameter_name }} is null)
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
return Set(registration => registration.Get{{ provider.name }}Settings().{{ setting.property_name }}.UnionWith({{ setting.parameter_name }}));
}
@ -439,10 +406,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(ECDsaSecurityKey {{ setting.parameter_name }})
{
if ({{ setting.parameter_name }} is null)
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
if ({{ setting.parameter_name }}.PrivateKeyStatus is PrivateKeyStatus.DoesNotExist)
{
@ -524,10 +488,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(Uri {{ setting.parameter_name }})
{
if ({{ setting.parameter_name }} is null)
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
if (!{{ setting.parameter_name }}.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri({{ setting.parameter_name }}))
{
@ -547,10 +508,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string {{ setting.parameter_name }})
{
if (string.IsNullOrEmpty({{ setting.parameter_name }}))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof({{ setting.parameter_name }}));
}
ArgumentException.ThrowIfNullOrEmpty({{ setting.parameter_name }});
return Set{{ setting.property_name }}(new Uri({{ setting.parameter_name }}, UriKind.RelativeOrAbsolute));
}
@ -565,10 +523,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(X509Certificate2 {{ setting.parameter_name }})
{
if ({{ setting.parameter_name }} is null)
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
if (!{{ setting.parameter_name }}.HasPrivateKey)
{
@ -591,7 +546,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
public {{ provider.name }} Set{{ setting.property_name }}(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
=> Set{{ setting.property_name }}(assembly, resource, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
=> Set{{ setting.property_name }}(assembly, resource, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@ -613,15 +568,8 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
Assembly assembly, string resource,
string? password, X509KeyStorageFlags flags)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
ArgumentNullException.ThrowIfNull(assembly);
ArgumentException.ThrowIfNullOrEmpty(resource);
using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@ -641,7 +589,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
public {{ provider.name }} Set{{ setting.property_name }}(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
=> Set{{ setting.property_name }}(stream, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
=> Set{{ setting.property_name }}(stream, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@ -660,10 +608,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(Stream stream, string? password, X509KeyStorageFlags flags)
{
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
ArgumentNullException.ThrowIfNull(stream);
using var buffer = new MemoryStream();
stream.CopyTo(buffer);
@ -691,10 +636,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint)
{
if (string.IsNullOrEmpty(thumbprint))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
ArgumentException.ThrowIfNullOrEmpty(thumbprint);
return Set{{ setting.property_name }}(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@ -724,10 +666,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}(string thumbprint, StoreName name, StoreLocation location)
{
if (string.IsNullOrEmpty(thumbprint))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
ArgumentException.ThrowIfNullOrEmpty(thumbprint);
using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
@ -759,10 +698,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
{{~ end ~}}
public {{ provider.name }} Set{{ setting.property_name }}({{ setting.clr_type }} {{ setting.parameter_name }})
{
if ({{ setting.parameter_name }} is null)
{
throw new ArgumentNullException(nameof({{ setting.parameter_name }}));
}
ArgumentNullException.ThrowIfNull({{ setting.parameter_name }});
return Set(registration => registration.Get{{ provider.name }}Settings().{{ setting.property_name }} = {{ setting.parameter_name }});
}
@ -790,10 +726,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref=""OpenIddictClientRegistration""/> instance.</returns>
private {{ provider.name }} Set(Action<OpenIddictClientRegistration> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
configuration(Registration);
@ -973,6 +906,8 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
{
public static partial void ConfigureProvider(OpenIddictClientRegistration registration)
{
ArgumentNullException.ThrowIfNull(registration);
{{~ for provider in providers ~}}
{{~ if for.index == 0 ~}}
if (registration.ProviderType is ProviderTypes.{{ provider.name }})

2
sandbox/OpenIddict.Sandbox.AspNet.Client/OpenIddict.Sandbox.AspNet.Client.csproj

@ -7,7 +7,7 @@
<MvcBuildViews>false</MvcBuildViews>
<ImplicitUsings>disable</ImplicitUsings>
<NoWarn>CA3147</NoWarn>
<DisablePolySharp>true</DisablePolySharp>
<IncludePolyfills>false</IncludePolyfills>
</PropertyGroup>
<ItemGroup>

2
sandbox/OpenIddict.Sandbox.AspNet.Server/OpenIddict.Sandbox.AspNet.Server.csproj

@ -7,7 +7,7 @@
<MvcBuildViews>false</MvcBuildViews>
<ImplicitUsings>disable</ImplicitUsings>
<NoWarn>CA3147</NoWarn>
<DisablePolySharp>true</DisablePolySharp>
<IncludePolyfills>false</IncludePolyfills>
</PropertyGroup>
<ItemGroup>

47
sandbox/OpenIddict.Sandbox.Console.Client/InteractiveService.cs

@ -436,7 +436,7 @@ public class InteractiveService : BackgroundService
select registration)
.UseConverter(registration => registration.ProviderDisplayName!)).ProviderName!;
return WaitAsync(Task.Run(PromptAsync, cancellationToken), cancellationToken);
return Task.Run(PromptAsync, cancellationToken).WaitAsync(cancellationToken);
}
Task<(string? GrantType, string? ResponseType)> GetSelectedFlowAsync(
@ -557,7 +557,7 @@ public class InteractiveService : BackgroundService
.UseConverter(choice => choice.DisplayName)).Item1;
}
return WaitAsync(Task.Run(() => Prompt(registration, configuration), cancellationToken), cancellationToken);
return Task.Run(() => Prompt(registration, configuration), cancellationToken).WaitAsync(cancellationToken);
}
Task<string> GetSelectedGrantTypeAsync(
@ -608,7 +608,7 @@ public class InteractiveService : BackgroundService
.UseConverter(choice => choice.DisplayName)).GrantType;
}
return WaitAsync(Task.Run(() => Prompt(registration, configuration), cancellationToken), cancellationToken);
return Task.Run(() => Prompt(registration, configuration), cancellationToken).WaitAsync(cancellationToken);
}
Task<bool> AuthenticateUserInteractivelyAsync(
@ -632,7 +632,7 @@ public class InteractiveService : BackgroundService
registration.GrantTypes.Any(static type => type is not (
GrantTypes.AuthorizationCode or GrantTypes.Implicit or GrantTypes.RefreshToken))))
{
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
return Task.FromResult(true);
@ -647,7 +647,7 @@ public class InteractiveService : BackgroundService
registration.GrantTypes.Any(static type => type is not (
GrantTypes.AuthorizationCode or GrantTypes.Implicit or GrantTypes.RefreshToken))))
{
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
return Task.FromResult(true);
@ -664,7 +664,7 @@ public class InteractiveService : BackgroundService
IsSecret = false
});
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task<string> GetPasswordAsync(CancellationToken cancellationToken)
@ -675,7 +675,7 @@ public class InteractiveService : BackgroundService
IsSecret = true
});
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task<bool> RefreshTokenAsync(CancellationToken cancellationToken)
@ -688,7 +688,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task<string?> GetRequestedTokenTypeAsync(CancellationToken cancellationToken)
@ -704,7 +704,7 @@ public class InteractiveService : BackgroundService
])
.UseConverter(choice => choice.DisplayName)).TokenType;
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task<(string TokenType, string Token)> GetSubjectTokenAsync(CancellationToken cancellationToken)
@ -730,7 +730,7 @@ public class InteractiveService : BackgroundService
return (type, token);
}
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
Task<(string? TokenType, string? Token)> GetActorTokenAsync(CancellationToken cancellationToken)
@ -760,7 +760,7 @@ public class InteractiveService : BackgroundService
}));
}
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task<bool> IntrospectAccessTokenAsync(CancellationToken cancellationToken)
@ -773,7 +773,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task<bool> LogOutAsync(CancellationToken cancellationToken)
@ -785,7 +785,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
static Task<bool> RevokeAccessTokenAsync(CancellationToken cancellationToken)
@ -798,26 +798,7 @@ public class InteractiveService : BackgroundService
ShowDefaultValue = true
});
return WaitAsync(Task.Run(Prompt, cancellationToken), cancellationToken);
}
static async Task<T> WaitAsync<T>(Task<T> task, CancellationToken cancellationToken)
{
#if SUPPORTS_TASK_WAIT_ASYNC
return await task.WaitAsync(cancellationToken);
#else
var source = new TaskCompletionSource<bool>(TaskCreationOptions.None);
using (cancellationToken.Register(static state => ((TaskCompletionSource<bool>) state!).SetResult(true), source))
{
if (await Task.WhenAny(task, source.Task) == source.Task)
{
throw new OperationCanceledException(cancellationToken);
}
return await task;
}
#endif
return Task.Run(Prompt, cancellationToken).WaitAsync(cancellationToken);
}
}
}

1
shared/OpenIddict.Extensions/OpenIddict.Extensions.csproj

@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>false</IsPackable>
<DefineConstants>$(DefineConstants);FeatureValueTuple</DefineConstants>
</PropertyGroup>
<ItemGroup>

150
shared/OpenIddict.Extensions/OpenIddictHelpers.cs

@ -35,10 +35,7 @@ internal static class OpenIddictHelpers
/// </returns>
public static bool IncludesAnyFromSet<T>(IReadOnlyList<T> array, ISet<T> set)
{
if (set is null)
{
throw new ArgumentNullException(nameof(set));
}
ArgumentNullException.ThrowIfNull(set);
for (var index = 0; index < array.Count; index++)
{
@ -150,15 +147,8 @@ internal static class OpenIddictHelpers
/// <exception cref="InvalidOperationException"><paramref name="left"/> is not an absolute URI.</exception>
public static bool IsBaseOf(Uri left, Uri right)
{
if (left is null)
{
throw new ArgumentNullException(nameof(left));
}
if (right is null)
{
throw new ArgumentNullException(nameof(right));
}
ArgumentNullException.ThrowIfNull(left);
ArgumentNullException.ThrowIfNull(right);
if (left is not { IsAbsoluteUri: true })
{
@ -188,10 +178,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
public static bool IsImplicitFileUri(Uri uri)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
return uri.IsAbsoluteUri && uri.IsFile &&
!uri.OriginalString.StartsWith(uri.Scheme, StringComparison.OrdinalIgnoreCase);
@ -206,10 +193,7 @@ internal static class OpenIddictHelpers
/// <returns>The final <see cref="Uri"/> instance, with the specified parameter appended.</returns>
public static Uri AddQueryStringParameter(Uri uri, string name, string? value)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
var builder = new StringBuilder(uri.Query);
if (builder.Length > 0)
@ -238,15 +222,8 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="parameters"/> is <see langword="null"/>.</exception>
public static Uri AddQueryStringParameters(Uri uri, IReadOnlyDictionary<string, StringValues> parameters)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(uri);
ArgumentNullException.ThrowIfNull(parameters);
if (parameters.Count is 0)
{
@ -302,10 +279,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="query"/> is <see langword="null"/>.</exception>
public static IReadOnlyDictionary<string, StringValues> ParseQuery(string query)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return query.TrimStart(Separators.QuestionMark[0])
.Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries)
@ -326,10 +300,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="fragment"/> is <see langword="null"/>.</exception>
public static IReadOnlyDictionary<string, StringValues> ParseFragment(string fragment)
{
if (fragment is null)
{
throw new ArgumentNullException(nameof(fragment));
}
ArgumentNullException.ThrowIfNull(fragment);
return fragment.TrimStart(Separators.Hash[0])
.Split([Separators.Ampersand[0], Separators.Semicolon[0]], StringSplitOptions.RemoveEmptyEntries)
@ -353,15 +324,8 @@ internal static class OpenIddictHelpers
public static async ValueTask<IReadOnlyDictionary<string, StringValues>> ParseFormAsync(
Stream stream, Encoding encoding, CancellationToken cancellationToken)
{
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
if (encoding is null)
{
throw new ArgumentNullException(nameof(encoding));
}
ArgumentNullException.ThrowIfNull(stream);
ArgumentNullException.ThrowIfNull(encoding);
var reader = new FormReader(stream, encoding);
return await reader.ReadFormAsync(cancellationToken);
@ -692,7 +656,7 @@ internal static class OpenIddictHelpers
/// </exception>
public static byte[] CreateRandomArray(int size)
{
var algorithm = GetAlgorithmFromConfig() switch
using var algorithm = GetAlgorithmFromConfig() switch
{
RandomNumberGenerator result => result,
null => null,
@ -701,32 +665,13 @@ internal static class OpenIddictHelpers
// If no custom random number generator was registered, use either the static GetBytes() or
// Fill() APIs on platforms that support them or create a default instance provided by the BCL.
#if SUPPORTS_ONE_SHOT_RANDOM_NUMBER_GENERATOR_METHODS
if (algorithm is null)
{
return RandomNumberGenerator.GetBytes(size / 8);
}
#endif
var array = new byte[size / 8];
#if SUPPORTS_STATIC_RANDOM_NUMBER_GENERATOR_METHODS
if (algorithm is null)
{
RandomNumberGenerator.Fill(array);
return array;
}
#else
algorithm ??= RandomNumberGenerator.Create();
#endif
try
{
algorithm.GetBytes(array);
}
finally
{
algorithm.Dispose();
}
var array = new byte[size / 8];
algorithm.GetBytes(array);
return array;
@ -747,40 +692,30 @@ internal static class OpenIddictHelpers
/// </exception>
public static string CreateRandomString(ReadOnlySpan<string> charset, int count)
{
var algorithm = GetAlgorithmFromConfig() switch
using var algorithm = GetAlgorithmFromConfig() switch
{
RandomNumberGenerator result => result,
null => null,
var result => throw new CryptographicException(SR.FormatID0351(result.GetType().FullName))
};
try
{
var builder = new StringBuilder();
var builder = new StringBuilder();
for (var index = 0; index < count; index++)
for (var index = 0; index < count; index++)
{
// Pick a character in the specified charset by generating a random index.
builder.Append(charset[index: algorithm switch
{
// Pick a character in the specified charset by generating a random index.
builder.Append(charset[index: algorithm switch
{
#if SUPPORTS_INT32_RANDOM_NUMBER_GENERATOR_METHODS
// If no custom random number generator was registered, use
// the static GetInt32() API on platforms that support it.
null => RandomNumberGenerator.GetInt32(0, charset.Length),
#endif
// Otherwise, create a default implementation if necessary
// and use the local function that achieves the same result.
_ => GetInt32(algorithm ??= RandomNumberGenerator.Create(), 0..charset.Length)
}]);
}
// If no custom random number generator was registered, use the static GetInt32() API.
null => RandomNumberGenerator.GetInt32(0, charset.Length),
return builder.ToString();
// Otherwise, create a default implementation if necessary
// and use the local function that achieves the same result.
_ => GetInt32(algorithm, 0..charset.Length)
}]);
}
finally
{
algorithm?.Dispose();
}
return builder.ToString();
static int GetInt32(RandomNumberGenerator algorithm, Range range)
{
@ -867,32 +802,6 @@ internal static class OpenIddictHelpers
#endif
}
/// <summary>
/// Converts the specified hex-encoded <paramref name="value"/> to a byte array.
/// </summary>
/// <param name="value">The hexadecimal string.</param>
/// <returns>The byte array.</returns>
public static byte[] ConvertFromHexadecimalString(string value)
{
#if SUPPORTS_HEXADECIMAL_STRING_CONVERSION
return Convert.FromHexString(value);
#else
if ((uint) value.Length % 2 is not 0)
{
throw new FormatException(SR.GetResourceString(SR.ID0413));
}
var array = new byte[value.Length / 2];
for (var index = 0; index < value.Length; index += 2)
{
array[index / 2] = Convert.ToByte(value.Substring(index, 2), 16);
}
return array;
#endif
}
/// <summary>
/// Removes the characters that are not part of <paramref name="charset"/>
/// from the specified <paramref name="value"/> string.
@ -906,10 +815,7 @@ internal static class OpenIddictHelpers
/// <exception cref="ArgumentNullException"><paramref name="charset"/> is <see langword="null"/>.</exception>
public static string? RemoveDisallowedCharacters(string? value, IReadOnlyCollection<string> charset)
{
if (charset is null)
{
throw new ArgumentNullException(nameof(charset));
}
ArgumentNullException.ThrowIfNull(charset);
if (charset.Count is 0 || string.IsNullOrEmpty(value))
{

170
shared/OpenIddict.Extensions/OpenIddictPolyfills.cs

@ -1,170 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System.Diagnostics;
namespace OpenIddict.Extensions;
/// <summary>
/// Exposes common polyfills used by the OpenIddict assemblies.
/// </summary>
internal static class OpenIddictPolyfills
{
extension<TSource>(IEnumerable<TSource> source)
{
#if !SUPPORTS_CHUNK_LINQ_EXTENSION
/// <summary>
/// Split the elements of a sequence into chunks of size at most <paramref name="size"/>.
/// </summary>
/// <remarks>
/// Every chunk except the last will be of size <paramref name="size"/>.
/// The last chunk will contain the remaining elements and may be of a smaller size.
/// </remarks>
/// <param name="size">Maximum size of each chunk.</param>
/// <returns>
/// An <see cref="IEnumerable{T}"/> that contains the elements of the input
/// sequence split into chunks of size <paramref name="size"/>.
/// </returns>
public IEnumerable<TSource[]> Chunk(int size)
{
// Note: this polyfill was directly copied from .NET's source code:
// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Linq/src/System/Linq/Chunk.cs.
using IEnumerator<TSource> enumerator = source.GetEnumerator();
if (enumerator.MoveNext())
{
var count = Math.Min(size, 4);
int index;
do
{
var array = new TSource[count];
array[0] = enumerator.Current;
index = 1;
if (size != array.Length)
{
for (; index < size && enumerator.MoveNext(); index++)
{
if (index >= array.Length)
{
count = (int) Math.Min((uint) size, 2 * (uint) array.Length);
Array.Resize(ref array, count);
}
array[index] = enumerator.Current;
}
}
else
{
var local = array;
Debug.Assert(local.Length == size);
for (; (uint) index < (uint) local.Length && enumerator.MoveNext(); index++)
{
local[index] = enumerator.Current;
}
}
if (index != array.Length)
{
Array.Resize(ref array, index);
}
yield return array;
}
while (index >= size && enumerator.MoveNext());
}
}
#endif
#if !SUPPORTS_TOHASHSET_LINQ_EXTENSION
/// <summary>
/// Creates a new <see cref="HashSet{T}"/> instance and imports the elements present in the specified source.
/// </summary>
/// <param name="comparer">The comparer to use.</param>
/// <returns>A new <see cref="HashSet{T}"/> instance and imports the elements present in the specified source.</returns>
public HashSet<TSource> ToHashSet(IEqualityComparer<TSource>? comparer) => new(source, comparer);
#endif
}
extension(Task task)
{
#if !SUPPORTS_TASK_WAIT_ASYNC
/// <summary>
/// Waits until the specified task returns a result or the cancellation token is signaled.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
/// <exception cref="OperationCanceledException">The specified <paramref name="cancellationToken"/> is signaled.</exception>
public async Task WaitAsync(CancellationToken cancellationToken)
{
var source = new TaskCompletionSource<bool>(TaskCreationOptions.None);
using (cancellationToken.Register(static state => ((TaskCompletionSource<bool>) state!).SetResult(true), source))
{
if (await Task.WhenAny(task, source.Task) == source.Task)
{
throw new OperationCanceledException(cancellationToken);
}
await task;
}
}
#endif
}
extension<TResult>(Task<TResult> task)
{
#if !SUPPORTS_TASK_WAIT_ASYNC
/// <summary>
/// Waits until the specified task returns a result or the cancellation token is signaled.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
/// <exception cref="OperationCanceledException">The specified <paramref name="cancellationToken"/> is signaled.</exception>
public async Task<TResult> WaitAsync(CancellationToken cancellationToken)
{
var source = new TaskCompletionSource<bool>(TaskCreationOptions.None);
using (cancellationToken.Register(static state => ((TaskCompletionSource<bool>) state!).SetResult(true), source))
{
if (await Task.WhenAny(task, source.Task) == source.Task)
{
throw new OperationCanceledException(cancellationToken);
}
return await task;
}
}
#endif
}
extension(ValueTask)
{
#if !SUPPORTS_VALUETASK_COMPLETED_TASK
/// <summary>
/// Gets a task that has already completed successfully.
/// </summary>
public static ValueTask CompletedTask => default;
#endif
}
extension<TResult>(ValueTask<TResult>)
{
#if !SUPPORTS_VALUETASK_COMPLETED_TASK
/// <summary>
/// Gets a task that has already completed successfully.
/// </summary>
public static ValueTask<TResult> CompletedTask => default;
#endif
}
}

40
src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs

@ -89,10 +89,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="audiences"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddAudiencePermissions(params string[] audiences)
{
if (audiences is null)
{
throw new ArgumentNullException(nameof(audiences));
}
ArgumentNullException.ThrowIfNull(audiences);
foreach (var audience in audiences)
{
@ -110,10 +107,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddGrantTypePermissions(params string[] types)
{
if (types is null)
{
throw new ArgumentNullException(nameof(types));
}
ArgumentNullException.ThrowIfNull(types);
foreach (var type in types)
{
@ -131,10 +125,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="resources"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddResourcePermissions(params string[] resources)
{
if (resources is null)
{
throw new ArgumentNullException(nameof(resources));
}
ArgumentNullException.ThrowIfNull(resources);
foreach (var resource in resources)
{
@ -152,10 +143,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="scopes"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor AddScopePermissions(params string[] scopes)
{
if (scopes is null)
{
throw new ArgumentNullException(nameof(scopes));
}
ArgumentNullException.ThrowIfNull(scopes);
foreach (var scope in scopes)
{
@ -341,10 +329,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="audiences"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveAudiencePermissions(params string[] audiences)
{
if (audiences is null)
{
throw new ArgumentNullException(nameof(audiences));
}
ArgumentNullException.ThrowIfNull(audiences);
foreach (var audience in audiences)
{
@ -362,10 +347,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="types"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveGrantTypePermissions(params string[] types)
{
if (types is null)
{
throw new ArgumentNullException(nameof(types));
}
ArgumentNullException.ThrowIfNull(types);
foreach (var type in types)
{
@ -383,10 +365,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="resources"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveResourcePermissions(params string[] resources)
{
if (resources is null)
{
throw new ArgumentNullException(nameof(resources));
}
ArgumentNullException.ThrowIfNull(resources);
foreach (var resource in resources)
{
@ -404,10 +383,7 @@ public class OpenIddictApplicationDescriptor
/// <exception cref="ArgumentNullException"><paramref name="scopes"/> is <see langword="null"/>.</exception>
public OpenIddictApplicationDescriptor RemoveScopePermissions(params string[] scopes)
{
if (scopes is null)
{
throw new ArgumentNullException(nameof(scopes));
}
ArgumentNullException.ThrowIfNull(scopes);
foreach (var scope in scopes)
{

16
src/OpenIddict.Abstractions/OpenIddictExtensions.cs

@ -19,10 +19,7 @@ public static class OpenIddictExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictBuilder AddOpenIddict(this IServiceCollection services)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}
ArgumentNullException.ThrowIfNull(services);
return new OpenIddictBuilder(services);
}
@ -36,15 +33,8 @@ public static class OpenIddictExtensions
/// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddOpenIddict(this IServiceCollection services, Action<OpenIddictBuilder> configuration)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configuration);
configuration(services.AddOpenIddict());

21
src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs

@ -21,10 +21,7 @@ public sealed class OpenIddictConverter : JsonConverter<OpenIddictMessage>
/// <returns><see langword="true"/> if the type is supported, <see langword="false"/> otherwise.</returns>
public override bool CanConvert(Type typeToConvert)
{
if (typeToConvert is null)
{
throw new ArgumentNullException(nameof(typeToConvert));
}
ArgumentNullException.ThrowIfNull(typeToConvert);
return typeToConvert == typeof(OpenIddictMessage) ||
typeToConvert == typeof(OpenIddictRequest) ||
@ -40,10 +37,7 @@ public sealed class OpenIddictConverter : JsonConverter<OpenIddictMessage>
/// <returns>The deserialized <see cref="OpenIddictMessage"/> instance.</returns>
public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (typeToConvert is null)
{
throw new ArgumentNullException(nameof(typeToConvert));
}
ArgumentNullException.ThrowIfNull(typeToConvert);
using var document = JsonDocument.ParseValue(ref reader);
@ -61,15 +55,8 @@ public sealed class OpenIddictConverter : JsonConverter<OpenIddictMessage>
/// <param name="options">The JSON serializer options.</param>
public override void Write(Utf8JsonWriter writer, OpenIddictMessage value, JsonSerializerOptions options)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(value);
value.WriteTo(writer);
}

916
src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs

File diff suppressed because it is too large

60
src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs

@ -75,10 +75,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(JsonObject parameters)
{
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@ -106,10 +103,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
{
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@ -130,10 +124,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, string?>> parameters)
{
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters.GroupBy(parameter => parameter.Key))
{
@ -163,10 +154,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, ImmutableArray<string?>?>> parameters)
{
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@ -196,10 +184,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(IEnumerable<KeyValuePair<string, StringValues>> parameters)
{
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);
foreach (var parameter in parameters)
{
@ -229,10 +214,7 @@ public class OpenIddictMessage
/// <remarks>Parameters with a null or empty key are always ignored.</remarks>
public OpenIddictMessage(NameValueCollection parameters)
{
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);
for (var index = 0; index < parameters.AllKeys.Length; index++)
{
@ -286,10 +268,7 @@ public class OpenIddictMessage
/// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage AddParameter(string name, OpenIddictParameter value)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
if (Parameters.ContainsKey(name))
{
@ -323,10 +302,7 @@ public class OpenIddictMessage
/// <returns><see langword="true"/> if the parameter is present, <see langword="false"/> otherwise.</returns>
public bool HasParameter(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
return Parameters.ContainsKey(name);
}
@ -338,10 +314,7 @@ public class OpenIddictMessage
/// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage RemoveParameter(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
Parameters.Remove(name);
@ -357,10 +330,7 @@ public class OpenIddictMessage
/// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage SetParameter(string name, OpenIddictParameter? value)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
// If the parameter value is null or empty, remove the corresponding entry from the collection.
if (value is null || OpenIddictParameter.IsNullOrEmpty(value.GetValueOrDefault()))
@ -384,10 +354,7 @@ public class OpenIddictMessage
/// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns>
public bool TryGetParameter(string name, out OpenIddictParameter value)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0190), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
return Parameters.TryGetValue(name, out value);
}
@ -445,10 +412,7 @@ public class OpenIddictMessage
/// <param name="writer">The UTF-8 JSON writer.</param>
public void WriteTo(Utf8JsonWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
ArgumentNullException.ThrowIfNull(writer);
writer.WriteStartObject();

15
src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs

@ -673,10 +673,7 @@ public readonly struct OpenIddictParameter : IEquatable<OpenIddictParameter>
/// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns>
public bool TryGetNamedParameter(string name, out OpenIddictParameter value)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0192), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
var result = _value switch
{
@ -709,10 +706,7 @@ public readonly struct OpenIddictParameter : IEquatable<OpenIddictParameter>
/// <returns><see langword="true"/> if the parameter could be found, <see langword="false"/> otherwise.</returns>
public bool TryGetUnnamedParameter(int index, out OpenIddictParameter value)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index), SR.GetResourceString(SR.ID0193));
}
ArgumentOutOfRangeException.ThrowIfNegative(index);
var result = _value switch
{
@ -746,10 +740,7 @@ public readonly struct OpenIddictParameter : IEquatable<OpenIddictParameter>
/// <param name="writer">The UTF-8 JSON writer.</param>
public void WriteTo(Utf8JsonWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
ArgumentNullException.ThrowIfNull(writer);
switch (_value)
{

1
src/OpenIddict.AspNetCore/OpenIddict.AspNetCore.csproj

@ -4,6 +4,7 @@
<TargetFrameworks>$(NetFrameworkTargetFrameworks);$(NetCoreTargetFrameworks)</TargetFrameworks>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
<IncludePolyfills>false</IncludePolyfills>
<IncludeInternalExtensions>false</IncludeInternalExtensions>
</PropertyGroup>

10
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreBuilder.cs

@ -38,10 +38,7 @@ public sealed class OpenIddictClientAspNetCoreBuilder
/// <returns>The <see cref="OpenIddictClientAspNetCoreBuilder"/> instance.</returns>
public OpenIddictClientAspNetCoreBuilder Configure(Action<OpenIddictClientAspNetCoreOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@ -74,10 +71,7 @@ public sealed class OpenIddictClientAspNetCoreBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientAspNetCoreBuilder AddForwardedAuthenticationScheme(string provider, string? caption)
{
if (string.IsNullOrEmpty(provider))
{
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
ArgumentException.ThrowIfNullOrEmpty(provider);
return Configure(options => options.ForwardedAuthenticationSchemes.Add(
new AuthenticationScheme(provider, caption, typeof(OpenIddictClientAspNetCoreForwarder))));

20
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreConfiguration.cs

@ -31,10 +31,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/>
public void Configure(AuthenticationOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// If a handler was already registered and the type doesn't correspond to the OpenIddict handler, throw an exception.
if (options.SchemeMap.TryGetValue(OpenIddictClientAspNetCoreDefaults.AuthenticationScheme, out var builder) &&
@ -64,10 +61,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientAspNetCoreOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
if (!options.DisableAutomaticAuthenticationSchemeForwarding)
{
@ -102,10 +96,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/>
public void Configure(OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict ASP.NET Core client components.
options.Handlers.AddRange(OpenIddictClientAspNetCoreHandlers.DefaultHandlers);
@ -114,10 +105,7 @@ public sealed class OpenIddictClientAspNetCoreConfiguration : IConfigureOptions<
/// <inheritdoc/>
public void PostConfigure(string? name, AuthenticationOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
if (!TryValidate(options.SchemeMap, options.DefaultAuthenticateScheme) ||
!TryValidate(options.SchemeMap, options.DefaultScheme) ||

17
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs

@ -24,10 +24,7 @@ public static class OpenIddictClientAspNetCoreExtensions
/// <returns>The <see cref="OpenIddictClientAspNetCoreBuilder"/> instance.</returns>
public static OpenIddictClientAspNetCoreBuilder UseAspNetCore(this OpenIddictClientBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddAuthentication();
@ -73,15 +70,9 @@ public static class OpenIddictClientAspNetCoreExtensions
public static OpenIddictClientBuilder UseAspNetCore(
this OpenIddictClientBuilder builder, Action<OpenIddictClientAspNetCoreBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseAspNetCore());

2
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandler.cs

@ -29,7 +29,7 @@ public sealed class OpenIddictClientAspNetCoreHandler : AuthenticationHandler<Op
/// <summary>
/// Creates a new instance of the <see cref="OpenIddictClientAspNetCoreHandler"/> class.
/// </summary>
#if SUPPORTS_TIME_PROVIDER
#if SUPPORTS_AUTHENTICATION_HANDLER_TIME_PROVIDER_ARGUMENT
public OpenIddictClientAspNetCoreHandler(
IOpenIddictClientDispatcher dispatcher,
IOpenIddictClientFactory factory,

30
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlerFilters.cs

@ -29,10 +29,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableErrorPassthrough);
}
@ -46,10 +43,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetHttpRequest() is not null);
}
@ -69,10 +63,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnablePostLogoutRedirectionEndpointPassthrough);
}
@ -92,10 +83,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableRedirectionEndpointPassthrough);
}
@ -114,10 +102,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableStatusCodePagesIntegration);
}
@ -136,10 +121,7 @@ public static class OpenIddictClientAspNetCoreHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!_options.CurrentValue.DisableTransportSecurityRequirement);
}

5
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Authentication.cs

@ -61,10 +61,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.

5
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.Session.cs

@ -61,10 +61,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.

110
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs

@ -95,10 +95,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -149,10 +146,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -194,10 +188,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -239,10 +230,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -319,10 +307,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.GrantType is GrantTypes.DeviceCode)
{
@ -353,10 +338,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (!string.IsNullOrEmpty(context.Nonce))
{
@ -394,10 +376,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -511,10 +490,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.GrantType is GrantTypes.DeviceCode)
{
@ -546,10 +522,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -656,10 +629,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -695,10 +665,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an explicit response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.ResponseMode))
@ -795,10 +762,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: using a correlation cookie serves as an injection/antiforgery protection as the request
// will always be rejected if a cookie corresponding to the request forgery protection claim
@ -881,10 +845,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -981,10 +942,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -1027,10 +985,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: using a correlation cookie serves as an injection/antiforgery protection as the request
// will always be rejected if a cookie corresponding to the request forgery protection claim
@ -1115,10 +1070,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.SkipRequest();
@ -1146,10 +1098,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -1189,10 +1138,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -1233,10 +1179,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Response is not null, SR.GetResourceString(SR.ID4007));
@ -1273,10 +1216,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -1329,10 +1269,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -1403,10 +1340,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.Logger.LogInformation(6145, SR.GetResourceString(SR.ID6145));
context.HandleRequest();

20
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHelpers.cs

@ -21,10 +21,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="HttpRequest"/> instance or <see langword="null"/> if it couldn't be found.</returns>
public static HttpRequest? GetHttpRequest(this OpenIddictClientTransaction transaction)
{
if (transaction is null)
{
throw new ArgumentNullException(nameof(transaction));
}
ArgumentNullException.ThrowIfNull(transaction);
if (!transaction.Properties.TryGetValue(typeof(HttpRequest).FullName!, out object? property))
{
@ -46,10 +43,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="OpenIddictClientEndpointType"/>.</returns>
public static OpenIddictClientEndpointType GetOpenIddictClientEndpointType(this HttpContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.EndpointType ?? default;
}
@ -61,10 +55,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="OpenIddictRequest"/> instance or <see langword="null"/> if it couldn't be found.</returns>
public static OpenIddictRequest? GetOpenIddictClientRequest(this HttpContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.Request;
}
@ -76,10 +67,7 @@ public static class OpenIddictClientAspNetCoreHelpers
/// <returns>The <see cref="OpenIddictResponse"/> instance or <see langword="null"/> if it couldn't be found.</returns>
public static OpenIddictResponse? GetOpenIddictClientResponse(this HttpContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return context.Features.Get<OpenIddictClientAspNetCoreFeature>()?.Transaction?.Response;
}

15
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionBuilder.cs

@ -37,10 +37,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns>
public OpenIddictClientDataProtectionBuilder Configure(Action<OpenIddictClientDataProtectionOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@ -55,10 +52,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns>
public OpenIddictClientDataProtectionBuilder UseDataProtectionProvider(IDataProtectionProvider provider)
{
if (provider is null)
{
throw new ArgumentNullException(nameof(provider));
}
ArgumentNullException.ThrowIfNull(provider);
return Configure(options => options.DataProtectionProvider = provider);
}
@ -70,10 +64,7 @@ public sealed class OpenIddictClientDataProtectionBuilder
/// <returns>The <see cref="OpenIddictClientDataProtectionBuilder"/> instance.</returns>
public OpenIddictClientDataProtectionBuilder UseFormatter(IOpenIddictClientDataProtectionFormatter formatter)
{
if (formatter is null)
{
throw new ArgumentNullException(nameof(formatter));
}
ArgumentNullException.ThrowIfNull(formatter);
return Configure(options => options.Formatter = formatter);
}

10
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionConfiguration.cs

@ -29,10 +29,7 @@ public sealed class OpenIddictClientDataProtectionConfiguration : IConfigureOpti
/// <inheritdoc/>
public void Configure(OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict Data Protection server components.
options.Handlers.AddRange(OpenIddictClientDataProtectionHandlers.DefaultHandlers);
@ -41,10 +38,7 @@ public sealed class OpenIddictClientDataProtectionConfiguration : IConfigureOpti
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientDataProtectionOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
options.DataProtectionProvider ??= _dataProtectionProvider;
}

16
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs

@ -25,10 +25,7 @@ public static class OpenIddictClientDataProtectionExtensions
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public static OpenIddictClientDataProtectionBuilder UseDataProtection(this OpenIddictClientBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddDataProtection();
@ -60,15 +57,8 @@ public static class OpenIddictClientDataProtectionExtensions
public static OpenIddictClientBuilder UseDataProtection(
this OpenIddictClientBuilder builder, Action<OpenIddictClientDataProtectionBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseDataProtection());

27
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionFormatter.cs

@ -20,10 +20,7 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
{
public ClaimsPrincipal ReadToken(BinaryReader reader)
{
if (reader is null)
{
throw new ArgumentNullException(nameof(reader));
}
ArgumentNullException.ThrowIfNull(reader);
var (principal, properties) = Read(reader);
@ -182,15 +179,8 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
public void WriteToken(BinaryWriter writer, ClaimsPrincipal principal)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
if (principal is null)
{
throw new ArgumentNullException(nameof(principal));
}
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(principal);
var properties = new Dictionary<string, string>();
@ -293,15 +283,8 @@ public sealed class OpenIddictClientDataProtectionFormatter : IOpenIddictClientD
static void WriteClaim(BinaryWriter writer, Claim claim)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
if (claim is null)
{
throw new ArgumentNullException(nameof(claim));
}
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(claim);
WriteWithDefault(writer, claim.Type, claim.Subject?.NameClaimType ?? ClaimsIdentity.DefaultNameClaimType);
writer.Write(claim.Value);

5
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlerFilters.cs

@ -20,10 +20,7 @@ public static class OpenIddictClientDataProtectionHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.TokenFormat is TokenFormats.Private.DataProtection);
}

10
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionHandlers.Protection.cs

@ -176,10 +176,7 @@ public static partial class OpenIddictClientDataProtectionHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// ASP.NET Core Data Protection can be used to format certain types of tokens in lieu
// of the default token format (typically, JSON Web Token). By default, Data Protection
@ -223,10 +220,7 @@ public static partial class OpenIddictClientDataProtectionHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an access token was already attached by another handler, don't overwrite it.
if (!string.IsNullOrEmpty(context.Token))

5
src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs

@ -74,10 +74,7 @@ public sealed class OpenIddictClientOwinBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientOwinBuilder AddForwardedAuthenticationType(string provider, string? caption)
{
if (string.IsNullOrEmpty(provider))
{
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
ArgumentException.ThrowIfNullOrEmpty(provider);
return Configure(options => options.ForwardedAuthenticationTypes.Add(new AuthenticationDescription
{

1
src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj

@ -30,6 +30,7 @@
allow loading dependencies that are not strong-named), the warning can be safely disabled.
-->
<NoWarn>$(NoWarn);CS8002</NoWarn>
<DefineConstants>$(DefineConstants);FeatureRuntimeInformation;FeatureValueTuple</DefineConstants>
</PropertyGroup>
<PropertyGroup>

5
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivation.cs

@ -21,10 +21,7 @@ public sealed class OpenIddictClientSystemIntegrationActivation
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is <see langword="null"/>.</exception>
public OpenIddictClientSystemIntegrationActivation(Uri uri)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{

25
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs

@ -40,10 +40,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
/// <returns>The <see cref="OpenIddictClientSystemIntegrationBuilder"/>.</returns>
public OpenIddictClientSystemIntegrationBuilder Configure(Action<OpenIddictClientSystemIntegrationOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@ -209,10 +206,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetApplicationDiscriminator(string discriminator)
{
if (string.IsNullOrEmpty(discriminator))
{
throw new ArgumentException(SR.FormatID0366(nameof(discriminator)), nameof(discriminator));
}
ArgumentException.ThrowIfNullOrEmpty(discriminator);
return Configure(options => options.ApplicationDiscriminator = discriminator);
}
@ -226,10 +220,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetInstanceIdentifier(string identifier)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return Configure(options => options.InstanceIdentifier = identifier);
}
@ -243,10 +234,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemIntegrationBuilder SetPipeName(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
return Configure(options => options.PipeName = name);
}
@ -270,10 +258,7 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
[EditorBrowsable(EditorBrowsableState.Advanced), SupportedOSPlatform("windows")]
public OpenIddictClientSystemIntegrationBuilder SetPipeSecurity(PipeSecurity security)
{
if (security is null)
{
throw new ArgumentNullException(nameof(security));
}
ArgumentNullException.ThrowIfNull(security);
return Configure(options => options.PipeSecurity = security);
}

66
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs

@ -7,7 +7,6 @@
using System.ComponentModel;
using System.IO.Pipes;
using System.Net;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
@ -38,10 +37,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
/// <inheritdoc/>
public void Configure(OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict client system integration components.
options.Handlers.AddRange(OpenIddictClientSystemIntegrationHandlers.DefaultHandlers);
@ -53,10 +49,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// If no explicit client URI was set, default to the static "http://localhost/" address, which is
// adequate for a native/mobile client and points to the embedded web server when it is enabled.
@ -66,18 +59,15 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientSystemIntegrationOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// Ensure the operating system is supported.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
// Ensure the operating system version is supported.
if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
(OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
OperatingSystem.IsLinux() ||
(OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
(OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
(OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
@ -87,37 +77,19 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
// is used to prevent the generic/non-OS specific TFM from being used as launching the system
// browser cannot be done using Process.Start() and requires using OS-specific APIs that are
// not available on the portable version of the OpenIddict.Client.SystemIntegration package.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")))
if (OperatingSystem.IsAndroid())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
#if !SUPPORTS_UIKIT
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) ||
RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")))
if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
// Ensure the operating system version is supported.
if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
(OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
(OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
(OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
(OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !IsWindowsVersionAtLeast(7))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#endif
#pragma warning disable CA1416
// If explicitly set, ensure the specified authentication mode is supported.
if (options.AuthenticationMode is ASWebAuthenticationSession && !IsASWebAuthenticationSessionSupported())
@ -141,10 +113,8 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
IsASWebAuthenticationSessionSupported() ? ASWebAuthenticationSession :
IsCustomTabsIntentSupported() ? CustomTabsIntent : SystemBrowser;
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (!OperatingSystem.IsAndroid() && !OperatingSystem.IsIOS() &&
!OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacOS())
{
options.EnableActivationHandling ??= true;
options.EnableActivationRedirection ??= true;
@ -189,13 +159,13 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
// Note: on Windows, the name is deliberately prefixed with "LOCAL\" to support
// partial trust/sandboxed applications that are executed in an AppContainer
// and cannot communicate with applications outside the sandbox container.
options.PipeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
options.PipeName = OperatingSystem.IsWindows() ?
@$"LOCAL\{options.ApplicationDiscriminator}" :
options.ApplicationDiscriminator;
}
#if SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION
if (options.PipeOptions is null && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (options.PipeOptions is null && !OperatingSystem.IsWindows())
{
// Note: the CurrentUserOnly option is also supported on Windows, but is less
// flexible than using a PipeSecurity object (e.g cross-process communication
@ -214,11 +184,11 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
// between elevated and non-elevated processes. Note: if the process executes
// inside an AppContainer, don't override the default OS pipe security policy
// to allow all applications with the same identity to access the named pipe.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && options.PipeSecurity is null)
if (OperatingSystem.IsWindows() && options.PipeSecurity is null)
{
using var identity = WindowsIdentity.GetCurrent(TokenAccessLevels.Query);
if (!IsWindowsVersionAtLeast(10, 0, 10240) || !HasAppContainerToken(identity))
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 10240) || !HasAppContainerToken(identity))
{
options.PipeSecurity = new PipeSecurity();
options.PipeSecurity.SetOwner(identity.User!);

53
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs

@ -4,7 +4,6 @@
* the license and the contributors participating to this project.
*/
using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
@ -26,18 +25,15 @@ public static class OpenIddictClientSystemIntegrationExtensions
/// <returns>The <see cref="OpenIddictClientSystemIntegrationBuilder"/>.</returns>
public static OpenIddictClientSystemIntegrationBuilder UseSystemIntegration(this OpenIddictClientBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
// Ensure the operating system is supported.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
// Ensure the operating system version is supported.
if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
(OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
OperatingSystem.IsLinux() ||
(OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
(OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
(OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
@ -47,37 +43,19 @@ public static class OpenIddictClientSystemIntegrationExtensions
// is used to prevent the generic/non-OS specific TFM from being used as launching the system
// browser cannot be done using Process.Start() and requires using OS-specific APIs that are
// not available on the portable version of the OpenIddict.Client.SystemIntegration package.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")))
if (OperatingSystem.IsAndroid())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
#if !SUPPORTS_UIKIT
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) ||
RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")))
if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
// Ensure the operating system version is supported.
if ((OperatingSystem.IsAndroid() && !OperatingSystem.IsAndroidVersionAtLeast(21)) ||
(OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(12)) ||
(OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacCatalystVersionAtLeast(13, 1)) ||
(OperatingSystem.IsMacOS() && !OperatingSystem.IsMacOSVersionAtLeast(10, 15)) ||
(OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(7)))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !IsWindowsVersionAtLeast(7))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#endif
// Note: the OpenIddict activation handler service is deliberately registered as early as possible to
// ensure protocol activations can be handled before another service can stop the initialization of the
// application (e.g Dapplo.Microsoft.Extensions.Hosting.AppServices relies on an IHostedService to implement
@ -142,15 +120,8 @@ public static class OpenIddictClientSystemIntegrationExtensions
public static OpenIddictClientBuilder UseSystemIntegration(
this OpenIddictClientBuilder builder, Action<OpenIddictClientSystemIntegrationBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseSystemIntegration());

50
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs

@ -30,10 +30,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES
if (IsASWebAuthenticationSessionSupported())
@ -61,10 +58,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!string.IsNullOrEmpty(context.Nonce));
}
@ -83,10 +77,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (IsCustomTabsIntentSupported())
@ -118,10 +109,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(_options.CurrentValue.EnableEmbeddedWebServer is true);
}
@ -135,10 +123,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetHttpListenerContext() is not null);
}
@ -152,10 +137,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(Environment.UserInteractive);
}
@ -170,10 +152,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetPlatformCallback() is not null);
}
@ -187,10 +166,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.Transaction.GetProtocolActivation() is not null);
}
@ -210,10 +186,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (!context.Transaction.Properties.TryGetValue(
typeof(OpenIddictClientSystemIntegrationAuthenticationMode).FullName!, out var result) ||
@ -240,10 +213,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
if (IsWebAuthenticationBrokerSupported())

36
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs

@ -5,7 +5,6 @@
*/
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using Microsoft.Extensions.Primitives;
@ -99,10 +98,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.RedirectUri) ||
@ -322,10 +318,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (string.IsNullOrEmpty(context.RedirectUri))
@ -398,10 +391,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
#pragma warning restore CS1998
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
if (string.IsNullOrEmpty(context.RedirectUri))
@ -543,10 +533,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var uri = OpenIddictHelpers.AddQueryStringParameters(
uri: new Uri(context.AuthorizationEndpoint, UriKind.Absolute),
@ -554,7 +541,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
static parameter => parameter.Key,
static parameter => (StringValues) parameter.Value));
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
// Note: on Windows, multiple application models exist and must be supported to cover most scenarios:
//
@ -612,13 +599,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
return;
}
#endif
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && await TryLaunchBrowserWithOpenAsync(uri))
if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri))
{
context.HandleRequest();
return;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && await TryLaunchBrowserWithXdgOpenAsync(uri))
if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri))
{
context.HandleRequest();
return;
@ -648,10 +635,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ApplyRedirectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -671,11 +655,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
_ => "Authentication failed. Please return to the application."
});
#if SUPPORTS_STREAM_MEMORY_METHODS
await response.OutputStream.WriteAsync(buffer);
#else
await response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
#endif
await response.OutputStream.FlushAsync();
context.HandleRequest();

36
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs

@ -5,7 +5,6 @@
*/
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using Microsoft.Extensions.Primitives;
@ -99,10 +98,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri) ||
@ -322,10 +318,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
@ -398,10 +391,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
#pragma warning restore CS1998
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
@ -543,10 +533,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var uri = OpenIddictHelpers.AddQueryStringParameters(
uri: new Uri(context.EndSessionEndpoint, UriKind.Absolute),
@ -554,7 +541,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
static parameter => parameter.Key,
static parameter => (StringValues) parameter.Value));
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
// Note: on Windows, multiple application models exist and must be supported to cover most scenarios:
//
@ -612,13 +599,13 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
return;
}
#endif
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && await TryLaunchBrowserWithOpenAsync(uri))
if (OperatingSystem.IsMacOS() && await TryLaunchBrowserWithOpenAsync(uri))
{
context.HandleRequest();
return;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && await TryLaunchBrowserWithXdgOpenAsync(uri))
if (OperatingSystem.IsLinux() && await TryLaunchBrowserWithXdgOpenAsync(uri))
{
context.HandleRequest();
return;
@ -648,10 +635,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ApplyPostLogoutRedirectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -671,11 +655,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
_ => "Logout failed. Please return to the application."
});
#if SUPPORTS_STREAM_MEMORY_METHODS
await response.OutputStream.WriteAsync(buffer);
#else
await response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
#endif
await response.OutputStream.FlushAsync();
context.HandleRequest();

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

@ -108,10 +108,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// When using the OpenIddict client system integration, requests can originate from multiple sources:
//
@ -177,10 +174,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
(context.BaseUri, context.RequestUri) = context.Transaction.GetProtocolActivation() switch
{
@ -215,10 +209,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
(context.BaseUri, context.RequestUri) = context.Transaction.GetPlatformCallback() switch
{
@ -254,10 +245,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If the base or request URIs couldn't be resolved, don't try to infer the endpoint type.
if (context is not { BaseUri.IsAbsoluteUri: true, RequestUri.IsAbsoluteUri: true })
@ -332,10 +320,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -377,10 +362,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -430,10 +412,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -520,10 +499,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Transaction.GetProtocolActivation() is not { ActivationUri: Uri uri })
{
@ -578,10 +554,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Transaction.GetPlatformCallback() is not OpenIddictClientSystemIntegrationPlatformCallback callback)
{
@ -624,10 +597,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -721,10 +691,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -767,10 +734,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -813,10 +777,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -860,10 +821,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -918,10 +876,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -1002,10 +957,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1053,10 +1005,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1101,10 +1050,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1148,10 +1094,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1195,10 +1138,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1242,10 +1182,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1288,10 +1225,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1336,10 +1270,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1383,10 +1314,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1430,10 +1358,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1477,10 +1402,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1522,10 +1444,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1569,10 +1488,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1611,10 +1527,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(!string.IsNullOrEmpty(context.Nonce), SR.GetResourceString(SR.ID4019));
@ -1649,10 +1562,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.BaseUri ??= context.Options.ClientUri;
@ -1692,10 +1602,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If the redirect_uri uses a loopback host/IP as the authority and doesn't include a non-default port,
// determine whether the embedded web server is running: if so, override the port in the redirect_uri
@ -1747,10 +1654,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an explicit response type was specified, don't overwrite it.
if (!string.IsNullOrEmpty(context.ResponseMode))
@ -1931,10 +1835,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -1976,10 +1877,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.Nonce))
{
@ -2020,10 +1918,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.BaseUri ??= context.Options.ClientUri;
@ -2062,10 +1957,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If the post_logout_redirect_uri uses a loopback host/IP as the authority and doesn't include a non-default port,
// determine whether the embedded web server is running: if so, override the port in the post_logout_redirect_uri
@ -2113,10 +2005,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -2158,10 +2047,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (string.IsNullOrEmpty(context.Nonce))
{
@ -2211,10 +2097,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessErrorContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Try to resolve the authentication context from the transaction, if available.
var notification = context.Transaction.GetProperty<ProcessAuthenticationContext>(
@ -2262,10 +2145,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -2305,10 +2185,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to HTTP listener requests. If the HTTP context cannot be resolved,
// this may indicate that the request was incorrectly processed by another server stack.
@ -2345,10 +2222,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// For both protocol activations (initial or redirected) and web-view-like results,
// no proper response can be generated and eventually displayed to the user. In this
@ -2381,10 +2255,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// For both protocol activations (initial or redirected) and web-view-like results,
// no proper response can be generated and eventually displayed to the user. In this

39
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs

@ -68,38 +68,6 @@ public static class OpenIddictClientSystemIntegrationHelpers
public static HttpListenerContext? GetHttpListenerContext(this OpenIddictClientTransaction transaction)
=> transaction.GetProperty<HttpListenerContext>(typeof(HttpListenerContext).FullName!);
/// <summary>
/// Determines whether the current Windows version
/// is greater than or equals to the specified version.
/// </summary>
/// <returns>
/// <see langword="true"/> if the current Windows version is greater than
/// or equals to the specified version, <see langword="false"/> otherwise.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SupportedOSPlatformGuard("windows")]
internal static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
{
#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
return OperatingSystem.IsWindowsVersionAtLeast(major, minor, build, revision);
#else
if (Environment.OSVersion.Platform is PlatformID.Win32NT &&
Environment.OSVersion.Version >= new Version(major, minor, build, revision))
{
return true;
}
// Note: on older versions of .NET, Environment.OSVersion.Version is known to be affected by
// the compatibility shims used by Windows 10+ when the application doesn't have a manifest
// that explicitly indicates it's compatible with Windows 10 and higher. To avoid that, a
// second pass using RuntimeInformation.OSDescription (that calls NtDll.RtlGetVersion() under
// the hood) is made. Note: no version is returned on UWP due to the missing Win32 API.
return RuntimeInformation.OSDescription.StartsWith("Microsoft Windows ", StringComparison.OrdinalIgnoreCase) &&
RuntimeInformation.OSDescription["Microsoft Windows ".Length..] is string value &&
Version.TryParse(value, out Version? version) && version >= new Version(major, minor, build, revision);
#endif
}
/// <summary>
/// Determines whether the ASWebAuthenticationSession API is supported on this platform.
/// </summary>
@ -144,7 +112,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
// oldest supported version in the package, it is also used for the runtime check.
internal static bool IsWindowsRuntimeSupported()
#if SUPPORTS_WINDOWS_RUNTIME
=> IsWindowsVersionAtLeast(10, 0, 17763);
=> OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17763);
#else
=> false;
#endif
@ -227,10 +195,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[SupportedOSPlatform("windows10.0.10240")]
internal static unsafe bool HasAppContainerToken(WindowsIdentity identity)
{
if (identity is null)
{
throw new ArgumentNullException(nameof(identity));
}
ArgumentNullException.ThrowIfNull(identity);
int* buffer = stackalloc int[1];

5
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHttpListener.cs

@ -8,7 +8,6 @@ using System.ComponentModel;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@ -146,7 +145,7 @@ public sealed class OpenIddictClientSystemIntegrationHttpListener : BackgroundSe
// non-Windows operating systems) and doesn't require running the application
// as an administrator or adding a namespace reservation/ACL rule on Windows.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
// On Windows 10 1511 and higher, listening on 127.0.0.1 and ::1 is preferred
// to localhost as it allows ignoring requests that are sent by other machines
@ -154,7 +153,7 @@ public sealed class OpenIddictClientSystemIntegrationHttpListener : BackgroundSe
// configured to reject such requests) without requiring administrator rights.
//
// See https://www.rfc-editor.org/rfc/rfc8252#section-8.3 for more information.
if (IsWindowsVersionAtLeast(10, 0, 10586))
if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 10586))
{
if (Socket.OSSupportsIPv4)
{

3
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs

@ -6,7 +6,6 @@
using System.ComponentModel;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@ -131,7 +130,7 @@ public sealed class OpenIddictClientSystemIntegrationPipeListener : BackgroundSe
static NamedPipeServerStream CreatePipeServerStream(OpenIddictClientSystemIntegrationOptions options)
// Note: the ACL-based PipeSecurity class is only supported on Windows. On other operating systems,
// PipeOptions.CurrentUserOnly can be used as an alternative, but only for TFMs that implement it.
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
=> OperatingSystem.IsWindows() ?
#if SUPPORTS_NAMED_PIPE_CONSTRUCTOR_WITH_ACL
new NamedPipeServerStream(
#elif SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL

10
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPlatformCallback.cs

@ -25,20 +25,14 @@ public sealed class OpenIddictClientSystemIntegrationPlatformCallback
public OpenIddictClientSystemIntegrationPlatformCallback(
Uri uri, IReadOnlyDictionary<string, OpenIddictParameter> parameters)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0144), nameof(uri));
}
if (parameters is null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);
CallbackUri = uri;
Parameters = parameters.ToImmutableDictionary();

21
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs

@ -53,10 +53,7 @@ public sealed class OpenIddictClientSystemIntegrationService
[EditorBrowsable(EditorBrowsableState.Advanced)]
public Task HandleCustomTabsIntentAsync(Intent intent, CancellationToken cancellationToken = default)
{
if (intent is null)
{
throw new ArgumentNullException(nameof(intent));
}
ArgumentNullException.ThrowIfNull(intent);
if (intent.Data is null)
{
@ -139,10 +136,7 @@ public sealed class OpenIddictClientSystemIntegrationService
/// <exception cref="ArgumentNullException"><paramref name="property"/> is <see langword="null"/>.</exception>
private async Task HandleRequestAsync<TProperty>(TProperty property, CancellationToken cancellationToken) where TProperty : class
{
if (property is null)
{
throw new ArgumentNullException(nameof(property));
}
ArgumentNullException.ThrowIfNull(property);
cancellationToken.ThrowIfCancellationRequested();
@ -188,15 +182,8 @@ public sealed class OpenIddictClientSystemIntegrationService
OpenIddictClientSystemIntegrationActivation activation,
string identifier, CancellationToken cancellationToken = default)
{
if (activation is null)
{
throw new ArgumentNullException(nameof(activation));
}
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
ArgumentNullException.ThrowIfNull(activation);
ArgumentException.ThrowIfNullOrEmpty(identifier);
using var buffer = new MemoryStream();
using var writer = new BinaryWriter(buffer);

1
src/OpenIddict.Client.SystemNetHttp/OpenIddict.Client.SystemNetHttp.csproj

@ -6,6 +6,7 @@
$(NetCoreTargetFrameworks);
$(NetStandardTargetFrameworks)
</TargetFrameworks>
<DefineConstants>$(DefineConstants);FeatureRuntimeInformation</DefineConstants>
</PropertyGroup>
<PropertyGroup>

97
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs

@ -42,10 +42,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder Configure(Action<OpenIddictClientSystemNetHttpOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@ -63,10 +60,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action<HttpClient> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
return ConfigureHttpClient((registration, client) => configuration(client));
}
@ -84,15 +78,8 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(string provider, Action<HttpClient> configuration)
{
if (string.IsNullOrEmpty(provider))
{
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
ArgumentException.ThrowIfNullOrEmpty(provider);
return ConfigureHttpClient((registration, client) =>
{
@ -115,10 +102,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClient(Action<OpenIddictClientRegistration, HttpClient> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
return Configure(options => options.HttpClientActions.Add(configuration));
}
@ -134,10 +118,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(Action<HttpClientHandler> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
return ConfigureHttpClientHandler((registration, handler) => configuration(handler));
}
@ -155,15 +136,8 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(string provider, Action<HttpClientHandler> configuration)
{
if (string.IsNullOrEmpty(provider))
{
throw new ArgumentException(SR.FormatID0366(nameof(provider)), nameof(provider));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
ArgumentException.ThrowIfNullOrEmpty(provider);
return ConfigureHttpClientHandler((registration, handler) =>
{
@ -187,10 +161,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder ConfigureHttpClientHandler(
Action<OpenIddictClientRegistration, HttpClientHandler> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
return Configure(options => options.HttpClientHandlerActions.Add(configuration));
}
@ -203,10 +174,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetContactAddress(MailAddress address)
{
if (address is null)
{
throw new ArgumentNullException(nameof(address));
}
ArgumentNullException.ThrowIfNull(address);
return Configure(options => options.ContactAddress = address);
}
@ -219,10 +187,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetContactAddress(string address)
{
if (string.IsNullOrEmpty(address))
{
throw new ArgumentException(SR.FormatID0366(nameof(address)), nameof(address));
}
ArgumentException.ThrowIfNullOrEmpty(address);
return SetContactAddress(new MailAddress(address));
}
@ -234,10 +199,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy<HttpResponseMessage> policy)
{
if (policy is null)
{
throw new ArgumentNullException(nameof(policy));
}
ArgumentNullException.ThrowIfNull(policy);
return Configure(options => options.HttpErrorPolicy = policy);
}
@ -257,10 +219,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline(
Action<ResiliencePipelineBuilder<HttpResponseMessage>> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
var builder = new ResiliencePipelineBuilder<HttpResponseMessage>();
configuration(builder);
@ -279,10 +238,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetHttpResiliencePipeline(ResiliencePipeline<HttpResponseMessage> pipeline)
{
if (pipeline is null)
{
throw new ArgumentNullException(nameof(pipeline));
}
ArgumentNullException.ThrowIfNull(pipeline);
return Configure(options => options.HttpResiliencePipeline = pipeline);
}
@ -296,10 +252,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue information)
{
if (information is null)
{
throw new ArgumentNullException(nameof(information));
}
ArgumentNullException.ThrowIfNull(information);
return Configure(options => options.ProductInformation = information);
}
@ -313,10 +266,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(string name, string? version)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0345), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
return SetProductInformation(new ProductInfoHeaderValue(name, version));
}
@ -330,10 +280,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/> instance.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(Assembly assembly)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
ArgumentNullException.ThrowIfNull(assembly);
return SetProductInformation(new ProductInfoHeaderValue(
productName: assembly.GetName().Name!,
@ -356,10 +303,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetSelfSignedTlsClientAuthenticationCertificateSelector(
Func<OpenIddictClientRegistration, X509Certificate2?> selector)
{
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
}
ArgumentNullException.ThrowIfNull(selector);
return Configure(options => options.SelfSignedTlsClientAuthenticationCertificateSelector = selector);
}
@ -380,10 +324,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
public OpenIddictClientSystemNetHttpBuilder SetTlsClientAuthenticationCertificateSelector(
Func<OpenIddictClientRegistration, X509Certificate2?> selector)
{
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
}
ArgumentNullException.ThrowIfNull(selector);
return Configure(options => options.TlsClientAuthenticationCertificateSelector = selector);
}

20
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs

@ -42,10 +42,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/>
public void Configure(OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict System.Net.Http client components.
options.Handlers.AddRange(OpenIddictClientSystemNetHttpHandlers.DefaultHandlers);
@ -62,10 +59,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/>
public void Configure(string? name, HttpClientFactoryOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName();
@ -179,10 +173,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/>
public void PostConfigure(string? name, HttpClientFactoryOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
var assembly = typeof(OpenIddictClientSystemNetHttpOptions).Assembly.GetName();
@ -270,10 +261,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// If no client authentication certificate selector was provided, use fallback delegates that
// automatically use the first X.509 signing certificate attached to the client registration

16
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs

@ -25,10 +25,7 @@ public static class OpenIddictClientSystemNetHttpExtensions
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public static OpenIddictClientSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictClientBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddHttpClient();
@ -65,15 +62,8 @@ public static class OpenIddictClientSystemNetHttpExtensions
public static OpenIddictClientBuilder UseSystemNetHttp(
this OpenIddictClientBuilder builder, Action<OpenIddictClientSystemNetHttpBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseSystemNetHttp());

5
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlerFilters.cs

@ -19,10 +19,7 @@ public static class OpenIddictClientSystemNetHttpHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseExternalContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(
string.Equals(context.RemoteUri?.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||

10
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.Userinfo.cs

@ -62,10 +62,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Request is not null, SR.GetResourceString(SR.ID4008));
@ -103,10 +100,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Response is not null || !string.IsNullOrEmpty(context.UserInfoToken))

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

@ -10,7 +10,6 @@ using System.Diagnostics;
using System.IO.Compression;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@ -82,10 +81,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.TokenEndpointClientAuthenticationMethod))
@ -204,10 +200,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Unlike DPoP, the mTLS specification doesn't use a specific token type to represent
// certificate-bound tokens. As such, most implementations (e.g Keycloak) simply return
@ -269,10 +262,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.DeviceAuthorizationEndpointClientAuthenticationMethod))
@ -399,10 +389,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.PushedAuthorizationEndpointClientAuthenticationMethod))
@ -530,10 +517,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessIntrospectionContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.IntrospectionEndpointClientAuthenticationMethod))
@ -652,10 +636,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If an explicit client authentication method was attached, don't overwrite it.
if (!string.IsNullOrEmpty(context.RevocationEndpointClientAuthenticationMethod))
@ -772,10 +753,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: HttpClientFactory doesn't support flowing a list of properties that can be
// accessed from the HttpClientAction or HttpMessageHandlerBuilderAction delegates
@ -856,10 +834,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Store the HttpRequestMessage in the transaction properties.
context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!,
@ -888,10 +863,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Store the HttpRequestMessage in the transaction properties.
context.Transaction.SetProperty(typeof(HttpRequestMessage).FullName!,
@ -920,10 +892,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION || SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
@ -968,10 +937,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -1013,10 +979,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -1067,10 +1030,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -1103,10 +1063,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -1160,10 +1117,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -1220,10 +1174,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -1284,10 +1235,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -1322,10 +1270,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: automatic content decompression can be enabled by constructing an HttpClient wrapping
// a generic HttpClientHandler, a SocketsHttpHandler or a WinHttpHandler instance with the
@ -1367,7 +1312,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
// Content-Encoding header from the response, which leads to incorrect results when trying
// to decompress the content a second time. To avoid that, the entire logic used in this
// handler is ignored on iOS if the native HTTP handler (NSUrlSessionHandler) is used.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
if (OperatingSystem.IsIOS() &&
AppContext.TryGetSwitch("System.Net.Http.UseNativeHttpHandler", out bool value) && value)
{
return;
@ -1468,10 +1413,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null)
@ -1547,10 +1489,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null)
@ -1676,10 +1615,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the response if one was already provided.
if (context.Transaction.Response is not null)
@ -1722,10 +1658,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -1792,10 +1725,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationBuilder.cs

@ -35,10 +35,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
/// <returns>The <see cref="OpenIddictClientWebIntegrationBuilder"/> instance.</returns>
public OpenIddictClientWebIntegrationBuilder Configure(Action<OpenIddictClientWebIntegrationOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);

15
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationConfiguration.cs

@ -23,10 +23,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
/// <inheritdoc/>
public void Configure(OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// Register the built-in event handlers used by the OpenIddict client Web components.
options.Handlers.AddRange(OpenIddictClientWebIntegrationHandlers.DefaultHandlers);
@ -35,10 +32,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
options.Registrations.ForEach(static registration =>
{
@ -54,10 +48,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfi
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientSystemNetHttpOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
// Override the default/user-defined selectors to support attaching TLS client
// certificates that don't meet the requirements enforced by default by OpenIddict.

16
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs

@ -25,10 +25,7 @@ public static partial class OpenIddictClientWebIntegrationExtensions
/// <returns>The <see cref="OpenIddictClientWebIntegrationBuilder"/> instance.</returns>
public static OpenIddictClientWebIntegrationBuilder UseWebProviders(this OpenIddictClientBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
// Register the System.Net.Http integration.
builder.UseSystemNetHttp();
@ -68,15 +65,8 @@ public static partial class OpenIddictClientWebIntegrationExtensions
public static OpenIddictClientBuilder UseWebProviders(
this OpenIddictClientBuilder builder, Action<OpenIddictClientWebIntegrationBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseWebProviders());

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Authentication.cs

@ -40,10 +40,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareAuthorizationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Some providers implement old drafts of the OAuth 2.0 specification that didn't support
// the "response_type" parameter but relied on a "type" parameter to determine the type

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Device.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractDeviceAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Response is null)
{

30
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs

@ -45,10 +45,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.Response[Metadata.Issuer] = context.Registration.ProviderType switch
{
@ -97,10 +94,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: some providers don't list the grant types they support, which prevents the OpenIddict
// client from using them (unless they are assumed to be enabled by default, like the
@ -182,10 +176,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Some providers support Proof Key for Code Exchange but don't list any supported code
// challenge method in the server configuration metadata. To ensure the OpenIddict client
@ -227,10 +218,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Atlassian includes the "openid" scope in its server configuration but doesn't currently allow
// requesting it. To prevent an error from being returned, OpenID Connect support is disabled.
@ -280,10 +268,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Alibaba Cloud doesn't document whether sending client credentials using basic authentication
// is supported and doesn't return a "token_endpoint_auth_methods_supported" nor a
@ -394,10 +379,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// While Atlassian implements an OpenID Connect userinfo endpoint, using it requires
// requesting the "openid" scope, which isn't allowed yet. To work around this

30
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs

@ -60,10 +60,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Amazon doesn't support the standard "urn:ietf:params:oauth:grant-type:device_code"
// grant type and requires using the non-standard "device_code" grant type instead.
@ -138,10 +135,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Some providers are known to incorrectly implement basic authentication support, either because
// an incorrect encoding scheme is used (e.g the credentials are not formURL-encoded as required
@ -199,10 +193,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -251,10 +242,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -312,10 +300,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareTokenRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -362,10 +347,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractTokenResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Response is null)
{

5
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Introspection.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Response is null)
{

10
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Protection.cs

@ -45,10 +45,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the client registration may be null (e.g when validating a state token).
// In this case, don't amend the default token validation parameters.
@ -103,10 +100,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the client registration may be null (e.g when generating a state token).
// In this case, don't amend the default security token descriptor.

25
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Revocation.cs

@ -55,10 +55,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -106,10 +103,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// These providers don't support the standard "token" parameter and
// require using the non-standard "access_token" parameter instead.
@ -167,10 +161,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -208,10 +199,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -260,10 +248,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractRevocationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.

40
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs

@ -59,10 +59,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -106,10 +103,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -169,10 +163,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -233,10 +224,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// ArcGIS Online doesn't support header-based content negotiation and requires using
// the non-standard "f" parameter to get back JSON responses instead of HTML pages.
@ -274,10 +262,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareUserInfoRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
@ -325,10 +310,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// This handler only applies to System.Net.Http requests. If the HTTP response cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
@ -390,10 +372,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007));
@ -511,10 +490,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractUserInfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007));

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

@ -87,10 +87,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Shopify returns custom/non-standard parameters like the name of the shop for which the
// installation request was initiated. To prevent these parameters from being tampered with,
@ -151,7 +148,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
try
{
if (!OpenIddictHelpers.FixedTimeEquals(
left : OpenIddictHelpers.ConvertFromHexadecimalString(signature),
left : Convert.FromHexString(signature),
right: OpenIddictHelpers.ComputeSha256MessageAuthenticationCode(
key : Encoding.UTF8.GetBytes(context.Registration.ClientSecret),
data: Encoding.UTF8.GetBytes(builder.ToString()))))
@ -200,10 +197,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: some providers are known to return non-standard errors.
// To normalize the set of errors handled by the OpenIddict client,
@ -349,10 +343,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.StateTokenPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -466,10 +457,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.TokenEndpointClientAuthenticationMethod = context.Registration.ProviderType switch
{
@ -509,10 +497,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.TokenEndpoint = context.Registration.ProviderType switch
{
@ -596,10 +581,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -641,10 +623,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@ -707,10 +686,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@ -752,10 +728,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
@ -810,10 +783,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
(context.ExtractBackchannelIdentityToken,
context.RequireBackchannelIdentityToken,
@ -860,10 +830,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: despite implementing OpenID Connect, some providers are known to implement the
// specification incorrectly and either don't support the "nonce" authorization request
@ -905,10 +872,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.SendUserInfoRequest = context.Registration.ProviderType switch
{
@ -996,10 +960,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: despite implementing OpenID Connect, some providers are known to implement completely custom
// userinfo endpoints or semi-standard endpoints that don't fully conform to the core specification.
@ -1038,10 +999,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.UserInfoEndpoint = context.Registration.ProviderType switch
{
@ -1131,10 +1089,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.UserInfoRequest is not null, SR.GetResourceString(SR.ID4008));
@ -1267,10 +1222,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
Debug.Assert(context.TokenResponse is not null, SR.GetResourceString(SR.ID4007));
@ -1372,10 +1324,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@ -1636,10 +1585,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If no explicit shop name was attached to the challenge properties, use the
// shop name set in the provider settings, if set. Otherwise, throw an exception.
@ -1679,10 +1625,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.AuthorizationEndpoint = context.Registration.ProviderType switch
{
@ -1755,10 +1698,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.ResponseMode = context.Registration.ProviderType switch
{
@ -1793,10 +1733,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.Request.Scope = context.Registration.ProviderType switch
{
@ -1837,10 +1774,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.RedirectUri is null)
{
@ -1891,10 +1825,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Active Directory Federation Services allows sending an optional custom "resource"
// parameter to define what API resources the access token will give access to.
@ -2084,10 +2015,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.RevocationEndpointClientAuthenticationMethod = context.Registration.ProviderType switch
{
@ -2122,10 +2050,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.ClientAssertionPrincipal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -2167,10 +2092,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ProcessRevocationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008));

203
src/OpenIddict.Client/OpenIddictClientBuilder.cs

@ -7,7 +7,6 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
@ -46,10 +45,7 @@ public sealed class OpenIddictClientBuilder
Action<OpenIddictClientHandlerDescriptor.Builder<TContext>> configuration)
where TContext : BaseContext
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
// Note: handlers registered using this API are assumed to be custom handlers by default.
var builder = OpenIddictClientHandlerDescriptor.CreateBuilder<TContext>()
@ -68,10 +64,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder AddEventHandler(OpenIddictClientHandlerDescriptor descriptor)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
// Register the handler in the services collection.
Services.Add(descriptor.ServiceDescriptor);
@ -87,10 +80,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder RemoveEventHandler(OpenIddictClientHandlerDescriptor descriptor)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
Services.RemoveAll(descriptor.ServiceDescriptor.ServiceType);
@ -116,10 +106,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder Configure(Action<OpenIddictClientOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@ -133,10 +120,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCredentials(EncryptingCredentials credentials)
{
if (credentials is null)
{
throw new ArgumentNullException(nameof(credentials));
}
ArgumentNullException.ThrowIfNull(credentials);
return Configure(options => options.EncryptionCredentials.Add(credentials));
}
@ -148,10 +132,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionKey(SecurityKey key)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
// If the encryption key is an asymmetric security key, ensure it has a private key.
if (key is AsymmetricSecurityKey asymmetricSecurityKey &&
@ -187,10 +168,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionKeys(IEnumerable<SecurityKey> keys)
{
if (keys is null)
{
throw new ArgumentNullException(nameof(keys));
}
ArgumentNullException.ThrowIfNull(keys);
return keys.Aggregate(this, static (builder, key) => builder.AddEncryptionKey(key));
}
@ -209,10 +187,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddDevelopmentEncryptionCertificate(X500DistinguishedName subject)
{
if (subject is null)
{
throw new ArgumentNullException(nameof(subject));
}
ArgumentNullException.ThrowIfNull(subject);
Services.AddOptions<OpenIddictClientOptions>().Configure<IServiceProvider>((options, provider) =>
{
@ -242,7 +217,7 @@ public sealed class OpenIddictClientBuilder
// Note: setting the friendly name is not supported on Unix machines (including Linux and macOS).
// To ensure an exception is not thrown by the property setter, an OS runtime check is used here.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
certificate.FriendlyName = "OpenIddict Client Development Encryption Certificate";
}
@ -259,7 +234,7 @@ public sealed class OpenIddictClientBuilder
// Note: macOS requires marking the certificate private key as exportable.
// If this flag is not set, a CryptographicException is thrown at runtime.
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
{
flags |= X509KeyStorageFlags.Exportable;
}
@ -313,10 +288,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEphemeralEncryptionKey(string algorithm)
{
if (string.IsNullOrEmpty(algorithm))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0057), nameof(algorithm));
}
ArgumentException.ThrowIfNullOrEmpty(algorithm);
return algorithm switch
{
@ -342,10 +314,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(X509Certificate2 certificate)
{
if (certificate is null)
{
throw new ArgumentNullException(nameof(certificate));
}
ArgumentNullException.ThrowIfNull(certificate);
// If the certificate is a X.509v3 certificate that specifies at least one
// key usage, ensure that the certificate key can be used for key encryption.
@ -377,7 +346,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddEncryptionCertificate(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
=> AddEncryptionCertificate(assembly, resource, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
=> AddEncryptionCertificate(assembly, resource, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@ -396,15 +365,8 @@ public sealed class OpenIddictClientBuilder
Assembly assembly, string resource,
string? password, X509KeyStorageFlags flags)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
ArgumentNullException.ThrowIfNull(assembly);
ArgumentException.ThrowIfNullOrEmpty(resource);
using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@ -421,7 +383,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
=> AddEncryptionCertificate(stream, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
=> AddEncryptionCertificate(stream, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@ -437,10 +399,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(Stream stream, string? password, X509KeyStorageFlags flags)
{
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
ArgumentNullException.ThrowIfNull(stream);
using var buffer = new MemoryStream();
stream.CopyTo(buffer);
@ -465,10 +424,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint)
{
if (string.IsNullOrEmpty(thumbprint))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
ArgumentException.ThrowIfNullOrEmpty(thumbprint);
return AddEncryptionCertificate(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@ -495,10 +451,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificate(string thumbprint, StoreName name, StoreLocation location)
{
if (string.IsNullOrEmpty(thumbprint))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
ArgumentException.ThrowIfNullOrEmpty(thumbprint);
using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
@ -516,11 +469,8 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEncryptionCertificates(IEnumerable<X509Certificate2> certificates)
{
if (certificates is null)
{
throw new ArgumentNullException(nameof(certificates));
}
ArgumentNullException.ThrowIfNull(certificates);
return certificates.Aggregate(this, static (builder, certificate) => builder.AddEncryptionCertificate(certificate));
}
@ -531,10 +481,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCredentials(SigningCredentials credentials)
{
if (credentials is null)
{
throw new ArgumentNullException(nameof(credentials));
}
ArgumentNullException.ThrowIfNull(credentials);
return Configure(options => options.SigningCredentials.Add(credentials));
}
@ -546,10 +493,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningKey(SecurityKey key)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
// If the signing key is an asymmetric security key, ensure it has a private key.
if (key is AsymmetricSecurityKey asymmetricSecurityKey &&
@ -603,10 +547,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningKeys(IEnumerable<SecurityKey> keys)
{
if (keys is null)
{
throw new ArgumentNullException(nameof(keys));
}
ArgumentNullException.ThrowIfNull(keys);
return keys.Aggregate(this, static (builder, key) => builder.AddSigningKey(key));
}
@ -625,10 +566,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddDevelopmentSigningCertificate(X500DistinguishedName subject)
{
if (subject is null)
{
throw new ArgumentNullException(nameof(subject));
}
ArgumentNullException.ThrowIfNull(subject);
Services.AddOptions<OpenIddictClientOptions>().Configure<IServiceProvider>((options, provider) =>
{
@ -658,7 +596,7 @@ public sealed class OpenIddictClientBuilder
// Note: setting the friendly name is not supported on Unix machines (including Linux and macOS).
// To ensure an exception is not thrown by the property setter, an OS runtime check is used here.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
certificate.FriendlyName = "OpenIddict Client Development Signing Certificate";
}
@ -675,7 +613,7 @@ public sealed class OpenIddictClientBuilder
// Note: macOS requires marking the certificate private key as exportable.
// If this flag is not set, a CryptographicException is thrown at runtime.
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
{
flags |= X509KeyStorageFlags.Exportable;
}
@ -728,10 +666,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddEphemeralSigningKey(string algorithm)
{
if (string.IsNullOrEmpty(algorithm))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0057), nameof(algorithm));
}
ArgumentException.ThrowIfNullOrEmpty(algorithm);
return algorithm switch
{
@ -786,10 +721,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(X509Certificate2 certificate)
{
if (certificate is null)
{
throw new ArgumentNullException(nameof(certificate));
}
ArgumentNullException.ThrowIfNull(certificate);
// If the certificate is a X.509v3 certificate that specifies at least
// one key usage, ensure that the certificate key can be used for signing.
@ -821,7 +753,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddSigningCertificate(Assembly assembly, string resource, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
=> AddSigningCertificate(assembly, resource, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
=> AddSigningCertificate(assembly, resource, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@ -840,15 +772,8 @@ public sealed class OpenIddictClientBuilder
Assembly assembly, string resource,
string? password, X509KeyStorageFlags flags)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
ArgumentNullException.ThrowIfNull(assembly);
ArgumentException.ThrowIfNullOrEmpty(resource);
using var stream = assembly.GetManifestResourceStream(resource) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0064));
@ -865,7 +790,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password)
#if SUPPORTS_EPHEMERAL_KEY_SETS
// Note: ephemeral key sets are currently not supported on macOS.
=> AddSigningCertificate(stream, password, RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
=> AddSigningCertificate(stream, password, OperatingSystem.IsMacOS() ?
X509KeyStorageFlags.MachineKeySet :
X509KeyStorageFlags.EphemeralKeySet);
#else
@ -881,10 +806,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(Stream stream, string? password, X509KeyStorageFlags flags)
{
if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
ArgumentNullException.ThrowIfNull(stream);
using var buffer = new MemoryStream();
stream.CopyTo(buffer);
@ -909,10 +831,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(string thumbprint)
{
if (string.IsNullOrEmpty(thumbprint))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
ArgumentException.ThrowIfNullOrEmpty(thumbprint);
return AddSigningCertificate(
GetCertificate(StoreLocation.CurrentUser, thumbprint) ??
@ -939,10 +858,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificate(string thumbprint, StoreName name, StoreLocation location)
{
if (string.IsNullOrEmpty(thumbprint))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0065), nameof(thumbprint));
}
ArgumentException.ThrowIfNullOrEmpty(thumbprint);
using var store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
@ -960,11 +876,8 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddSigningCertificates(IEnumerable<X509Certificate2> certificates)
{
if (certificates is null)
{
throw new ArgumentNullException(nameof(certificates));
}
ArgumentNullException.ThrowIfNull(certificates);
return certificates.Aggregate(this, static (builder, certificate) => builder.AddSigningCertificate(certificate));
}
@ -975,10 +888,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder AddRegistration(OpenIddictClientRegistration registration)
{
if (registration is null)
{
throw new ArgumentNullException(nameof(registration));
}
ArgumentNullException.ThrowIfNull(registration);
return Configure(options => options.Registrations.Add(registration));
}
@ -1038,10 +948,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder AllowCustomFlow(string type)
{
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0071), nameof(type));
}
ArgumentException.ThrowIfNullOrEmpty(type);
return Configure(options => options.GrantTypes.Add(type));
}
@ -1138,10 +1045,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris(
[StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris)
{
if (uris is null)
{
throw new ArgumentNullException(nameof(uris));
}
ArgumentNullException.ThrowIfNull(uris);
return SetPostLogoutRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]);
}
@ -1154,10 +1058,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder SetPostLogoutRedirectionEndpointUris(params Uri[] uris)
{
if (uris is null)
{
throw new ArgumentNullException(nameof(uris));
}
ArgumentNullException.ThrowIfNull(uris);
if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri))
{
@ -1191,10 +1092,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetRedirectionEndpointUris(
[StringSyntax(StringSyntaxAttribute.Uri)] params string[] uris)
{
if (uris is null)
{
throw new ArgumentNullException(nameof(uris));
}
ArgumentNullException.ThrowIfNull(uris);
return SetRedirectionEndpointUris([.. uris.Select(uri => new Uri(uri, UriKind.RelativeOrAbsolute))]);
}
@ -1213,10 +1111,7 @@ public sealed class OpenIddictClientBuilder
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public OpenIddictClientBuilder SetRedirectionEndpointUris(params Uri[] uris)
{
if (uris is null)
{
throw new ArgumentNullException(nameof(uris));
}
ArgumentNullException.ThrowIfNull(uris);
if (Array.Exists(uris, OpenIddictHelpers.IsImplicitFileUri))
{
@ -1265,10 +1160,7 @@ public sealed class OpenIddictClientBuilder
[EditorBrowsable(EditorBrowsableState.Advanced)]
public OpenIddictClientBuilder SetClientUri(Uri uri)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
return Configure(options => options.ClientUri = uri);
}
@ -1282,10 +1174,7 @@ public sealed class OpenIddictClientBuilder
public OpenIddictClientBuilder SetClientUri(
[StringSyntax(StringSyntaxAttribute.Uri, UriKind.Absolute)] string uri)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.FormatID0366(nameof(uri)), nameof(uri));
}
ArgumentException.ThrowIfNullOrEmpty(uri);
if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value))
{

5
src/OpenIddict.Client/OpenIddictClientConfiguration.cs

@ -40,10 +40,7 @@ public sealed class OpenIddictClientConfiguration : IPostConfigureOptions<OpenId
/// <inheritdoc/>
public void PostConfigure(string? name, OpenIddictClientOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);
if (options.JsonWebTokenHandler is null)
{

5
src/OpenIddict.Client/OpenIddictClientDispatcher.cs

@ -36,10 +36,7 @@ public sealed class OpenIddictClientDispatcher : IOpenIddictClientDispatcher
/// <inheritdoc/>
public async ValueTask DispatchAsync<TContext>(TContext context) where TContext : BaseContext
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
await foreach (var handler in GetHandlersAsync())
{

16
src/OpenIddict.Client/OpenIddictClientExtensions.cs

@ -23,10 +23,7 @@ public static class OpenIddictClientExtensions
/// <returns>The <see cref="OpenIddictClientBuilder"/> instance.</returns>
public static OpenIddictClientBuilder AddClient(this OpenIddictBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddLogging();
builder.Services.AddOptions();
@ -98,15 +95,8 @@ public static class OpenIddictClientExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictBuilder AddClient(this OpenIddictBuilder builder, Action<OpenIddictClientBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.AddClient());

10
src/OpenIddict.Client/OpenIddictClientHandlerDescriptor.cs

@ -88,10 +88,7 @@ public sealed class OpenIddictClientHandlerDescriptor
/// <returns>The builder instance, so that calls can be easily chained.</returns>
public Builder<TContext> Import(OpenIddictClientHandlerDescriptor descriptor)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
if (descriptor.ContextType != typeof(TContext))
{
@ -114,10 +111,7 @@ public sealed class OpenIddictClientHandlerDescriptor
/// <returns>The builder instance, so that calls can be easily chained.</returns>
public Builder<TContext> SetServiceDescriptor(ServiceDescriptor descriptor)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
if (!typeof(IOpenIddictClientHandler<TContext>).IsAssignableFrom(descriptor.ServiceType))
{

210
src/OpenIddict.Client/OpenIddictClientHandlerFilters.cs

@ -19,10 +19,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateAuthorizationCode);
}
@ -36,10 +33,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateBackchannelAccessToken);
}
@ -53,10 +47,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableBackchannelIdentityTokenNonceValidation);
}
@ -70,10 +61,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.BackchannelIdentityTokenPrincipal is not null);
}
@ -87,10 +75,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateBackchannelIdentityToken);
}
@ -104,10 +89,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@ -123,10 +105,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@ -134,10 +113,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
ValueTask<bool> IOpenIddictClientHandlerFilter<ProcessRevocationContext>.IsActiveAsync(ProcessRevocationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@ -152,10 +128,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GrantType is GrantTypes.DeviceCode);
}
@ -169,10 +142,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.SendDeviceAuthorizationRequest);
}
@ -186,10 +156,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateFrontchannelAccessToken);
}
@ -203,10 +170,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableFrontchannelIdentityTokenNonceValidation);
}
@ -220,10 +184,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.FrontchannelIdentityTokenPrincipal is not null);
}
@ -237,10 +198,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateFrontchannelIdentityToken);
}
@ -255,10 +213,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GrantType switch
{
@ -277,10 +232,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessIntrospectionContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@ -294,10 +246,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessIntrospectionContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.SendIntrospectionRequest);
}
@ -311,10 +260,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateIssuedToken);
}
@ -328,10 +274,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.TokenFormat is TokenFormats.Private.JsonWebToken);
}
@ -345,10 +288,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateStateToken);
}
@ -362,10 +302,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateStateToken);
}
@ -379,10 +316,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.EndpointType is OpenIddictClientEndpointType.PostLogoutRedirection);
}
@ -396,10 +330,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.SendPushedAuthorizationRequest);
}
@ -413,10 +344,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.EndpointType is OpenIddictClientEndpointType.Redirection);
}
@ -430,10 +358,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateRefreshToken);
}
@ -447,10 +372,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessRevocationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.GenerateClientAssertion);
}
@ -464,10 +386,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessRevocationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.SendRevocationRequest);
}
@ -481,10 +400,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.StateTokenPrincipal is not null);
}
@ -498,10 +414,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ValidateStateToken);
}
@ -515,10 +428,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableAudienceValidation);
}
@ -532,10 +442,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.CreateTokenEntry);
}
@ -549,10 +456,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!string.IsNullOrEmpty(context.TokenId));
}
@ -566,10 +470,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableLifetimeValidation);
}
@ -583,10 +484,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.PersistTokenPayload);
}
@ -600,10 +498,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.DisablePresenterValidation);
}
@ -617,10 +512,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.SendTokenRequest);
}
@ -634,10 +526,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.Options.DisableTokenStorage);
}
@ -651,10 +540,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.SendUserInfoRequest);
}
@ -668,10 +554,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.ExtractUserInfoToken);
}
@ -685,10 +568,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(context.UserInfoTokenPrincipal is not null);
}
@ -702,10 +582,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(ProcessAuthenticationContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.DisableUserInfoValidation);
}
@ -719,10 +596,7 @@ public static class OpenIddictClientHandlerFilters
/// <inheritdoc/>
public ValueTask<bool> IsActiveAsync(BaseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
return new(!context.Options.DisableWebServicesFederationClaimMapping);
}

65
src/OpenIddict.Client/OpenIddictClientHandlers.Authentication.cs

@ -78,10 +78,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new PrepareAuthorizationRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -123,10 +120,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessChallengeContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyAuthorizationRequestContext(context.Transaction)
{
@ -178,10 +172,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the endpoint URI if it was already set.
if (!string.IsNullOrEmpty(context.AuthorizationEndpoint))
@ -220,10 +211,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@ -284,10 +272,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
if (!string.IsNullOrEmpty(context.Response.Error))
@ -331,10 +316,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "request_uri" parameter is missing.
//
@ -384,10 +366,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandlePushedAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "expires_in" parameter is missing.
//
@ -429,10 +408,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ExtractRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -491,10 +467,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ValidateRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -547,10 +520,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new HandleRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -604,10 +574,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyRedirectionResponseContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -646,10 +613,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(PrepareAuthorizationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// When the response mode corresponds to the default mode assigned to the selected
// response type, the specification explicitly recommends omitting the response mode.
@ -697,10 +661,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ValidateRedirectionRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ProcessAuthenticationContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);

20
src/OpenIddict.Client/OpenIddictClientHandlers.Device.cs

@ -43,10 +43,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@ -113,10 +110,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
if (!string.IsNullOrEmpty(context.Response.Error))
@ -161,10 +155,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "verification_uri" parameter is missing.
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.
@ -227,10 +218,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleDeviceAuthorizationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Return an error if the mandatory "expires_in" parameter is missing.
// For more information, see https://www.rfc-editor.org/rfc/rfc8628#section-3.2.

170
src/OpenIddict.Client/OpenIddictClientHandlers.Discovery.cs

@ -78,10 +78,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@ -171,10 +168,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the specification doesn't define a standard way to return an error other than
// returning a 4xx status code. That said, some implementations are known to return
@ -214,10 +208,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the issuer returned in the discovery document must exactly match the URI used to access it.
// See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationValidation.
@ -278,10 +269,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the authorization_endpoint node is required by the OpenID Connect discovery specification
// but is optional in the OAuth 2.0 authorization server metadata specification. To make OpenIddict
@ -330,10 +318,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the jwks_uri node is required by the OpenID Connect discovery specification.
// See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationClient.
@ -382,10 +367,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.DeviceAuthorizationEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@ -425,10 +407,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.IntrospectionEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@ -468,10 +447,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.EndSessionEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@ -512,10 +488,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@ -548,10 +521,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@ -583,10 +553,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@ -618,10 +585,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@ -653,10 +617,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@ -688,10 +649,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: as recommended by the specification, values present in the "mtls_endpoint_aliases" node
// that can't be recognized as OAuth 2.0 endpoints or are not valid URIs are simply ignored.
@ -723,10 +681,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.PushedAuthorizationRequestEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@ -766,10 +721,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.RevocationEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@ -809,10 +761,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.TokenEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@ -852,10 +801,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var endpoint = (string?) context.Response[Metadata.UserInfoEndpoint];
if (!string.IsNullOrEmpty(endpoint))
@ -895,10 +841,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the grant types supported by the authorization endpoint, if available.
foreach (var type in (ImmutableArray<string?>?) context.Response[Metadata.GrantTypesSupported] ?? [])
@ -931,10 +874,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the response modes supported by the authorization endpoint, if available.
foreach (var mode in (ImmutableArray<string?>?) context.Response[Metadata.ResponseModesSupported] ?? [])
@ -967,10 +907,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the response types supported by the authorization endpoint, if available.
foreach (var type in (ImmutableArray<string?>?) context.Response[Metadata.ResponseTypesSupported] ?? [])
@ -1003,10 +940,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the code challenge methods supported by the authorization endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.CodeChallengeMethodsSupported] ?? [])
@ -1039,10 +973,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the scopes supported by the remote server, if available.
foreach (var scope in (ImmutableArray<string?>?) context.Response[Metadata.ScopesSupported] ?? [])
@ -1076,10 +1007,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.Configuration.AuthorizationResponseIssParameterSupported = (bool?)
context.Response[Metadata.AuthorizationResponseIssParameterSupported];
@ -1107,10 +1035,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.Configuration.TlsClientCertificateBoundAccessTokens = (bool?)
context.Response[Metadata.TlsClientCertificateBoundAccessTokens];
@ -1138,10 +1063,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.Configuration.RequirePushedAuthorizationRequests = (bool?)
context.Response[Metadata.RequirePushedAuthorizationRequests];
@ -1169,10 +1091,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the device authorization endpoint, if available.
//
@ -1209,10 +1128,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the introspection endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.IntrospectionEndpointAuthMethodsSupported] ?? [])
@ -1246,10 +1162,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the pushed authorization endpoint, if available.
//
@ -1286,10 +1199,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the revocation endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.RevocationEndpointAuthMethodsSupported] ?? [])
@ -1323,10 +1233,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleConfigurationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Resolve the client authentication methods supported by the token endpoint, if available.
foreach (var method in (ImmutableArray<string?>?) context.Response[Metadata.TokenEndpointAuthMethodsSupported] ?? [])
@ -1359,10 +1266,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@ -1421,10 +1325,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the specification doesn't define a standard way to return an error other than
// returning a 4xx status code. That said, some implementations are known to return
@ -1464,10 +1365,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleJsonWebKeySetResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var keys = context.Response[JsonWebKeySetParameterNames.Keys]?.GetUnnamedParameters();
if (keys is not { Count: > 0 })

10
src/OpenIddict.Client/OpenIddictClientHandlers.Exchange.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleTokenResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@ -107,10 +104,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleTokenResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// For more information, see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2.
if (!string.IsNullOrEmpty(context.Response.Error))

40
src/OpenIddict.Client/OpenIddictClientHandlers.Introspection.cs

@ -50,10 +50,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@ -127,10 +124,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the specification requires returning most errors (e.g invalid token errors)
// as "active: false" responses instead of as proper OAuth 2.0 error responses.
@ -173,10 +167,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: the introspection specification requires that server return "active: false" instead of a proper
// OAuth 2.0 error when the token is invalid, expired, revoked or invalid for any other reason.
@ -226,10 +217,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// The issuer claim is optional. If it's not null or empty, validate it to
// ensure it matches the issuer registered in the server configuration.
@ -280,10 +268,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: in most cases, an expired token should lead to an errored or "active=false" response
// being returned by the authorization server. Unfortunately, some implementations are known not
@ -327,10 +312,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// OpenIddict-based authorization servers always return the actual token type using
// the special "token_usage" claim, that helps resource servers determine whether the
@ -383,10 +365,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));
@ -476,10 +455,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleIntrospectionResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));

85
src/OpenIddict.Client/OpenIddictClientHandlers.Protection.cs

@ -64,10 +64,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// The OpenIddict client is expected to validate tokens it creates (e.g state tokens) and
// tokens that are created by one or multiple authorization servers (e.g identity tokens).
@ -206,10 +203,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If no character was explicitly added, all characters are considered valid.
if (context.AllowedCharset.Count is 0)
@ -262,10 +256,7 @@ public static partial class OpenIddictClientHandlers
public async ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: reference tokens are only used for state tokens.
if (context.ValidTokenTypes.Count is not 1 ||
@ -336,10 +327,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If a principal was already attached, don't overwrite it.
if (context.Principal is not null)
@ -494,10 +482,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Note: only map the private claims from fully trusted tokens.
if (context.Principal is null || !context.Principal.HasTokenType(TokenTypeIdentifiers.Private.StateToken))
@ -559,10 +544,7 @@ public static partial class OpenIddictClientHandlers
public async ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Principal is null)
{
@ -625,10 +607,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Principal is null)
{
@ -678,10 +657,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -719,10 +695,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -782,10 +755,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
@ -855,10 +825,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ValidateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Principal is { Identity: ClaimsIdentity }, SR.GetResourceString(SR.ID4006));
Debug.Assert(!string.IsNullOrEmpty(context.TokenId), SR.GetResourceString(SR.ID4017));
@ -920,10 +887,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
context.SecurityTokenHandler = context.Options.JsonWebTokenHandler;
@ -980,10 +944,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var descriptor = new OpenIddictTokenDescriptor
{
@ -1028,10 +989,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (context.Principal is not { Identity: ClaimsIdentity } principal)
{
@ -1077,10 +1035,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var claims = context.SecurityTokenDescriptor.Claims is not null ?
new Dictionary<string, object>(context.SecurityTokenDescriptor.Claims, StringComparer.Ordinal) :
@ -1143,10 +1098,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// If a token was already attached by another handler, don't overwrite it.
if (!string.IsNullOrEmpty(context.Token))
@ -1191,10 +1143,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(GenerateTokenContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var identifier = context.Principal.GetTokenId();
if (string.IsNullOrEmpty(identifier))

10
src/OpenIddict.Client/OpenIddictClientHandlers.Revocation.cs

@ -41,10 +41,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleRevocationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
foreach (var parameter in context.Response.GetParameters())
{
@ -98,10 +95,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleRevocationResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
if (!string.IsNullOrEmpty(context.Response.Error))
{

40
src/OpenIddict.Client/OpenIddictClientHandlers.Session.cs

@ -63,10 +63,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new PrepareEndSessionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -107,10 +104,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessSignOutContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyEndSessionRequestContext(context.Transaction)
{
@ -161,10 +155,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(ApplyEndSessionRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Don't overwrite the endpoint URI if it was already set.
if (!string.IsNullOrEmpty(context.EndSessionEndpoint))
@ -208,10 +199,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ExtractPostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -270,10 +258,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ValidatePostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -326,10 +311,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ProcessRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new HandlePostLogoutRedirectionRequestContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -383,10 +365,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(TContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ApplyPostLogoutRedirectionResponseContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);
@ -431,10 +410,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public async ValueTask HandleAsync(ValidatePostLogoutRedirectionRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
var notification = new ProcessAuthenticationContext(context.Transaction);
await _dispatcher.DispatchAsync(notification);

15
src/OpenIddict.Client/OpenIddictClientHandlers.Userinfo.cs

@ -44,10 +44,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// Ignore the response instance if a userinfo token was extracted.
if (!string.IsNullOrEmpty(context.UserInfoToken))
@ -110,10 +107,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
// For more information, see https://openid.net/specs/openid-connect-core-1_0.html#UserInfoError.
if (!string.IsNullOrEmpty(context.Response.Error))
@ -156,10 +150,7 @@ public static partial class OpenIddictClientHandlers
/// <inheritdoc/>
public ValueTask HandleAsync(HandleUserInfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
Debug.Assert(context.Registration.Issuer is { IsAbsoluteUri: true }, SR.GetResourceString(SR.ID4013));

700
src/OpenIddict.Client/OpenIddictClientHandlers.cs

File diff suppressed because it is too large

22
src/OpenIddict.Client/OpenIddictClientHelpers.cs

@ -21,15 +21,8 @@ public static class OpenIddictClientHelpers
public static TProperty? GetProperty<TProperty>(
this OpenIddictClientTransaction transaction, string name) where TProperty : class
{
if (transaction is null)
{
throw new ArgumentNullException(nameof(transaction));
}
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name));
}
ArgumentNullException.ThrowIfNull(transaction);
ArgumentException.ThrowIfNullOrEmpty(name);
if (transaction.Properties.TryGetValue(name, out var property) && property is TProperty result)
{
@ -51,15 +44,8 @@ public static class OpenIddictClientHelpers
this OpenIddictClientTransaction transaction,
string name, TProperty? value) where TProperty : class
{
if (transaction is null)
{
throw new ArgumentNullException(nameof(transaction));
}
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name));
}
ArgumentNullException.ThrowIfNull(transaction);
ArgumentException.ThrowIfNullOrEmpty(name);
if (value is null)
{

5
src/OpenIddict.Client/OpenIddictClientRetriever.cs

@ -38,10 +38,7 @@ public sealed class OpenIddictClientRetriever : IConfigurationRetriever<OpenIddi
async Task<OpenIddictConfiguration> IConfigurationRetriever<OpenIddictConfiguration>.GetConfigurationAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string address, IDocumentRetriever retriever, CancellationToken cancel)
{
if (string.IsNullOrEmpty(address))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(address));
}
ArgumentException.ThrowIfNullOrEmpty(address);
if (!Uri.TryCreate(address, UriKind.Absolute, out Uri? uri) || OpenIddictHelpers.IsImplicitFileUri(uri))
{

232
src/OpenIddict.Client/OpenIddictClientService.cs

@ -68,10 +68,7 @@ public class OpenIddictClientService
public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByIssuerAsync(
Uri uri, CancellationToken cancellationToken = default)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
if (cancellationToken.IsCancellationRequested)
{
@ -108,10 +105,7 @@ public class OpenIddictClientService
public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByProviderNameAsync(
string name, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
if (cancellationToken.IsCancellationRequested)
{
@ -146,10 +140,7 @@ public class OpenIddictClientService
public virtual ValueTask<OpenIddictClientRegistration> GetClientRegistrationByIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
if (cancellationToken.IsCancellationRequested)
{
@ -179,10 +170,7 @@ public class OpenIddictClientService
public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByIssuerAsync(
Uri uri, CancellationToken cancellationToken = default)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);
var registration = await GetClientRegistrationByIssuerAsync(uri, cancellationToken);
if (registration.ConfigurationManager is null)
@ -212,10 +200,7 @@ public class OpenIddictClientService
public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByProviderNameAsync(
string name, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.FormatID0366(nameof(name)), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
var registration = await GetClientRegistrationByProviderNameAsync(name, cancellationToken);
if (registration.ConfigurationManager is null)
@ -242,10 +227,7 @@ public class OpenIddictClientService
public virtual async ValueTask<OpenIddictConfiguration> GetServerConfigurationByRegistrationIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.FormatID0366(nameof(identifier)), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var registration = await GetClientRegistrationByIdAsync(identifier, cancellationToken);
if (registration.ConfigurationManager is null)
@ -271,10 +253,7 @@ public class OpenIddictClientService
/// <returns>The interactive authentication result.</returns>
public async ValueTask<InteractiveAuthenticationResult> AuthenticateInteractivelyAsync(InteractiveAuthenticationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -344,10 +323,7 @@ public class OpenIddictClientService
/// <returns>The interactive challenge result.</returns>
public async ValueTask<InteractiveChallengeResult> ChallengeInteractivelyAsync(InteractiveChallengeRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -430,10 +406,7 @@ public class OpenIddictClientService
public async ValueTask<ClientCredentialsAuthenticationResult> AuthenticateWithClientCredentialsAsync(
ClientCredentialsAuthenticationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -515,10 +488,7 @@ public class OpenIddictClientService
[EditorBrowsable(EditorBrowsableState.Advanced)]
public async ValueTask<CustomGrantAuthenticationResult> AuthenticateWithCustomGrantAsync(CustomGrantAuthenticationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
// Prevent well-known/non-custom grant types from being used with this API.
if (request.GrantType is GrantTypes.AuthorizationCode or GrantTypes.ClientCredentials or
@ -608,10 +578,7 @@ public class OpenIddictClientService
/// <returns>The device authentication result.</returns>
public async ValueTask<DeviceAuthenticationResult> AuthenticateWithDeviceAsync(DeviceAuthenticationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
using var source = CancellationTokenSource.CreateLinkedTokenSource(request.CancellationToken);
source.CancelAfter(request.Timeout);
@ -725,10 +692,7 @@ public class OpenIddictClientService
/// <returns>The device challenge result.</returns>
public async ValueTask<DeviceChallengeResult> ChallengeUsingDeviceAsync(DeviceChallengeRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -808,10 +772,7 @@ public class OpenIddictClientService
/// <returns>The resource owner password credentials authentication result.</returns>
public async ValueTask<PasswordAuthenticationResult> AuthenticateWithPasswordAsync(PasswordAuthenticationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -897,10 +858,7 @@ public class OpenIddictClientService
public async ValueTask<TokenExchangeAuthenticationResult> AuthenticateWithTokenExchangeAsync(
TokenExchangeAuthenticationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -986,10 +944,7 @@ public class OpenIddictClientService
public async ValueTask<RefreshTokenAuthenticationResult> AuthenticateWithRefreshTokenAsync(
RefreshTokenAuthenticationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -1073,10 +1028,7 @@ public class OpenIddictClientService
/// <returns>The introspection result.</returns>
public async ValueTask<IntrospectionResult> IntrospectTokenAsync(IntrospectionRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -1136,10 +1088,7 @@ public class OpenIddictClientService
/// <returns>The revocation result.</returns>
public async ValueTask<RevocationResult> RevokeTokenAsync(RevocationRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -1201,15 +1150,8 @@ public class OpenIddictClientService
internal async ValueTask<OpenIddictConfiguration> GetConfigurationAsync(
OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default)
{
if (registration is null)
{
throw new ArgumentNullException(nameof(uri));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(registration);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@ -1338,10 +1280,7 @@ public class OpenIddictClientService
/// <returns>The interactive sign-out result.</returns>
public async ValueTask<InteractiveSignOutResult> SignOutInteractivelyAsync(InteractiveSignOutRequest request)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
ArgumentNullException.ThrowIfNull(request);
request.CancellationToken.ThrowIfCancellationRequested();
@ -1407,15 +1346,8 @@ public class OpenIddictClientService
internal async ValueTask<JsonWebKeySet> GetSecurityKeysAsync(
OpenIddictClientRegistration registration, Uri uri, CancellationToken cancellationToken = default)
{
if (registration is null)
{
throw new ArgumentNullException(nameof(registration));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(registration);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@ -1552,25 +1484,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
if (registration is null)
{
throw new ArgumentNullException(nameof(registration));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(registration);
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@ -1710,20 +1627,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@ -1865,25 +1771,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
if (registration is null)
{
throw new ArgumentNullException(nameof(registration));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(registration);
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@ -2023,20 +1914,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@ -2176,25 +2056,10 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, string? method, CancellationToken cancellationToken = default)
{
if (registration is null)
{
throw new ArgumentNullException(nameof(registration));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(registration);
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{
@ -2334,20 +2199,9 @@ public class OpenIddictClientService
OpenIddictClientRegistration registration, OpenIddictConfiguration configuration,
OpenIddictRequest request, Uri uri, HashSet<string> methods, CancellationToken cancellationToken = default)
{
if (registration is null)
{
throw new ArgumentNullException(nameof(registration));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(registration);
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(uri);
if (!uri.IsAbsoluteUri || OpenIddictHelpers.IsImplicitFileUri(uri))
{

45
src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs

@ -45,10 +45,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/>
public async ValueTask AddAsync(TApplication application, CancellationToken cancellationToken)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
_cache.Remove(new
{
@ -107,10 +104,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/>
public ValueTask<TApplication?> FindByClientIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@ -141,10 +135,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/>
public ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@ -176,10 +167,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
public IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentException.ThrowIfNullOrEmpty(uri);
return ExecuteAsync(cancellationToken);
@ -218,10 +206,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
public IAsyncEnumerable<TApplication> FindByRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentException.ThrowIfNullOrEmpty(uri);
return ExecuteAsync(cancellationToken);
@ -259,10 +244,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <inheritdoc/>
public async ValueTask RemoveAsync(TApplication application, CancellationToken cancellationToken)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
var identifier = await _store.GetIdAsync(application, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@ -286,10 +268,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TApplication? application, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -312,10 +291,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TApplication> applications, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -341,10 +317,7 @@ public sealed class OpenIddictApplicationCache<TApplication> : IOpenIddictApplic
/// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TApplication application, CancellationToken cancellationToken)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
var identifier = await _store.GetIdAsync(application, cancellationToken);
if (string.IsNullOrEmpty(identifier))

40
src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs

@ -44,10 +44,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/>
public async ValueTask AddAsync(TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
_cache.Remove(new
{
@ -104,10 +101,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/>
public IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return ExecuteAsync(cancellationToken);
@ -145,10 +139,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/>
public ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@ -179,10 +170,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/>
public IAsyncEnumerable<TAuthorization> FindBySubjectAsync(string subject, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
ArgumentException.ThrowIfNullOrEmpty(subject);
return ExecuteAsync(cancellationToken);
@ -220,10 +208,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <inheritdoc/>
public async ValueTask RemoveAsync(TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
var identifier = await _store.GetIdAsync(authorization, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@ -247,10 +232,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TAuthorization? authorization, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -273,10 +255,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TAuthorization> authorizations, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -302,10 +281,7 @@ public sealed class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAu
/// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
var identifier = await _store.GetIdAsync(authorization, cancellationToken);
if (string.IsNullOrEmpty(identifier))

40
src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs

@ -44,10 +44,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/>
public async ValueTask AddAsync(TScope scope, CancellationToken cancellationToken)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
_cache.Remove(new
{
@ -97,10 +94,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/>
public ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@ -131,10 +125,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/>
public ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0202), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
var parameters = new
{
@ -188,10 +179,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/>
public IAsyncEnumerable<TScope> FindByResourceAsync(string resource, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
ArgumentException.ThrowIfNullOrEmpty(resource);
return ExecuteAsync(cancellationToken);
@ -229,10 +217,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <inheritdoc/>
public async ValueTask RemoveAsync(TScope scope, CancellationToken cancellationToken)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
var identifier = await _store.GetIdAsync(scope, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@ -256,10 +241,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TScope? scope, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -282,10 +264,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TScope> scopes, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -311,10 +290,7 @@ public sealed class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>
/// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TScope scope, CancellationToken cancellationToken)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
var identifier = await _store.GetIdAsync(scope, cancellationToken);
if (string.IsNullOrEmpty(identifier))

50
src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs

@ -44,10 +44,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/>
public async ValueTask AddAsync(TToken token, CancellationToken cancellationToken)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
_cache.Remove(new
{
@ -121,10 +118,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/>
public IAsyncEnumerable<TToken> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return ExecuteAsync(cancellationToken);
@ -162,10 +156,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/>
public IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return ExecuteAsync(cancellationToken);
@ -203,10 +194,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/>
public ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@ -237,10 +225,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/>
public ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var parameters = new
{
@ -271,10 +256,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/>
public IAsyncEnumerable<TToken> FindBySubjectAsync(string subject, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
ArgumentException.ThrowIfNullOrEmpty(subject);
return ExecuteAsync(cancellationToken);
@ -312,10 +294,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <inheritdoc/>
public async ValueTask RemoveAsync(TToken token, CancellationToken cancellationToken)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
var identifier = await _store.GetIdAsync(token, cancellationToken);
if (string.IsNullOrEmpty(identifier))
@ -339,10 +318,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, TToken? token, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -365,10 +341,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
private async ValueTask CreateEntryAsync(object key, ImmutableArray<TToken> tokens, CancellationToken cancellationToken)
{
if (key is null)
{
throw new ArgumentNullException(nameof(key));
}
ArgumentNullException.ThrowIfNull(key);
using var entry = _cache.CreateEntry(key);
@ -394,10 +367,7 @@ public sealed class OpenIddictTokenCache<TToken> : IOpenIddictTokenCache<TToken>
/// </returns>
private async ValueTask<IChangeToken> CreateExpirationSignalAsync(TToken token, CancellationToken cancellationToken)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
var identifier = await _store.GetIdAsync(token, cancellationToken);
if (string.IsNullOrEmpty(identifier))

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

@ -18,6 +18,7 @@ using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using ValidationException = OpenIddict.Abstractions.OpenIddictExceptions.ValidationException;
#if !SUPPORTS_KEY_DERIVATION_WITH_SPECIFIED_HASH_ALGORITHM
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
@ -100,10 +101,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.CountAsync(query, cancellationToken);
}
@ -132,10 +130,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
public virtual async ValueTask CreateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
if (!string.IsNullOrEmpty(await Store.GetClientSecretAsync(application, cancellationToken)))
{
@ -226,10 +221,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<TApplication> CreateAsync(
OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
var application = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0208));
@ -260,10 +252,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
if (!Options.CurrentValue.DisableEntityCaching)
{
@ -285,10 +274,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<TApplication?> FindByClientIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var application = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByClientIdAsync(identifier, cancellationToken) :
@ -322,10 +308,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
public virtual async ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var application = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) :
@ -357,10 +340,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentException.ThrowIfNullOrEmpty(uri);
var applications = Options.CurrentValue.DisableEntityCaching ?
Store.FindByPostLogoutRedirectUriAsync(uri, cancellationToken) :
@ -399,10 +379,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<TApplication> FindByRedirectUriAsync(
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentException.ThrowIfNullOrEmpty(uri);
var applications = Options.CurrentValue.DisableEntityCaching ?
Store.FindByRedirectUriAsync(uri, cancellationToken) :
@ -444,10 +421,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<string?> GetApplicationTypeAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
var type = await Store.GetApplicationTypeAsync(application, cancellationToken);
if (string.IsNullOrEmpty(type))
@ -471,10 +445,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return GetAsync(static (applications, query) => query(applications), query, cancellationToken);
}
@ -495,10 +466,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.GetAsync(query, state, cancellationToken);
}
@ -515,10 +483,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<string?> GetClientIdAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetClientIdAsync(application, cancellationToken);
}
@ -535,10 +500,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<string?> GetClientTypeAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetClientTypeAsync(application, cancellationToken);
}
@ -555,10 +517,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<string?> GetConsentTypeAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
var type = await Store.GetConsentTypeAsync(application, cancellationToken);
if (string.IsNullOrEmpty(type))
@ -581,10 +540,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<string?> GetDisplayNameAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetDisplayNameAsync(application, cancellationToken);
}
@ -601,10 +557,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
var names = await Store.GetDisplayNamesAsync(application, cancellationToken);
if (names is not { Count: > 0 })
@ -626,10 +579,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
public virtual ValueTask<string?> GetIdAsync(TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetIdAsync(application, cancellationToken);
}
@ -645,10 +595,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
public virtual ValueTask<JsonWebKeySet?> GetJsonWebKeySetAsync(TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetJsonWebKeySetAsync(application, cancellationToken);
}
@ -683,15 +630,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<string?> GetLocalizedDisplayNameAsync(
TApplication application, CultureInfo culture, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (culture is null)
{
throw new ArgumentNullException(nameof(culture));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentNullException.ThrowIfNull(culture);
var names = await Store.GetDisplayNamesAsync(application, cancellationToken);
if (names is not { Count: > 0 })
@ -726,10 +666,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetPermissionsAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetPermissionsAsync(application, cancellationToken);
}
@ -746,10 +683,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken);
}
@ -766,10 +700,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetPropertiesAsync(application, cancellationToken);
}
@ -786,10 +717,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetRedirectUrisAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetRedirectUrisAsync(application, cancellationToken);
}
@ -806,10 +734,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableArray<string>> GetRequirementsAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetRequirementsAsync(application, cancellationToken);
}
@ -826,10 +751,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual ValueTask<ImmutableDictionary<string, string>> GetSettingsAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return Store.GetSettingsAsync(application, cancellationToken);
}
@ -844,15 +766,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasApplicationTypeAsync(
TApplication application, string type, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0209), nameof(type));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(type);
return string.Equals(await GetApplicationTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
}
@ -867,15 +782,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasClientTypeAsync(
TApplication application, string type, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0209), nameof(type));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(type);
return string.Equals(await GetClientTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
}
@ -890,15 +798,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasConsentTypeAsync(
TApplication application, string type, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0210), nameof(type));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(type);
return string.Equals(await GetConsentTypeAsync(application, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
}
@ -913,15 +814,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasPermissionAsync(
TApplication application, string permission, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(permission))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0211), nameof(permission));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(permission);
return (await GetPermissionsAsync(application, cancellationToken)).Contains(permission, StringComparer.Ordinal);
}
@ -936,15 +830,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> HasRequirementAsync(
TApplication application, string requirement, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(requirement))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0212), nameof(requirement));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(requirement);
return (await GetRequirementsAsync(application, cancellationToken)).Contains(requirement, StringComparer.Ordinal);
}
@ -970,10 +857,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return ListAsync(static (applications, query) => query(applications), query, cancellationToken);
}
@ -991,10 +875,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.ListAsync(query, state, cancellationToken);
}
@ -1011,15 +892,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask PopulateAsync(TApplication application,
OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentNullException.ThrowIfNull(descriptor);
await Store.SetApplicationTypeAsync(application, descriptor.ApplicationType, cancellationToken);
await Store.SetClientIdAsync(application, descriptor.ClientId, cancellationToken);
@ -1050,15 +924,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
OpenIddictApplicationDescriptor descriptor,
TApplication application, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(descriptor);
ArgumentNullException.ThrowIfNull(application);
descriptor.ApplicationType = await Store.GetApplicationTypeAsync(application, cancellationToken);
descriptor.ClientId = await Store.GetClientIdAsync(application, cancellationToken);
@ -1084,13 +951,13 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
// Ensure the URI is not null or empty.
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0213));
throw new InvalidOperationException(SR.GetResourceString(SR.ID0213));
}
// Ensure the URI is a valid absolute URI.
if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0214));
throw new InvalidOperationException(SR.GetResourceString(SR.ID0214));
}
descriptor.PostLogoutRedirectUris.Add(value);
@ -1108,13 +975,13 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
// Ensure the URI is not null or empty.
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0213));
throw new InvalidOperationException(SR.GetResourceString(SR.ID0213));
}
// Ensure the URI is a valid absolute URI.
if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri? value) || OpenIddictHelpers.IsImplicitFileUri(value))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0214));
throw new InvalidOperationException(SR.GetResourceString(SR.ID0214));
}
descriptor.RedirectUris.Add(value);
@ -1137,10 +1004,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
var results = await GetValidationResultsAsync(application, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
@ -1196,10 +1060,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
public virtual async ValueTask UpdateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
if (string.IsNullOrEmpty(secret))
{
@ -1227,15 +1088,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask UpdateAsync(TApplication application,
OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentNullException.ThrowIfNull(descriptor);
// Store the original client secret for later comparison.
var comparand = await Store.GetClientSecretAsync(application, cancellationToken);
@ -1262,10 +1116,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
ArgumentNullException.ThrowIfNull(application);
return ExecuteAsync(cancellationToken);
@ -1389,14 +1240,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> ValidateClientSecretAsync(
TApplication application, string secret, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(secret))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0216), nameof(secret));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(secret);
if (await HasClientTypeAsync(application, ClientTypes.Public, cancellationToken))
{
@ -1437,15 +1282,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> ValidatePostLogoutRedirectUriAsync(TApplication application,
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(uri);
foreach (var candidate in await Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken))
{
@ -1508,15 +1346,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
public virtual async ValueTask<bool> ValidateRedirectUriAsync(TApplication application,
[StringSyntax(StringSyntaxAttribute.Uri)] string uri, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0143), nameof(uri));
}
ArgumentNullException.ThrowIfNull(application);
ArgumentException.ThrowIfNullOrEmpty(uri);
foreach (var candidate in await Store.GetRedirectUrisAsync(application, cancellationToken))
{
@ -1579,10 +1410,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
/// </returns>
protected virtual ValueTask<string> ObfuscateClientSecretAsync(string secret, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(secret))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0216), nameof(secret));
}
ArgumentException.ThrowIfNullOrEmpty(secret);
// Note: the PRF, iteration count, salt length and key length currently all match the default values
// used by CryptoHelper and ASP.NET Core Identity but this may change in the future, if necessary.
@ -1644,15 +1472,8 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
protected virtual ValueTask<bool> ValidateClientSecretAsync(
string secret, string comparand, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(secret))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0216), nameof(secret));
}
if (string.IsNullOrEmpty(comparand))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0218), nameof(comparand));
}
ArgumentException.ThrowIfNullOrEmpty(secret);
ArgumentException.ThrowIfNullOrEmpty(comparand);
try
{

203
src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs

@ -90,10 +90,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.CountAsync(query, cancellationToken);
}
@ -108,10 +105,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns>
public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
// If no status was explicitly specified, assume that the authorization is valid.
if (string.IsNullOrEmpty(await Store.GetStatusAsync(authorization, cancellationToken)))
@ -166,10 +160,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<TAuthorization> CreateAsync(
OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
var authorization = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0220));
@ -214,25 +205,10 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
ClaimsPrincipal principal, string subject, string client,
string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default)
{
if (principal is null)
{
throw new ArgumentNullException(nameof(principal));
}
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
if (string.IsNullOrEmpty(client))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type));
}
ArgumentNullException.ThrowIfNull(principal);
ArgumentException.ThrowIfNullOrEmpty(subject);
ArgumentException.ThrowIfNullOrEmpty(client);
ArgumentException.ThrowIfNullOrEmpty(type);
var descriptor = new OpenIddictAuthorizationDescriptor
{
@ -259,10 +235,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns>
public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
if (!Options.CurrentValue.DisableEntityCaching)
{
@ -331,10 +304,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var authorizations = Options.CurrentValue.DisableEntityCaching ?
Store.FindByApplicationIdAsync(identifier, cancellationToken) :
@ -374,10 +344,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns>
public virtual async ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var authorization = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) :
@ -409,10 +376,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<TAuthorization> FindBySubjectAsync(
string subject, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
ArgumentException.ThrowIfNullOrEmpty(subject);
var authorizations = Options.CurrentValue.DisableEntityCaching ?
Store.FindBySubjectAsync(subject, cancellationToken) :
@ -453,10 +417,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetApplicationIdAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetApplicationIdAsync(authorization, cancellationToken);
}
@ -474,10 +435,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return GetAsync(static (authorizations, query) => query(authorizations), query, cancellationToken);
}
@ -498,10 +456,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.GetAsync(query, state, cancellationToken);
}
@ -518,10 +473,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetCreationDateAsync(authorization, cancellationToken);
}
@ -537,10 +489,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns>
public virtual ValueTask<string?> GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetIdAsync(authorization, cancellationToken);
}
@ -557,10 +506,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetPropertiesAsync(authorization, cancellationToken);
}
@ -577,10 +523,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<ImmutableArray<string>> GetScopesAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetScopesAsync(authorization, cancellationToken);
}
@ -597,10 +540,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetStatusAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetStatusAsync(authorization, cancellationToken);
}
@ -617,10 +557,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetSubjectAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetSubjectAsync(authorization, cancellationToken);
}
@ -637,10 +574,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual ValueTask<string?> GetTypeAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return Store.GetTypeAsync(authorization, cancellationToken);
}
@ -655,10 +589,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<bool> HasScopesAsync(TAuthorization authorization,
ImmutableArray<string> scopes, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return (await GetScopesAsync(authorization, cancellationToken))
.ToHashSet(StringComparer.Ordinal)
@ -675,15 +606,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<bool> HasStatusAsync(TAuthorization authorization,
string status, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
if (string.IsNullOrEmpty(status))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status));
}
ArgumentNullException.ThrowIfNull(authorization);
ArgumentException.ThrowIfNullOrEmpty(status);
return string.Equals(await GetStatusAsync(authorization, cancellationToken), status, StringComparison.OrdinalIgnoreCase);
}
@ -698,15 +622,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask<bool> HasTypeAsync(
TAuthorization authorization, string type, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type));
}
ArgumentNullException.ThrowIfNull(authorization);
ArgumentException.ThrowIfNullOrEmpty(type);
return string.Equals(await GetTypeAsync(authorization, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
}
@ -732,10 +649,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return ListAsync(static (authorizations, query) => query(authorizations), query, cancellationToken);
}
@ -753,10 +667,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.ListAsync(query, state, cancellationToken);
}
@ -773,15 +684,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask PopulateAsync(TAuthorization authorization,
OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(authorization);
ArgumentNullException.ThrowIfNull(descriptor);
await Store.SetApplicationIdAsync(authorization, descriptor.ApplicationId, cancellationToken);
await Store.SetCreationDateAsync(authorization, descriptor.CreationDate, cancellationToken);
@ -805,15 +709,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
OpenIddictAuthorizationDescriptor descriptor,
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(descriptor);
ArgumentNullException.ThrowIfNull(authorization);
descriptor.ApplicationId = await Store.GetApplicationIdAsync(authorization, cancellationToken);
descriptor.CreationDate = await Store.GetCreationDateAsync(authorization, cancellationToken);
@ -864,10 +761,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// <returns>The number of authorizations associated with the specified application that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return Store.RevokeByApplicationIdAsync(identifier, cancellationToken);
}
@ -880,10 +774,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// <returns>The number of authorizations associated with the specified subject that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(subject));
}
ArgumentException.ThrowIfNullOrEmpty(subject);
return Store.RevokeBySubjectAsync(subject, cancellationToken);
}
@ -896,10 +787,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// <returns><see langword="true"/> if the authorization was successfully revoked, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRevokeAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
var status = await Store.GetStatusAsync(authorization, cancellationToken);
if (string.Equals(status, Statuses.Revoked, StringComparison.OrdinalIgnoreCase))
@ -943,10 +831,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
/// </returns>
public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
var results = await GetValidationResultsAsync(authorization, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
@ -1001,15 +886,8 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual async ValueTask UpdateAsync(TAuthorization authorization,
OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(authorization);
ArgumentNullException.ThrowIfNull(descriptor);
await PopulateAsync(authorization, descriptor, cancellationToken);
await UpdateAsync(authorization, cancellationToken);
@ -1024,10 +902,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
ArgumentNullException.ThrowIfNull(authorization);
return ExecuteAsync(cancellationToken);

160
src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs

@ -89,10 +89,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.CountAsync(query, cancellationToken);
}
@ -107,10 +104,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
var results = await GetValidationResultsAsync(scope, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
@ -159,10 +153,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<TScope> CreateAsync(
OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
var scope = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0223));
@ -183,10 +174,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
if (!Options.CurrentValue.DisableEntityCaching)
{
@ -207,10 +195,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual async ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var scope = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) :
@ -244,10 +229,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual async ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0202), nameof(name));
}
ArgumentException.ThrowIfNullOrEmpty(name);
var scope = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByNameAsync(name, cancellationToken) :
@ -322,10 +304,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual IAsyncEnumerable<TScope> FindByResourceAsync(
string resource, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(resource))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0062), nameof(resource));
}
ArgumentException.ThrowIfNullOrEmpty(resource);
var scopes = Options.CurrentValue.DisableEntityCaching ?
Store.FindByResourceAsync(resource, cancellationToken) :
@ -368,10 +347,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return GetAsync(static (scopes, query) => query(scopes), query, cancellationToken);
}
@ -392,10 +368,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.GetAsync(query, state, cancellationToken);
}
@ -411,10 +384,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual ValueTask<string?> GetDescriptionAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
return Store.GetDescriptionAsync(scope, cancellationToken);
}
@ -431,10 +401,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync(
TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken);
if (descriptions is not { Count: > 0 })
@ -456,10 +423,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual ValueTask<string?> GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
return Store.GetDisplayNameAsync(scope, cancellationToken);
}
@ -476,10 +440,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(
TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
var names = await Store.GetDisplayNamesAsync(scope, cancellationToken);
if (names is not { Count: > 0 })
@ -501,10 +462,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual ValueTask<string?> GetIdAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
return Store.GetIdAsync(scope, cancellationToken);
}
@ -538,15 +496,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<string?> GetLocalizedDisplayNameAsync(
TScope scope, CultureInfo culture, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
if (culture is null)
{
throw new ArgumentNullException(nameof(culture));
}
ArgumentNullException.ThrowIfNull(scope);
ArgumentNullException.ThrowIfNull(culture);
var names = await Store.GetDisplayNamesAsync(scope, cancellationToken);
if (names is not { Count: > 0 })
@ -598,15 +549,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask<string?> GetLocalizedDescriptionAsync(
TScope scope, CultureInfo culture, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
if (culture is null)
{
throw new ArgumentNullException(nameof(culture));
}
ArgumentNullException.ThrowIfNull(scope);
ArgumentNullException.ThrowIfNull(culture);
var descriptions = await Store.GetDescriptionsAsync(scope, cancellationToken);
if (descriptions is not { Count: > 0 })
@ -640,10 +584,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual ValueTask<string?> GetNameAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
return Store.GetNameAsync(scope, cancellationToken);
}
@ -660,10 +601,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
return Store.GetPropertiesAsync(scope, cancellationToken);
}
@ -680,10 +618,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual ValueTask<ImmutableArray<string>> GetResourcesAsync(
TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
return Store.GetResourcesAsync(scope, cancellationToken);
}
@ -709,10 +644,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return ListAsync(static (scopes, query) => query(scopes), query, cancellationToken);
}
@ -730,10 +662,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.ListAsync(query, state, cancellationToken);
}
@ -773,15 +702,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask PopulateAsync(TScope scope,
OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(scope);
ArgumentNullException.ThrowIfNull(descriptor);
await Store.SetDescriptionAsync(scope, descriptor.Description, cancellationToken);
await Store.SetDescriptionsAsync(scope, descriptor.Descriptions.ToImmutableDictionary(), cancellationToken);
@ -805,15 +727,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
OpenIddictScopeDescriptor descriptor,
TScope scope, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(descriptor);
ArgumentNullException.ThrowIfNull(scope);
descriptor.Description = await Store.GetDescriptionAsync(scope, cancellationToken);
descriptor.DisplayName = await Store.GetDisplayNameAsync(scope, cancellationToken);
@ -850,10 +765,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// </returns>
public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
var results = await GetValidationResultsAsync(scope, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
@ -908,15 +820,8 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual async ValueTask UpdateAsync(TScope scope,
OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(scope);
ArgumentNullException.ThrowIfNull(descriptor);
await PopulateAsync(scope, descriptor, cancellationToken);
await UpdateAsync(scope, cancellationToken);
@ -930,10 +835,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
/// <returns>The validation error encountered when validating the scope.</returns>
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
ArgumentNullException.ThrowIfNull(scope);
return ExecuteAsync(cancellationToken);

230
src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs

@ -89,10 +89,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual ValueTask<long> CountAsync<TResult>(
Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.CountAsync(query, cancellationToken);
}
@ -107,10 +104,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
// If no status was explicitly specified, assume that the token is valid.
if (string.IsNullOrEmpty(await Store.GetStatusAsync(token, cancellationToken)))
@ -173,10 +167,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual async ValueTask<TToken> CreateAsync(
OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);
var token = await Store.InstantiateAsync(cancellationToken) ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0226));
@ -197,10 +188,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
if (!Options.CurrentValue.DisableEntityCaching)
{
@ -260,10 +248,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TToken> FindByApplicationIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var tokens = Options.CurrentValue.DisableEntityCaching ?
Store.FindByApplicationIdAsync(identifier, cancellationToken) :
@ -301,10 +286,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(
string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var tokens = Options.CurrentValue.DisableEntityCaching ?
Store.FindByAuthorizationIdAsync(identifier, cancellationToken) :
@ -344,10 +326,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual async ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
var token = Options.CurrentValue.DisableEntityCaching ?
await Store.FindByIdAsync(identifier, cancellationToken) :
@ -382,10 +361,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual async ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
identifier = await ObfuscateReferenceIdAsync(identifier, cancellationToken);
@ -420,10 +396,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TToken> FindBySubjectAsync(
string subject, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject));
}
ArgumentException.ThrowIfNullOrEmpty(subject);
var tokens = Options.CurrentValue.DisableEntityCaching ?
Store.FindBySubjectAsync(subject, cancellationToken) :
@ -463,10 +436,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<string?> GetApplicationIdAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetApplicationIdAsync(token, cancellationToken);
}
@ -484,10 +454,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual ValueTask<TResult?> GetAsync<TResult>(
Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return GetAsync(static (tokens, query) => query(tokens), query, cancellationToken);
}
@ -508,10 +475,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.GetAsync(query, state, cancellationToken);
}
@ -527,10 +491,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<string?> GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetAuthorizationIdAsync(token, cancellationToken);
}
@ -546,10 +507,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetCreationDateAsync(token, cancellationToken);
}
@ -565,10 +523,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<DateTimeOffset?> GetExpirationDateAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetExpirationDateAsync(token, cancellationToken);
}
@ -584,10 +539,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<string?> GetIdAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetIdAsync(token, cancellationToken);
}
@ -603,10 +555,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<string?> GetPayloadAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetPayloadAsync(token, cancellationToken);
}
@ -623,10 +572,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetPropertiesAsync(token, cancellationToken);
}
@ -642,10 +588,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<DateTimeOffset?> GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetRedemptionDateAsync(token, cancellationToken);
}
@ -663,10 +606,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<string?> GetReferenceIdAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetReferenceIdAsync(token, cancellationToken);
}
@ -682,10 +622,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<string?> GetStatusAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetStatusAsync(token, cancellationToken);
}
@ -701,10 +638,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual ValueTask<string?> GetSubjectAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return Store.GetSubjectAsync(token, cancellationToken);
}
@ -720,10 +654,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual async ValueTask<string?> GetTypeAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return await Store.GetTypeAsync(token, cancellationToken) switch
{
@ -752,15 +683,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token has the specified status, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> HasStatusAsync(TToken token, string status, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
if (string.IsNullOrEmpty(status))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status));
}
ArgumentNullException.ThrowIfNull(token);
ArgumentException.ThrowIfNullOrEmpty(status);
return string.Equals(await GetStatusAsync(token, cancellationToken), status, StringComparison.OrdinalIgnoreCase);
}
@ -774,15 +698,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token has the specified type, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> HasTypeAsync(TToken token, string type, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
if (string.IsNullOrEmpty(type))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type));
}
ArgumentNullException.ThrowIfNull(token);
ArgumentException.ThrowIfNullOrEmpty(type);
return string.Equals(await GetTypeAsync(token, cancellationToken), type, StringComparison.OrdinalIgnoreCase);
}
@ -796,10 +713,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token has any of the specified types, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> HasTypeAsync(TToken token, ImmutableArray<string> types, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
var type = await GetTypeAsync(token, cancellationToken);
if (string.IsNullOrEmpty(type))
@ -839,10 +753,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(
Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return ListAsync(static (tokens, query) => query(tokens), query, cancellationToken);
}
@ -860,10 +771,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default)
{
if (query is null)
{
throw new ArgumentNullException(nameof(query));
}
ArgumentNullException.ThrowIfNull(query);
return Store.ListAsync(query, state, cancellationToken);
}
@ -880,15 +788,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual async ValueTask PopulateAsync(TToken token,
OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(token);
ArgumentNullException.ThrowIfNull(descriptor);
await Store.SetApplicationIdAsync(token, descriptor.ApplicationId, cancellationToken);
await Store.SetAuthorizationIdAsync(token, descriptor.AuthorizationId, cancellationToken);
@ -916,15 +817,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
OpenIddictTokenDescriptor descriptor,
TToken token, CancellationToken cancellationToken = default)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(descriptor);
ArgumentNullException.ThrowIfNull(token);
descriptor.ApplicationId = await Store.GetApplicationIdAsync(token, cancellationToken);
descriptor.AuthorizationId = await Store.GetAuthorizationIdAsync(token, cancellationToken);
@ -974,10 +868,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The number of tokens associated with the specified application that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return Store.RevokeByApplicationIdAsync(identifier, cancellationToken);
}
@ -990,10 +881,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The number of tokens associated with the specified authorization that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
return Store.RevokeByAuthorizationIdAsync(identifier, cancellationToken);
}
@ -1006,10 +894,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The number of tokens associated with the specified subject that were marked as revoked.</returns>
public virtual ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(subject))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(subject));
}
ArgumentException.ThrowIfNullOrEmpty(subject);
return Store.RevokeBySubjectAsync(subject, cancellationToken);
}
@ -1022,10 +907,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token was successfully redemeed, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRedeemAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
// If the token doesn't have a redemption date attached, this likely means it's
// the first time the token is redeemed. In this case, attach the current date.
@ -1068,10 +950,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token was successfully redemeed, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRejectAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
await Store.SetStatusAsync(token, Statuses.Rejected, cancellationToken);
@ -1107,10 +986,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns><see langword="true"/> if the token was successfully revoked, <see langword="false"/> otherwise.</returns>
public virtual async ValueTask<bool> TryRevokeAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
await Store.SetStatusAsync(token, Statuses.Revoked, cancellationToken);
@ -1148,10 +1024,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
var results = await GetValidationResultsAsync(token, cancellationToken);
if (results.Any(result => result != ValidationResult.Success))
@ -1206,15 +1079,8 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
public virtual async ValueTask UpdateAsync(TToken token,
OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(token);
ArgumentNullException.ThrowIfNull(descriptor);
// Store the original reference identifier for later comparison.
var comparand = await Store.GetReferenceIdAsync(token, cancellationToken);
@ -1239,10 +1105,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// <returns>The validation error encountered when validating the token.</returns>
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
ArgumentNullException.ThrowIfNull(token);
return ExecuteAsync(cancellationToken);
@ -1290,10 +1153,7 @@ public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TTok
/// </returns>
protected virtual ValueTask<string> ObfuscateReferenceIdAsync(string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier));
}
ArgumentException.ThrowIfNullOrEmpty(identifier);
// Compute the digest of the generated identifier and use it as the hashed identifier of the reference token.
// Doing that prevents token identifiers stolen from the database from being used as valid reference tokens.

10
src/OpenIddict.Core/OpenIddictCoreBuilder.cs

@ -37,10 +37,7 @@ public sealed class OpenIddictCoreBuilder
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder Configure(Action<OpenIddictCoreOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);
@ -447,10 +444,7 @@ public sealed class OpenIddictCoreBuilder
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder SetEntityCacheLimit(int limit)
{
if (limit < 10)
{
throw new ArgumentException(SR.GetResourceString(SR.ID0233), nameof(limit));
}
ArgumentOutOfRangeException.ThrowIfLessThan(limit, 10);
return Configure(options => options.EntityCacheLimit = limit);
}

16
src/OpenIddict.Core/OpenIddictCoreExtensions.cs

@ -23,10 +23,7 @@ public static class OpenIddictCoreExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictCoreBuilder AddCore(this OpenIddictBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddLogging();
builder.Services.AddMemoryCache();
@ -70,15 +67,8 @@ public static class OpenIddictCoreExtensions
/// <returns>The <see cref="OpenIddictBuilder"/> instance.</returns>
public static OpenIddictBuilder AddCore(this OpenIddictBuilder builder, Action<OpenIddictCoreBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.AddCore());

4
src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj

@ -6,11 +6,7 @@
$(NetCoreTargetFrameworks);
$(NetStandardTargetFrameworks)
</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<IncludeInternalExtensions>false</IncludeInternalExtensions>
<PolySharpIncludeGeneratedTypes>System.Diagnostics.CodeAnalysis.StringSyntaxAttribute</PolySharpIncludeGeneratedTypes>
</PropertyGroup>
<PropertyGroup>

5
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs

@ -39,10 +39,7 @@ public sealed class OpenIddictEntityFrameworkBuilder
/// <returns>The <see cref="OpenIddictEntityFrameworkBuilder"/> instance.</returns>
public OpenIddictEntityFrameworkBuilder Configure(Action<OpenIddictEntityFrameworkOptions> configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(configuration);
Services.Configure(configuration);

16
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs

@ -24,10 +24,7 @@ public static class OpenIddictEntityFrameworkExtensions
/// <returns>The <see cref="OpenIddictEntityFrameworkBuilder"/> instance.</returns>
public static OpenIddictEntityFrameworkBuilder UseEntityFramework(this OpenIddictCoreBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
// Since Entity Framework 6.x may be used with databases performing case-insensitive
// or culture-sensitive comparisons, ensure the additional filtering logic is enforced
@ -64,15 +61,8 @@ public static class OpenIddictEntityFrameworkExtensions
public static OpenIddictCoreBuilder UseEntityFramework(
this OpenIddictCoreBuilder builder, Action<OpenIddictEntityFrameworkBuilder> configuration)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configuration);
configuration(builder.UseEntityFramework());

15
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs

@ -52,10 +52,7 @@ public static class OpenIddictEntityFrameworkHelpers
where TToken : OpenIddictEntityFrameworkToken<TKey, TApplication, TAuthorization>
where TKey : notnull, IEquatable<TKey>
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);
builder.Configurations
.Add(new OpenIddictEntityFrameworkApplicationConfiguration<TApplication, TAuthorization, TToken, TKey>())
@ -75,10 +72,7 @@ public static class OpenIddictEntityFrameworkHelpers
/// <returns>The streamed async enumeration containing the results.</returns>
internal static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IQueryable<T> source, CancellationToken cancellationToken)
{
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);
return ExecuteAsync(source, cancellationToken);
@ -101,10 +95,7 @@ public static class OpenIddictEntityFrameworkHelpers
/// <returns>The <see cref="DbContextTransaction"/> if it could be created, <see langword="null"/> otherwise.</returns>
internal static DbContextTransaction? CreateTransaction(this DbContext context, IsolationLevel level)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
try
{

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save