Browse Source

Add nullable annotations to OpenIddict.Abstractions

pull/1038/head
Kévin Chalet 6 years ago
parent
commit
27ebff1bea
  1. 5
      Directory.Build.props
  2. 1
      Directory.Packages.props
  3. 15
      src/OpenIddict.Abstractions/Caches/IOpenIddictApplicationCache.cs
  4. 26
      src/OpenIddict.Abstractions/Caches/IOpenIddictAuthorizationCache.cs
  5. 11
      src/OpenIddict.Abstractions/Caches/IOpenIddictScopeCache.cs
  6. 26
      src/OpenIddict.Abstractions/Caches/IOpenIddictTokenCache.cs
  7. 28
      src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
  8. 10
      src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs
  9. 15
      src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs
  10. 16
      src/OpenIddict.Abstractions/Descriptors/OpenIddictTokenDescriptor.cs
  11. 81
      src/OpenIddict.Abstractions/Managers/IOpenIddictApplicationManager.cs
  12. 79
      src/OpenIddict.Abstractions/Managers/IOpenIddictAuthorizationManager.cs
  13. 61
      src/OpenIddict.Abstractions/Managers/IOpenIddictScopeManager.cs
  14. 91
      src/OpenIddict.Abstractions/Managers/IOpenIddictTokenManager.cs
  15. 1
      src/OpenIddict.Abstractions/OpenIddict.Abstractions.csproj
  16. 7
      src/OpenIddict.Abstractions/OpenIddictBuilder.cs
  17. 24
      src/OpenIddict.Abstractions/OpenIddictExceptions.cs
  18. 7
      src/OpenIddict.Abstractions/OpenIddictExtensions.cs
  19. 3
      src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs
  20. 286
      src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs
  21. 21
      src/OpenIddict.Abstractions/Primitives/OpenIddictMessage.cs
  22. 107
      src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
  23. 161
      src/OpenIddict.Abstractions/Primitives/OpenIddictRequest.cs
  24. 57
      src/OpenIddict.Abstractions/Primitives/OpenIddictResponse.cs
  25. 17
      src/OpenIddict.Abstractions/Resources/OpenIddictResources.resx
  26. 77
      src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs
  27. 71
      src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs
  28. 61
      src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs
  29. 83
      src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs
  30. 2
      src/OpenIddict.Validation/OpenIddictValidationHandlers.Discovery.cs
  31. 147
      test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictParameterTests.cs

5
Directory.Build.props

@ -62,6 +62,11 @@
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" />
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[3.1.0]" />
</ItemGroup>
<ItemGroup>

1
Directory.Packages.props

@ -21,6 +21,7 @@
<PackageVersion Include="System.Linq.Async" Version="4.1.1" />
<PackageVersion Include="System.Net.Http.Json" Version="3.2.1" />
<PackageVersion Include="System.Text.Json" Version="4.7.2" />
<PackageVersion Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.154" />
</ItemGroup>
<ItemGroup

15
src/OpenIddict.Abstractions/Caches/IOpenIddictApplicationCache.cs

@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -23,7 +22,7 @@ namespace OpenIddict.Abstractions
/// <param name="application">The application to add to the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask AddAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask AddAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves an application using its client identifier.
@ -34,7 +33,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
ValueTask<TApplication> FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TApplication?> FindByClientIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves an application using its unique identifier.
@ -45,7 +44,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
ValueTask<TApplication> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves all the applications associated with the specified redirect_uri.
@ -53,8 +52,7 @@ namespace OpenIddict.Abstractions
/// <param name="address">The redirect_uri associated with the applications.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The client applications corresponding to the specified redirect_uri.</returns>
IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync(
[NotNull] string address, CancellationToken cancellationToken);
IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken);
/// <summary>
/// Retrieves all the applications associated with the specified redirect_uri.
@ -62,8 +60,7 @@ namespace OpenIddict.Abstractions
/// <param name="address">The redirect_uri associated with the applications.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The client applications corresponding to the specified redirect_uri.</returns>
IAsyncEnumerable<TApplication> FindByRedirectUriAsync(
[NotNull] string address, CancellationToken cancellationToken);
IAsyncEnumerable<TApplication> FindByRedirectUriAsync(string address, CancellationToken cancellationToken);
/// <summary>
/// Removes the specified application from the cache.
@ -71,6 +68,6 @@ namespace OpenIddict.Abstractions
/// <param name="application">The application to remove from the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask RemoveAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask RemoveAsync(TApplication application, CancellationToken cancellationToken);
}
}

26
src/OpenIddict.Abstractions/Caches/IOpenIddictAuthorizationCache.cs

@ -8,7 +8,6 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -24,7 +23,7 @@ namespace OpenIddict.Abstractions
/// <param name="authorization">The authorization to add to the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask AddAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask AddAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations corresponding to the specified
@ -34,8 +33,7 @@ namespace OpenIddict.Abstractions
/// <param name="client">The client associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the subject/client.</returns>
IAsyncEnumerable<TAuthorization> FindAsync(
[NotNull] string subject, [NotNull] string client, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> FindAsync(string subject, string client, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -45,8 +43,7 @@ namespace OpenIddict.Abstractions
/// <param name="status">The authorization status.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<TAuthorization> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string status, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> FindAsync(string subject, string client, string status, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -58,8 +55,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<TAuthorization> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string status,
[NotNull] string type, CancellationToken cancellationToken);
string subject, string client, string status,
string type, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -72,8 +69,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<TAuthorization> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string status,
[NotNull] string type, ImmutableArray<string> scopes, CancellationToken cancellationToken);
string subject, string client, string status,
string type, ImmutableArray<string> scopes, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
@ -81,8 +78,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The application identifier associated with the authorizations.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the specified application.</returns>
IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(
[NotNull] string identifier, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves an authorization using its unique identifier.
@ -93,7 +89,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the identifier.
/// </returns>
ValueTask<TAuthorization> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves all the authorizations corresponding to the specified subject.
@ -101,7 +97,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the specified subject.</returns>
IAsyncEnumerable<TAuthorization> FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> FindBySubjectAsync(string subject, CancellationToken cancellationToken);
/// <summary>
/// Removes the specified authorization from the cache.
@ -109,6 +105,6 @@ namespace OpenIddict.Abstractions
/// <param name="authorization">The authorization to remove from the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask RemoveAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask RemoveAsync(TAuthorization authorization, CancellationToken cancellationToken);
}
}

11
src/OpenIddict.Abstractions/Caches/IOpenIddictScopeCache.cs

@ -8,7 +8,6 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -24,7 +23,7 @@ namespace OpenIddict.Abstractions
/// <param name="scope">The scope to add to the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask AddAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask AddAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a scope using its unique identifier.
@ -35,7 +34,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the identifier.
/// </returns>
ValueTask<TScope> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a scope using its name.
@ -46,7 +45,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the specified name.
/// </returns>
ValueTask<TScope> FindByNameAsync([NotNull] string name, CancellationToken cancellationToken);
ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a list of scopes using their name.
@ -62,7 +61,7 @@ namespace OpenIddict.Abstractions
/// <param name="resource">The resource associated with the scopes.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The scopes associated with the specified resource.</returns>
IAsyncEnumerable<TScope> FindByResourceAsync([NotNull] string resource, CancellationToken cancellationToken);
IAsyncEnumerable<TScope> FindByResourceAsync(string resource, CancellationToken cancellationToken);
/// <summary>
/// Removes the specified scope from the cache.
@ -70,6 +69,6 @@ namespace OpenIddict.Abstractions
/// <param name="scope">The scope to remove from the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask RemoveAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask RemoveAsync(TScope scope, CancellationToken cancellationToken);
}
}

26
src/OpenIddict.Abstractions/Caches/IOpenIddictTokenCache.cs

@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -23,7 +22,7 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to add to the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask AddAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask AddAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the tokens corresponding to the specified
@ -33,8 +32,7 @@ namespace OpenIddict.Abstractions
/// <param name="client">The client associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the subject/client.</returns>
IAsyncEnumerable<TToken> FindAsync([NotNull] string subject,
[NotNull] string client, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindAsync(string subject, string client, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the tokens matching the specified parameters.
@ -44,9 +42,7 @@ namespace OpenIddict.Abstractions
/// <param name="status">The token status.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the criteria.</returns>
IAsyncEnumerable<TToken> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindAsync(string subject, string client, string status, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the tokens matching the specified parameters.
@ -58,8 +54,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the criteria.</returns>
IAsyncEnumerable<TToken> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, [NotNull] string type, CancellationToken cancellationToken);
string subject, string client,
string status, string type, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified application identifier.
@ -67,7 +63,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The application identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified application.</returns>
IAsyncEnumerable<TToken> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified authorization identifier.
@ -75,7 +71,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The authorization identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified authorization.</returns>
IAsyncEnumerable<TToken> FindByAuthorizationIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a token using its unique identifier.
@ -86,7 +82,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token corresponding to the unique identifier.
/// </returns>
ValueTask<TToken> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified reference identifier.
@ -98,7 +94,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified reference identifier.
/// </returns>
ValueTask<TToken> FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified subject.
@ -106,7 +102,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified subject.</returns>
IAsyncEnumerable<TToken> FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindBySubjectAsync(string subject, CancellationToken cancellationToken);
/// <summary>
/// Removes the specified token from the cache.
@ -114,6 +110,6 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to remove from the cache.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask RemoveAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask RemoveAsync(TToken token, CancellationToken cancellationToken);
}
}

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

@ -10,29 +10,26 @@ namespace OpenIddict.Abstractions
public class OpenIddictApplicationDescriptor
{
/// <summary>
/// Gets or sets the client identifier
/// associated with the application.
/// Gets or sets the client identifier associated with the application.
/// </summary>
public string ClientId { get; set; }
public string? ClientId { get; set; }
/// <summary>
/// Gets or sets the client secret associated with the application.
/// Note: depending on the application manager used when creating it,
/// this property may be hashed or encrypted for security reasons.
/// </summary>
public string ClientSecret { get; set; }
public string? ClientSecret { get; set; }
/// <summary>
/// Gets or sets the consent type
/// associated with the application.
/// Gets or sets the consent type associated with the application.
/// </summary>
public string ConsentType { get; set; }
public string? ConsentType { get; set; }
/// <summary>
/// Gets or sets the display name
/// associated with the application.
/// Gets or sets the display name associated with the application.
/// </summary>
public string DisplayName { get; set; }
public string? DisplayName { get; set; }
/// <summary>
/// Gets the localized display names associated with the application.
@ -46,14 +43,12 @@ namespace OpenIddict.Abstractions
public HashSet<string> Permissions { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary>
/// Gets the logout callback URLs
/// associated with the application.
/// Gets the logout callback URLs associated with the application.
/// </summary>
public HashSet<Uri> PostLogoutRedirectUris { get; } = new HashSet<Uri>();
/// <summary>
/// Gets the callback URLs
/// associated with the application.
/// Gets the callback URLs associated with the application.
/// </summary>
public HashSet<Uri> RedirectUris { get; } = new HashSet<Uri>();
@ -63,9 +58,8 @@ namespace OpenIddict.Abstractions
public HashSet<string> Requirements { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary>
/// Gets or sets the application type
/// associated with the application.
/// Gets or sets the application type associated with the application.
/// </summary>
public string Type { get; set; }
public string? Type { get; set; }
}
}

10
src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs

@ -12,13 +12,13 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the application identifier associated with the authorization.
/// </summary>
public string ApplicationId { get; set; }
public string? ApplicationId { get; set; }
/// <summary>
/// Gets or sets the optional principal associated with the authorization.
/// Note: this property is not stored by the default authorization stores.
/// </summary>
public ClaimsPrincipal Principal { get; set; }
public ClaimsPrincipal? Principal { get; set; }
/// <summary>
/// Gets the scopes associated with the authorization.
@ -28,16 +28,16 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the status associated with the authorization.
/// </summary>
public string Status { get; set; }
public string? Status { get; set; }
/// <summary>
/// Gets or sets the subject associated with the authorization.
/// </summary>
public string Subject { get; set; }
public string? Subject { get; set; }
/// <summary>
/// Gets or sets the type of the authorization.
/// </summary>
public string Type { get; set; }
public string? Type { get; set; }
}
}

15
src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs

@ -10,10 +10,9 @@ namespace OpenIddict.Abstractions
public class OpenIddictScopeDescriptor
{
/// <summary>
/// Gets or sets the description
/// associated with the scope.
/// Gets or sets the description associated with the scope.
/// </summary>
public string Description { get; set; }
public string? Description { get; set; }
/// <summary>
/// Gets the localized descriptions associated with the scope.
@ -21,10 +20,9 @@ namespace OpenIddict.Abstractions
public Dictionary<CultureInfo, string> Descriptions { get; } = new Dictionary<CultureInfo, string>();
/// <summary>
/// Gets or sets the display name
/// associated with the scope.
/// Gets or sets the display name associated with the scope.
/// </summary>
public string DisplayName { get; set; }
public string? DisplayName { get; set; }
/// <summary>
/// Gets the localized display names associated with the scope.
@ -32,10 +30,9 @@ namespace OpenIddict.Abstractions
public Dictionary<CultureInfo, string> DisplayNames { get; } = new Dictionary<CultureInfo, string>();
/// <summary>
/// Gets or sets the unique name
/// associated with the scope.
/// Gets or sets the unique name associated with the scope.
/// </summary>
public string Name { get; set; }
public string? Name { get; set; }
/// <summary>
/// Gets the resources associated with the scope.

16
src/OpenIddict.Abstractions/Descriptors/OpenIddictTokenDescriptor.cs

@ -11,12 +11,12 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the application identifier associated with the token.
/// </summary>
public string ApplicationId { get; set; }
public string? ApplicationId { get; set; }
/// <summary>
/// Gets or sets the authorization identifier associated with the token.
/// </summary>
public string AuthorizationId { get; set; }
public string? AuthorizationId { get; set; }
/// <summary>
/// Gets or sets the creation date associated with the token.
@ -31,34 +31,34 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the payload associated with the token.
/// </summary>
public string Payload { get; set; }
public string? Payload { get; set; }
/// <summary>
/// Gets or sets the optional principal associated with the token.
/// Note: this property is not stored by the default token stores.
/// </summary>
public ClaimsPrincipal Principal { get; set; }
public ClaimsPrincipal? Principal { get; set; }
/// <summary>
/// Gets or sets the reference identifier associated with the token.
/// Note: depending on the application manager used when creating it,
/// this property may be hashed or encrypted for security reasons.
/// </summary>
public string ReferenceId { get; set; }
public string? ReferenceId { get; set; }
/// <summary>
/// Gets or sets the status associated with the token.
/// </summary>
public string Status { get; set; }
public string? Status { get; set; }
/// <summary>
/// Gets or sets the subject associated with the token.
/// </summary>
public string Subject { get; set; }
public string? Subject { get; set; }
/// <summary>
/// Gets or sets the token type.
/// </summary>
public string Type { get; set; }
public string? Type { get; set; }
}
}

81
src/OpenIddict.Abstractions/Managers/IOpenIddictApplicationManager.cs

@ -6,7 +6,6 @@ using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -40,7 +39,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
ValueTask<long> CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new application based on the specified descriptor.
@ -53,7 +52,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the application.
/// </returns>
ValueTask<object> CreateAsync([NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask<object> CreateAsync(OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new application.
@ -63,7 +62,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask CreateAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask CreateAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new application.
@ -76,7 +75,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask CreateAsync([NotNull] object application, [CanBeNull] string secret, CancellationToken cancellationToken = default);
ValueTask CreateAsync(object application, string? secret, CancellationToken cancellationToken = default);
/// <summary>
/// Removes an existing application.
@ -86,7 +85,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask DeleteAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask DeleteAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves an application using its client identifier.
@ -97,7 +96,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
ValueTask<object> FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
ValueTask<object?> FindByClientIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves an application using its unique identifier.
@ -108,7 +107,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
ValueTask<object> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
ValueTask<object?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves all the applications associated with the specified post_logout_redirect_uri.
@ -116,7 +115,7 @@ namespace OpenIddict.Abstractions
/// <param name="address">The post_logout_redirect_uri associated with the applications.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The client applications corresponding to the specified post_logout_redirect_uri.</returns>
IAsyncEnumerable<object> FindByPostLogoutRedirectUriAsync([NotNull] string address, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves all the applications associated with the specified redirect_uri.
@ -124,7 +123,7 @@ namespace OpenIddict.Abstractions
/// <param name="address">The redirect_uri associated with the applications.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The client applications corresponding to the specified redirect_uri.</returns>
IAsyncEnumerable<object> FindByRedirectUriAsync([NotNull] string address, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -137,7 +136,7 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -152,8 +151,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the client identifier associated with an application.
@ -164,7 +163,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client identifier associated with the application.
/// </returns>
ValueTask<string> GetClientIdAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<string?> GetClientIdAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the client type associated with an application.
@ -175,7 +174,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client type of the application (by default, "public").
/// </returns>
ValueTask<string> GetClientTypeAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<string?> GetClientTypeAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the consent type associated with an application.
@ -186,7 +185,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the consent type of the application (by default, "explicit").
/// </returns>
ValueTask<string> GetConsentTypeAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<string?> GetConsentTypeAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the display name associated with an application.
@ -197,7 +196,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the application.
/// </returns>
ValueTask<string> GetDisplayNameAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<string?> GetDisplayNameAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized display names associated with an application.
@ -208,7 +207,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the localized display names associated with the application.
/// </returns>
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the unique identifier associated with an application.
@ -219,7 +218,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the application.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<string?> GetIdAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized display name associated with an application
@ -232,7 +231,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the matching localized display name associated with the application.
/// </returns>
ValueTask<string> GetLocalizedDisplayNameAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<string?> GetLocalizedDisplayNameAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized display name associated with an application
@ -246,7 +245,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the matching localized display name associated with the application.
/// </returns>
ValueTask<string> GetLocalizedDisplayNameAsync([NotNull] object application, [NotNull] CultureInfo culture, CancellationToken cancellationToken = default);
ValueTask<string?> GetLocalizedDisplayNameAsync(object application, CultureInfo culture, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the permissions associated with an application.
@ -257,7 +256,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the permissions associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetPermissionsAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<ImmutableArray<string>> GetPermissionsAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the logout callback addresses associated with an application.
@ -268,7 +267,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the post_logout_redirect_uri associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the callback addresses associated with an application.
@ -279,7 +278,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the redirect_uri associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetRedirectUrisAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<ImmutableArray<string>> GetRedirectUrisAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the requirements associated with an application.
@ -290,7 +289,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the requirements associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetRequirementsAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask<ImmutableArray<string>> GetRequirementsAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether a given application has the specified client type.
@ -299,7 +298,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The expected client type.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the application has the specified client type, <c>false</c> otherwise.</returns>
ValueTask<bool> HasClientTypeAsync([NotNull] object application, [NotNull] string type, CancellationToken cancellationToken = default);
ValueTask<bool> HasClientTypeAsync(object application, string type, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether a given application has the specified consent type.
@ -308,7 +307,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The expected consent type.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the application has the specified consent type, <c>false</c> otherwise.</returns>
ValueTask<bool> HasConsentTypeAsync([NotNull] object application, [NotNull] string type, CancellationToken cancellationToken = default);
ValueTask<bool> HasConsentTypeAsync(object application, string type, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether the specified permission has been granted to the application.
@ -317,7 +316,7 @@ namespace OpenIddict.Abstractions
/// <param name="permission">The permission.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the application has been granted the specified permission, <c>false</c> otherwise.</returns>
ValueTask<bool> HasPermissionAsync([NotNull] object application, [NotNull] string permission, CancellationToken cancellationToken = default);
ValueTask<bool> HasPermissionAsync(object application, string permission, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether the specified requirement has been enforced for the specified application.
@ -326,7 +325,7 @@ namespace OpenIddict.Abstractions
/// <param name="requirement">The requirement.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the requirement has been enforced for the specified application, <c>false</c> otherwise.</returns>
ValueTask<bool> HasRequirementAsync([NotNull] object application, [NotNull] string requirement, CancellationToken cancellationToken = default);
ValueTask<bool> HasRequirementAsync(object application, string requirement, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -336,7 +335,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<object> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
int? count = null, int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -346,7 +345,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -358,8 +357,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the specified descriptor using the properties exposed by the application.
@ -370,7 +369,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] OpenIddictApplicationDescriptor descriptor, [NotNull] object application, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(OpenIddictApplicationDescriptor descriptor, object application, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the application using the specified descriptor.
@ -381,7 +380,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] object application, [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(object application, OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing application.
@ -391,7 +390,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object application, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing application.
@ -402,7 +401,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object application, [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object application, OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing application and replaces the existing secret.
@ -415,7 +414,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object application, [CanBeNull] string secret, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object application, string? secret, CancellationToken cancellationToken = default);
/// <summary>
/// Validates the application to ensure it's in a consistent state.
@ -423,7 +422,7 @@ namespace OpenIddict.Abstractions
/// <param name="application">The application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The validation error encountered when validating the application.</returns>
IAsyncEnumerable<ValidationResult> ValidateAsync([NotNull] object application, CancellationToken cancellationToken = default);
IAsyncEnumerable<ValidationResult> ValidateAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Validates the client_secret associated with an application.
@ -436,7 +435,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns a boolean indicating whether the client secret was valid.
/// </returns>
ValueTask<bool> ValidateClientSecretAsync([NotNull] object application, [NotNull] string secret, CancellationToken cancellationToken = default);
ValueTask<bool> ValidateClientSecretAsync(object application, string secret, CancellationToken cancellationToken = default);
/// <summary>
/// Validates the redirect_uri to ensure it's associated with an application.
@ -448,6 +447,6 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns a boolean indicating whether the redirect_uri was valid.
/// </returns>
ValueTask<bool> ValidateRedirectUriAsync([NotNull] object application, [NotNull] string address, CancellationToken cancellationToken = default);
ValueTask<bool> ValidateRedirectUriAsync(object application, string address, CancellationToken cancellationToken = default);
}
}

79
src/OpenIddict.Abstractions/Managers/IOpenIddictAuthorizationManager.cs

@ -6,7 +6,6 @@ using System.Linq;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -41,7 +40,7 @@ namespace OpenIddict.Abstractions
/// whose result returns the number of authorizations that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new permanent authorization based on the specified parameters.
@ -56,8 +55,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation, whose result returns the authorization.
/// </returns>
ValueTask<object> CreateAsync(
[NotNull] ClaimsPrincipal principal, [NotNull] string subject, [NotNull] string client,
[NotNull] string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
ClaimsPrincipal principal, string subject, string client,
string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new authorization based on the specified descriptor.
@ -67,7 +66,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation, whose result returns the authorization.
/// </returns>
ValueTask<object> CreateAsync([NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask<object> CreateAsync(OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new authorization.
@ -77,7 +76,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask CreateAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask CreateAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Removes an existing authorization.
@ -87,7 +86,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask DeleteAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask DeleteAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the authorizations corresponding to the specified
@ -97,7 +96,7 @@ namespace OpenIddict.Abstractions
/// <param name="client">The client associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the subject/client.</returns>
IAsyncEnumerable<object> FindAsync([NotNull] string subject, [NotNull] string client, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindAsync(string subject, string client, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -108,8 +107,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<object> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, CancellationToken cancellationToken = default);
string subject, string client,
string status, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -121,8 +120,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<object> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, [NotNull] string type, CancellationToken cancellationToken = default);
string subject, string client,
string status, string type, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -135,8 +134,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<object> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string status,
[NotNull] string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
string subject, string client, string status,
string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
@ -144,7 +143,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The application identifier associated with the authorizations.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the specified application.</returns>
IAsyncEnumerable<object> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves an authorization using its unique identifier.
@ -155,7 +154,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the identifier.
/// </returns>
ValueTask<object> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
ValueTask<object?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves all the authorizations corresponding to the specified subject.
@ -163,7 +162,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the specified subject.</returns>
IAsyncEnumerable<object> FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the optional application identifier associated with an authorization.
@ -174,7 +173,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the application identifier associated with the authorization.
/// </returns>
ValueTask<string> GetApplicationIdAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask<string?> GetApplicationIdAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -187,7 +186,7 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -202,8 +201,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the unique identifier associated with an authorization.
@ -214,7 +213,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the authorization.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask<string?> GetIdAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the scopes associated with an authorization.
@ -225,7 +224,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scopes associated with the specified authorization.
/// </returns>
ValueTask<ImmutableArray<string>> GetScopesAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask<ImmutableArray<string>> GetScopesAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the status associated with an authorization.
@ -236,7 +235,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the status associated with the specified authorization.
/// </returns>
ValueTask<string> GetStatusAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask<string?> GetStatusAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the subject associated with an authorization.
@ -247,7 +246,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the subject associated with the specified authorization.
/// </returns>
ValueTask<string> GetSubjectAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask<string?> GetSubjectAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the type associated with an authorization.
@ -258,7 +257,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the type associated with the specified authorization.
/// </returns>
ValueTask<string> GetTypeAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask<string?> GetTypeAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether the specified scopes are included in the authorization.
@ -267,7 +266,7 @@ namespace OpenIddict.Abstractions
/// <param name="scopes">The scopes.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the scopes are included in the authorization, <c>false</c> otherwise.</returns>
ValueTask<bool> HasScopesAsync([NotNull] object authorization, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
ValueTask<bool> HasScopesAsync(object authorization, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether a given authorization has the specified status.
@ -276,7 +275,7 @@ namespace OpenIddict.Abstractions
/// <param name="status">The expected status.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the authorization has the specified status, <c>false</c> otherwise.</returns>
ValueTask<bool> HasStatusAsync([NotNull] object authorization, [NotNull] string status, CancellationToken cancellationToken = default);
ValueTask<bool> HasStatusAsync(object authorization, string status, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether a given authorization has the specified type.
@ -285,7 +284,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The expected type.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the authorization has the specified type, <c>false</c> otherwise.</returns>
ValueTask<bool> HasTypeAsync([NotNull] object authorization, [NotNull] string type, CancellationToken cancellationToken = default);
ValueTask<bool> HasTypeAsync(object authorization, string type, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -295,7 +294,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<object> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
int? count = null, int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -305,7 +304,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -317,8 +316,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the specified descriptor using the properties exposed by the authorization.
@ -329,7 +328,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] OpenIddictAuthorizationDescriptor descriptor, [NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(OpenIddictAuthorizationDescriptor descriptor, object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the authorization using the specified descriptor.
@ -340,7 +339,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] object authorization, [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(object authorization, OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Removes the authorizations that are marked as invalid and the ad-hoc ones that have no valid/nonexpired token attached.
@ -360,7 +359,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask SetApplicationIdAsync([NotNull] object authorization, [CanBeNull] string identifier, CancellationToken cancellationToken = default);
ValueTask SetApplicationIdAsync(object authorization, string? identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Tries to revoke an authorization.
@ -368,7 +367,7 @@ namespace OpenIddict.Abstractions
/// <param name="authorization">The authorization to revoke.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the authorization was successfully revoked, <c>false</c> otherwise.</returns>
ValueTask<bool> TryRevokeAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask<bool> TryRevokeAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing authorization.
@ -378,7 +377,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing authorization.
@ -389,7 +388,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object authorization, [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object authorization, OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Validates the authorization to ensure it's in a consistent state.
@ -397,6 +396,6 @@ namespace OpenIddict.Abstractions
/// <param name="authorization">The authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The validation error encountered when validating the authorization.</returns>
IAsyncEnumerable<ValidationResult> ValidateAsync([NotNull] object authorization, CancellationToken cancellationToken = default);
IAsyncEnumerable<ValidationResult> ValidateAsync(object authorization, CancellationToken cancellationToken = default);
}
}

61
src/OpenIddict.Abstractions/Managers/IOpenIddictScopeManager.cs

@ -6,7 +6,6 @@ using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -40,7 +39,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
ValueTask<long> CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new scope based on the specified descriptor.
@ -50,7 +49,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation, whose result returns the scope.
/// </returns>
ValueTask<object> CreateAsync([NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask<object> CreateAsync(OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new scope.
@ -60,7 +59,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask CreateAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask CreateAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Removes an existing scope.
@ -70,7 +69,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask DeleteAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask DeleteAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves a scope using its unique identifier.
@ -81,7 +80,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the identifier.
/// </returns>
ValueTask<object> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
ValueTask<object?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves a scope using its name.
@ -92,7 +91,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the specified name.
/// </returns>
ValueTask<object> FindByNameAsync([NotNull] string name, CancellationToken cancellationToken = default);
ValueTask<object?> FindByNameAsync(string name, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves a list of scopes using their name.
@ -108,7 +107,7 @@ namespace OpenIddict.Abstractions
/// <param name="resource">The resource associated with the scopes.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The scopes associated with the specified resource.</returns>
IAsyncEnumerable<object> FindByResourceAsync([NotNull] string resource, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindByResourceAsync(string resource, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -121,7 +120,7 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -136,8 +135,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the description associated with a scope.
@ -148,7 +147,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the description associated with the specified scope.
/// </returns>
ValueTask<string> GetDescriptionAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<string?> GetDescriptionAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized descriptions associated with an scope.
@ -159,7 +158,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the localized descriptions associated with the scope.
/// </returns>
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the display name associated with a scope.
@ -170,7 +169,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the scope.
/// </returns>
ValueTask<string> GetDisplayNameAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<string?> GetDisplayNameAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized display names associated with an scope.
@ -181,7 +180,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the localized display names associated with the scope.
/// </returns>
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the unique identifier associated with a scope.
@ -192,7 +191,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the scope.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<string?> GetIdAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized description associated with an scope
@ -205,7 +204,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the matching localized description associated with the scope.
/// </returns>
ValueTask<string> GetLocalizedDescriptionAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<string?> GetLocalizedDescriptionAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized description associated with an scope
@ -219,7 +218,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the matching localized description associated with the scope.
/// </returns>
ValueTask<string> GetLocalizedDescriptionAsync([NotNull] object scope, [NotNull] CultureInfo culture, CancellationToken cancellationToken = default);
ValueTask<string?> GetLocalizedDescriptionAsync(object scope, CultureInfo culture, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized display name associated with an scope
@ -232,7 +231,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the scope.
/// </returns>
ValueTask<string> GetLocalizedDisplayNameAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<string?> GetLocalizedDisplayNameAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the localized display name associated with an scope
@ -246,7 +245,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the scope.
/// </returns>
ValueTask<string> GetLocalizedDisplayNameAsync([NotNull] object scope, [NotNull] CultureInfo culture, CancellationToken cancellationToken = default);
ValueTask<string?> GetLocalizedDisplayNameAsync(object scope, CultureInfo culture, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the name associated with a scope.
@ -257,7 +256,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the name associated with the specified scope.
/// </returns>
ValueTask<string> GetNameAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<string?> GetNameAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the resources associated with a scope.
@ -268,7 +267,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the resources associated with the scope.
/// </returns>
ValueTask<ImmutableArray<string>> GetResourcesAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask<ImmutableArray<string>> GetResourcesAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -278,7 +277,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<object> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
int? count = null, int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -288,7 +287,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -300,8 +299,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Lists all the resources associated with the specified scopes.
@ -320,7 +319,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] OpenIddictScopeDescriptor descriptor, [NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(OpenIddictScopeDescriptor descriptor, object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the scope using the specified descriptor.
@ -331,7 +330,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] object scope, [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(object scope, OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing scope.
@ -341,7 +340,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object scope, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing scope.
@ -352,7 +351,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object scope, [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object scope, OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Validates the scope to ensure it's in a consistent state.
@ -360,6 +359,6 @@ namespace OpenIddict.Abstractions
/// <param name="scope">The scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The validation error encountered when validating the scope.</returns>
IAsyncEnumerable<ValidationResult> ValidateAsync([NotNull] object scope, CancellationToken cancellationToken = default);
IAsyncEnumerable<ValidationResult> ValidateAsync(object scope, CancellationToken cancellationToken = default);
}
}

91
src/OpenIddict.Abstractions/Managers/IOpenIddictTokenManager.cs

@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -38,7 +37,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of tokens that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
ValueTask<long> CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new token based on the specified descriptor.
@ -48,7 +47,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation, whose result returns the token.
/// </returns>
ValueTask<object> CreateAsync([NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask<object> CreateAsync(OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new token.
@ -58,7 +57,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask CreateAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask CreateAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Removes an existing token.
@ -68,7 +67,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask DeleteAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask DeleteAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the tokens corresponding to the specified
@ -78,8 +77,8 @@ namespace OpenIddict.Abstractions
/// <param name="client">The client associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the subject/client.</returns>
IAsyncEnumerable<object> FindAsync([NotNull] string subject,
[NotNull] string client, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindAsync(string subject,
string client, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the tokens matching the specified parameters.
@ -90,8 +89,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the criteria.</returns>
IAsyncEnumerable<object> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, CancellationToken cancellationToken = default);
string subject, string client,
string status, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the tokens matching the specified parameters.
@ -103,8 +102,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the criteria.</returns>
IAsyncEnumerable<object> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, [NotNull] string type, CancellationToken cancellationToken = default);
string subject, string client,
string status, string type, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified application identifier.
@ -112,7 +111,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The application identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified application.</returns>
IAsyncEnumerable<object> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified authorization identifier.
@ -120,7 +119,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The authorization identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified authorization.</returns>
IAsyncEnumerable<object> FindByAuthorizationIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves a token using its unique identifier.
@ -131,7 +130,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token corresponding to the unique identifier.
/// </returns>
ValueTask<object> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
ValueTask<object?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified reference identifier.
@ -143,7 +142,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified reference identifier.
/// </returns>
ValueTask<object> FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
ValueTask<object?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified subject.
@ -151,7 +150,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified subject.</returns>
IAsyncEnumerable<object> FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken = default);
IAsyncEnumerable<object> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the optional application identifier associated with a token.
@ -162,7 +161,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the application identifier associated with the token.
/// </returns>
ValueTask<string> GetApplicationIdAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetApplicationIdAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -175,7 +174,7 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -190,8 +189,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the optional authorization identifier associated with a token.
@ -202,7 +201,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization identifier associated with the token.
/// </returns>
ValueTask<string> GetAuthorizationIdAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetAuthorizationIdAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the creation date associated with a token.
@ -213,7 +212,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the creation date associated with the specified token.
/// </returns>
ValueTask<DateTimeOffset?> GetCreationDateAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<DateTimeOffset?> GetCreationDateAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the expiration date associated with a token.
@ -224,7 +223,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the expiration date associated with the specified token.
/// </returns>
ValueTask<DateTimeOffset?> GetExpirationDateAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<DateTimeOffset?> GetExpirationDateAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the unique identifier associated with a token.
@ -235,7 +234,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the token.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetIdAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the payload associated with a token.
@ -246,7 +245,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the payload associated with the specified token.
/// </returns>
ValueTask<string> GetPayloadAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetPayloadAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the reference identifier associated with a token.
@ -259,7 +258,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the reference identifier associated with the specified token.
/// </returns>
ValueTask<string> GetReferenceIdAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetReferenceIdAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the status associated with a token.
@ -270,7 +269,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the status associated with the specified token.
/// </returns>
ValueTask<string> GetStatusAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetStatusAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the subject associated with a token.
@ -281,7 +280,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the subject associated with the specified token.
/// </returns>
ValueTask<string> GetSubjectAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetSubjectAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the token type associated with a token.
@ -292,7 +291,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token type associated with the specified token.
/// </returns>
ValueTask<string> GetTypeAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<string?> GetTypeAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether a given token has the specified status.
@ -301,7 +300,7 @@ namespace OpenIddict.Abstractions
/// <param name="status">The expected status.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the token has the specified status, <c>false</c> otherwise.</returns>
ValueTask<bool> HasStatusAsync([NotNull] object token, [NotNull] string status, CancellationToken cancellationToken = default);
ValueTask<bool> HasStatusAsync(object token, string status, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether a given token has the specified type.
@ -310,7 +309,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The expected type.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the token has the specified type, <c>false</c> otherwise.</returns>
ValueTask<bool> HasTypeAsync([NotNull] object token, [NotNull] string type, CancellationToken cancellationToken = default);
ValueTask<bool> HasTypeAsync(object token, string type, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -320,7 +319,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<object> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
int? count = null, int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -330,7 +329,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -342,8 +341,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the specified descriptor using the properties exposed by the token.
@ -354,7 +353,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] OpenIddictTokenDescriptor descriptor, [NotNull] object token, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(OpenIddictTokenDescriptor descriptor, object token, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the token using the specified descriptor.
@ -365,7 +364,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask PopulateAsync([NotNull] object token, [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask PopulateAsync(object token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Removes the tokens that are marked as expired or invalid.
@ -385,7 +384,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask SetApplicationIdAsync([NotNull] object token, [CanBeNull] string identifier, CancellationToken cancellationToken = default);
ValueTask SetApplicationIdAsync(object token, string? identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Sets the authorization identifier associated with a token.
@ -396,7 +395,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask SetAuthorizationIdAsync([NotNull] object token, [CanBeNull] string identifier, CancellationToken cancellationToken = default);
ValueTask SetAuthorizationIdAsync(object token, string? identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Tries to extend the specified token by replacing its expiration date.
@ -405,7 +404,7 @@ namespace OpenIddict.Abstractions
/// <param name="date">The date on which the token will no longer be considered valid.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the token was successfully extended, <c>false</c> otherwise.</returns>
ValueTask<bool> TryExtendAsync([NotNull] object token, [CanBeNull] DateTimeOffset? date, CancellationToken cancellationToken = default);
ValueTask<bool> TryExtendAsync(object token, DateTimeOffset? date, CancellationToken cancellationToken = default);
/// <summary>
/// Tries to redeem a token.
@ -413,7 +412,7 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to redeem.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the token was successfully redemeed, <c>false</c> otherwise.</returns>
ValueTask<bool> TryRedeemAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<bool> TryRedeemAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Tries to reject a token.
@ -421,7 +420,7 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to reject.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the token was successfully redemeed, <c>false</c> otherwise.</returns>
ValueTask<bool> TryRejectAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<bool> TryRejectAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Tries to revoke a token.
@ -429,7 +428,7 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to revoke.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns><c>true</c> if the token was successfully revoked, <c>false</c> otherwise.</returns>
ValueTask<bool> TryRevokeAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask<bool> TryRevokeAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing token.
@ -439,7 +438,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object token, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing token.
@ -450,7 +449,7 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
ValueTask UpdateAsync([NotNull] object token, [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default);
ValueTask UpdateAsync(object token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default);
/// <summary>
/// Validates the token to ensure it's in a consistent state.
@ -458,6 +457,6 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The validation error encountered when validating the token.</returns>
IAsyncEnumerable<ValidationResult> ValidateAsync([NotNull] object token, CancellationToken cancellationToken = default);
IAsyncEnumerable<ValidationResult> ValidateAsync(object token, CancellationToken cancellationToken = default);
}
}

1
src/OpenIddict.Abstractions/OpenIddict.Abstractions.csproj

@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<GenerateResxSourceEmitFormatMethods>true</GenerateResxSourceEmitFormatMethods>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>

7
src/OpenIddict.Abstractions/OpenIddictBuilder.cs

@ -6,7 +6,6 @@
using System;
using System.ComponentModel;
using JetBrains.Annotations;
namespace Microsoft.Extensions.DependencyInjection
{
@ -19,7 +18,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// Initializes a new instance of <see cref="OpenIddictBuilder"/>.
/// </summary>
/// <param name="services">The services collection.</param>
public OpenIddictBuilder([NotNull] IServiceCollection services)
public OpenIddictBuilder(IServiceCollection services)
=> Services = services ?? throw new ArgumentNullException(nameof(services));
/// <summary>
@ -34,7 +33,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="obj">The object to compare with the current object.</param>
/// <returns><c>true</c> if the specified object is equal to the current object; otherwise, false.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals([CanBeNull] object obj) => base.Equals(obj);
public override bool Equals(object? obj) => base.Equals(obj);
/// <summary>
/// Serves as the default hash function.
@ -48,6 +47,6 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary>
/// <returns>A string that represents the current object.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override string ToString() => base.ToString();
public override string? ToString() => base.ToString();
}
}

24
src/OpenIddict.Abstractions/OpenIddictExceptions.cs

@ -18,7 +18,7 @@ namespace OpenIddict.Abstractions
/// Creates a new <see cref="ConcurrencyException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
public ConcurrencyException(string message)
public ConcurrencyException(string? message)
: this(message, exception: null)
{
}
@ -28,7 +28,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="message">The exception message.</param>
/// <param name="exception">The inner exception.</param>
public ConcurrencyException(string message, Exception exception)
public ConcurrencyException(string? message, Exception? exception)
: base(message, exception)
{
}
@ -43,7 +43,7 @@ namespace OpenIddict.Abstractions
/// Creates a new <see cref="GenericException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
public GenericException(string message)
public GenericException(string? message)
: this(message, null)
{
}
@ -53,7 +53,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="message">The exception message.</param>
/// <param name="error">The error type.</param>
public GenericException(string message, string error)
public GenericException(string? message, string? error)
: this(message, error, description: null)
{
}
@ -64,7 +64,7 @@ namespace OpenIddict.Abstractions
/// <param name="message">The exception message.</param>
/// <param name="error">The error type.</param>
/// <param name="description">The error description.</param>
public GenericException(string message, string error, string description)
public GenericException(string? message, string? error, string? description)
: this(message, error, description, uri: null)
{
}
@ -76,7 +76,7 @@ namespace OpenIddict.Abstractions
/// <param name="error">The error type.</param>
/// <param name="description">The error description.</param>
/// <param name="uri">The error URI.</param>
public GenericException(string message, string error, string description, string uri)
public GenericException(string? message, string? error, string? description, string? uri)
: base(message)
{
Error = error;
@ -87,17 +87,17 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets the error type.
/// </summary>
public string Error { get; }
public string? Error { get; }
/// <summary>
/// Gets the error description.
/// </summary>
public string ErrorDescription { get; }
public string? ErrorDescription { get; }
/// <summary>
/// Gets the error URI.
/// </summary>
public string ErrorUri { get; }
public string? ErrorUri { get; }
}
/// <summary>
@ -109,7 +109,7 @@ namespace OpenIddict.Abstractions
/// Creates a new <see cref="ValidationException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
public ValidationException(string message)
public ValidationException(string? message)
: this(message, ImmutableArray.Create<ValidationResult>())
{
}
@ -119,7 +119,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="message">The exception message.</param>
/// <param name="results">The validation results.</param>
public ValidationException(string message, ImmutableArray<ValidationResult> results)
public ValidationException(string? message, ImmutableArray<ValidationResult> results)
: this(message, results, exception: null)
{
}
@ -130,7 +130,7 @@ namespace OpenIddict.Abstractions
/// <param name="message">The exception message.</param>
/// <param name="results">The validation results.</param>
/// <param name="exception">The inner exception.</param>
public ValidationException(string message, ImmutableArray<ValidationResult> results, Exception exception)
public ValidationException(string? message, ImmutableArray<ValidationResult> results, Exception? exception)
: base(message, exception)
{
Results = results;

7
src/OpenIddict.Abstractions/OpenIddictExtensions.cs

@ -5,7 +5,6 @@
*/
using System;
using JetBrains.Annotations;
namespace Microsoft.Extensions.DependencyInjection
{
@ -20,7 +19,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="services">The services collection.</param>
/// <remarks>This extension can be safely called multiple times.</remarks>
/// <returns>The <see cref="OpenIddictBuilder"/>.</returns>
public static OpenIddictBuilder AddOpenIddict([NotNull] this IServiceCollection services)
public static OpenIddictBuilder AddOpenIddict(this IServiceCollection services)
{
if (services == null)
{
@ -37,9 +36,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="configuration">The configuration delegate used to register new services.</param>
/// <remarks>This extension can be safely called multiple times.</remarks>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddOpenIddict(
[NotNull] this IServiceCollection services,
[NotNull] Action<OpenIddictBuilder> configuration)
public static IServiceCollection AddOpenIddict(this IServiceCollection services, Action<OpenIddictBuilder> configuration)
{
if (services == null)
{

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

@ -7,7 +7,6 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using JetBrains.Annotations;
using SR = OpenIddict.Abstractions.OpenIddictResources;
namespace OpenIddict.Abstractions
@ -22,7 +21,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="typeToConvert">The type to convert.</param>
/// <returns><c>true</c> if the type is supported, <c>false</c> otherwise.</returns>
public override bool CanConvert([NotNull] Type typeToConvert)
public override bool CanConvert(Type typeToConvert)
{
if (typeToConvert == null)
{

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

@ -13,7 +13,6 @@ using System.Linq;
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Text.Json;
using JetBrains.Annotations;
using Microsoft.Extensions.Primitives;
using static OpenIddict.Abstractions.OpenIddictConstants;
using SR = OpenIddict.Abstractions.OpenIddictResources;
@ -30,76 +29,56 @@ namespace OpenIddict.Abstractions
/// Extracts the authentication context class values from an <see cref="OpenIddictRequest"/>.
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
public static ImmutableArray<string> GetAcrValues([NotNull] this OpenIddictRequest request)
public static ImmutableArray<string> GetAcrValues(this OpenIddictRequest request)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
if (string.IsNullOrEmpty(request.AcrValues))
{
return ImmutableArray.Create<string>();
}
return GetValues(request.AcrValues, Separators.Space).Distinct(StringComparer.Ordinal).ToImmutableArray();
return GetValues(request.AcrValues, Separators.Space);
}
/// <summary>
/// Extracts the prompt values from an <see cref="OpenIddictRequest"/>.
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
public static ImmutableArray<string> GetPrompts([NotNull] this OpenIddictRequest request)
public static ImmutableArray<string> GetPrompts(this OpenIddictRequest request)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
if (string.IsNullOrEmpty(request.Prompt))
{
return ImmutableArray.Create<string>();
}
return GetValues(request.Prompt, Separators.Space).Distinct(StringComparer.Ordinal).ToImmutableArray();
return GetValues(request.Prompt, Separators.Space);
}
/// <summary>
/// Extracts the response types from an <see cref="OpenIddictRequest"/>.
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
public static ImmutableArray<string> GetResponseTypes([NotNull] this OpenIddictRequest request)
public static ImmutableArray<string> GetResponseTypes(this OpenIddictRequest request)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
if (string.IsNullOrEmpty(request.ResponseType))
{
return ImmutableArray.Create<string>();
}
return GetValues(request.ResponseType, Separators.Space).Distinct(StringComparer.Ordinal).ToImmutableArray();
return GetValues(request.ResponseType, Separators.Space);
}
/// <summary>
/// Extracts the scopes from an <see cref="OpenIddictRequest"/>.
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
public static ImmutableArray<string> GetScopes([NotNull] this OpenIddictRequest request)
public static ImmutableArray<string> GetScopes(this OpenIddictRequest request)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
if (string.IsNullOrEmpty(request.Scope))
{
return ImmutableArray.Create<string>();
}
return GetValues(request.Scope, Separators.Space).Distinct(StringComparer.Ordinal).ToImmutableArray();
return GetValues(request.Scope, Separators.Space);
}
/// <summary>
@ -107,7 +86,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <param name="value">The component to look for in the parameter.</param>
public static bool HasAcrValue([NotNull] this OpenIddictRequest request, [NotNull] string value)
public static bool HasAcrValue(this OpenIddictRequest request, string value)
{
if (request == null)
{
@ -127,7 +106,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <param name="prompt">The component to look for in the parameter.</param>
public static bool HasPrompt([NotNull] this OpenIddictRequest request, [NotNull] string prompt)
public static bool HasPrompt(this OpenIddictRequest request, string prompt)
{
if (request == null)
{
@ -147,7 +126,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <param name="type">The component to look for in the parameter.</param>
public static bool HasResponseType([NotNull] this OpenIddictRequest request, [NotNull] string type)
public static bool HasResponseType(this OpenIddictRequest request, string type)
{
if (request == null)
{
@ -167,7 +146,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <param name="scope">The component to look for in the parameter.</param>
public static bool HasScope([NotNull] this OpenIddictRequest request, [NotNull] string scope)
public static bool HasScope(this OpenIddictRequest request, string scope)
{
if (request == null)
{
@ -188,7 +167,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is a response_type=none request, <c>false</c> otherwise.</returns>
public static bool IsNoneFlow([NotNull] this OpenIddictRequest request)
public static bool IsNoneFlow(this OpenIddictRequest request)
{
if (request == null)
{
@ -215,7 +194,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is a code flow request, <c>false</c> otherwise.</returns>
public static bool IsAuthorizationCodeFlow([NotNull] this OpenIddictRequest request)
public static bool IsAuthorizationCodeFlow(this OpenIddictRequest request)
{
if (request == null)
{
@ -243,7 +222,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is an implicit flow request, <c>false</c> otherwise.</returns>
public static bool IsImplicitFlow([NotNull] this OpenIddictRequest request)
public static bool IsImplicitFlow(this OpenIddictRequest request)
{
if (request == null)
{
@ -297,7 +276,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is an hybrid flow request, <c>false</c> otherwise.</returns>
public static bool IsHybridFlow([NotNull] this OpenIddictRequest request)
public static bool IsHybridFlow(this OpenIddictRequest request)
{
if (request == null)
{
@ -364,7 +343,7 @@ namespace OpenIddict.Abstractions
/// <c>true</c> if the request specified the fragment response mode or if
/// it's the default value for the requested flow, <c>false</c> otherwise.
/// </returns>
public static bool IsFragmentResponseMode([NotNull] this OpenIddictRequest request)
public static bool IsFragmentResponseMode(this OpenIddictRequest request)
{
if (request == null)
{
@ -397,7 +376,7 @@ namespace OpenIddict.Abstractions
/// <c>true</c> if the request specified the query response mode or if
/// it's the default value for the requested flow, <c>false</c> otherwise.
/// </returns>
public static bool IsQueryResponseMode([NotNull] this OpenIddictRequest request)
public static bool IsQueryResponseMode(this OpenIddictRequest request)
{
if (request == null)
{
@ -429,7 +408,7 @@ namespace OpenIddict.Abstractions
/// <c>true</c> if the request specified the form post response mode or if
/// it's the default value for the requested flow, <c>false</c> otherwise.
/// </returns>
public static bool IsFormPostResponseMode([NotNull] this OpenIddictRequest request)
public static bool IsFormPostResponseMode(this OpenIddictRequest request)
{
if (request == null)
{
@ -445,7 +424,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is a code grant request, <c>false</c> otherwise.</returns>
public static bool IsAuthorizationCodeGrantType([NotNull] this OpenIddictRequest request)
public static bool IsAuthorizationCodeGrantType(this OpenIddictRequest request)
{
if (request == null)
{
@ -461,7 +440,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is a client credentials grant request, <c>false</c> otherwise.</returns>
public static bool IsClientCredentialsGrantType([NotNull] this OpenIddictRequest request)
public static bool IsClientCredentialsGrantType(this OpenIddictRequest request)
{
if (request == null)
{
@ -477,7 +456,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is a device code grant request, <c>false</c> otherwise.</returns>
public static bool IsDeviceCodeGrantType([NotNull] this OpenIddictRequest request)
public static bool IsDeviceCodeGrantType(this OpenIddictRequest request)
{
if (request == null)
{
@ -493,7 +472,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is a password grant request, <c>false</c> otherwise.</returns>
public static bool IsPasswordGrantType([NotNull] this OpenIddictRequest request)
public static bool IsPasswordGrantType(this OpenIddictRequest request)
{
if (request == null)
{
@ -509,7 +488,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="request">The <see cref="OpenIddictRequest"/> instance.</param>
/// <returns><c>true</c> if the request is a refresh token grant request, <c>false</c> otherwise.</returns>
public static bool IsRefreshTokenGrantType([NotNull] this OpenIddictRequest request)
public static bool IsRefreshTokenGrantType(this OpenIddictRequest request)
{
if (request == null)
{
@ -524,14 +503,14 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="claim">The <see cref="Claim"/> instance.</param>
/// <returns>The destinations associated with the claim.</returns>
public static ImmutableArray<string> GetDestinations([NotNull] this Claim claim)
public static ImmutableArray<string> GetDestinations(this Claim claim)
{
if (claim == null)
{
throw new ArgumentNullException(nameof(claim));
}
claim.Properties.TryGetValue(Properties.Destinations, out string destinations);
claim.Properties.TryGetValue(Properties.Destinations, out string? destinations);
if (string.IsNullOrEmpty(destinations))
{
@ -548,7 +527,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="claim">The <see cref="Claim"/> instance.</param>
/// <param name="destination">The required destination.</param>
public static bool HasDestination([NotNull] this Claim claim, [NotNull] string destination)
public static bool HasDestination(this Claim claim, string destination)
{
if (claim == null)
{
@ -560,7 +539,7 @@ namespace OpenIddict.Abstractions
throw new ArgumentException(SR.GetResourceString(SR.ID1180), nameof(destination));
}
claim.Properties.TryGetValue(Properties.Destinations, out string destinations);
claim.Properties.TryGetValue(Properties.Destinations, out string? destinations);
if (string.IsNullOrEmpty(destinations))
{
@ -576,7 +555,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="claim">The <see cref="Claim"/> instance.</param>
/// <param name="destinations">The destinations.</param>
public static Claim SetDestinations([NotNull] this Claim claim, ImmutableArray<string> destinations)
public static Claim SetDestinations(this Claim claim, ImmutableArray<string> destinations)
{
if (claim == null)
{
@ -610,7 +589,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="claim">The <see cref="Claim"/> instance.</param>
/// <param name="destinations">The destinations.</param>
public static Claim SetDestinations([NotNull] this Claim claim, [CanBeNull] IEnumerable<string> destinations)
public static Claim SetDestinations(this Claim claim, IEnumerable<string>? destinations)
=> claim.SetDestinations(destinations?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -618,7 +597,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="claim">The <see cref="Claim"/> instance.</param>
/// <param name="destinations">The destinations.</param>
public static Claim SetDestinations([NotNull] this Claim claim, [CanBeNull] params string[] destinations)
public static Claim SetDestinations(this Claim claim, params string[]? destinations)
=> claim.SetDestinations(destinations?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -626,7 +605,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The principal.</param>
/// <returns>The destinations, returned as a flattened dictionary.</returns>
public static ImmutableDictionary<string, string[]> GetDestinations([NotNull] this ClaimsPrincipal principal)
public static ImmutableDictionary<string, string[]> GetDestinations(this ClaimsPrincipal principal)
{
if (principal == null)
{
@ -664,9 +643,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The principal.</param>
/// <param name="destinations">The destinations, as a flattened dictionary.</param>
/// <returns>The principal.</returns>
public static ClaimsPrincipal SetDestinations(
[NotNull] this ClaimsPrincipal principal,
[NotNull] ImmutableDictionary<string, string[]> destinations)
public static ClaimsPrincipal SetDestinations(this ClaimsPrincipal principal, ImmutableDictionary<string, string[]> destinations)
{
if (principal == null)
{
@ -697,9 +674,7 @@ namespace OpenIddict.Abstractions
/// The delegate filtering the claims: return <c>true</c>
/// to accept the claim, <c>false</c> to remove it.
/// </param>
public static ClaimsIdentity Clone(
[NotNull] this ClaimsIdentity identity,
[NotNull] Func<Claim, bool> filter)
public static ClaimsIdentity Clone(this ClaimsIdentity identity, Func<Claim, bool> filter)
{
if (identity == null)
{
@ -739,9 +714,7 @@ namespace OpenIddict.Abstractions
/// The delegate filtering the claims: return <c>true</c>
/// to accept the claim, <c>false</c> to remove it.
/// </param>
public static ClaimsPrincipal Clone(
[NotNull] this ClaimsPrincipal principal,
[NotNull] Func<Claim, bool> filter)
public static ClaimsPrincipal Clone(this ClaimsPrincipal principal, Func<Claim, bool> filter)
{
if (principal == null)
{
@ -769,9 +742,7 @@ namespace OpenIddict.Abstractions
/// <param name="identity">The identity.</param>
/// <param name="type">The type associated with the claim.</param>
/// <param name="value">The value associated with the claim.</param>
public static ClaimsIdentity AddClaim(
[NotNull] this ClaimsIdentity identity,
[NotNull] string type, [NotNull] string value)
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value)
{
if (identity == null)
{
@ -799,10 +770,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The type associated with the claim.</param>
/// <param name="value">The value associated with the claim.</param>
/// <param name="destinations">The destinations associated with the claim.</param>
public static ClaimsIdentity AddClaim(
[NotNull] this ClaimsIdentity identity,
[NotNull] string type, [NotNull] string value,
[NotNull] ImmutableArray<string> destinations)
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, ImmutableArray<string> destinations)
{
if (identity == null)
{
@ -835,10 +803,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The type associated with the claim.</param>
/// <param name="value">The value associated with the claim.</param>
/// <param name="destinations">The destinations associated with the claim.</param>
public static ClaimsIdentity AddClaim(
[NotNull] this ClaimsIdentity identity,
[NotNull] string type, [NotNull] string value,
[NotNull] params string[] destinations)
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, params string[]? destinations)
=> identity.AddClaim(type, value, destinations?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -847,7 +812,7 @@ namespace OpenIddict.Abstractions
/// <param name="identity">The identity.</param>
/// <param name="type">The type associated with the claim.</param>
/// <returns>The claim value.</returns>
public static string GetClaim([NotNull] this ClaimsIdentity identity, [NotNull] string type)
public static string? GetClaim(this ClaimsIdentity identity, string type)
{
if (identity == null)
{
@ -868,7 +833,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The principal.</param>
/// <param name="type">The type associated with the claim.</param>
/// <returns>The claim value.</returns>
public static string GetClaim([NotNull] this ClaimsPrincipal principal, [NotNull] string type)
public static string? GetClaim(this ClaimsPrincipal principal, string type)
{
if (principal == null)
{
@ -889,7 +854,7 @@ namespace OpenIddict.Abstractions
/// <param name="identity">The identity.</param>
/// <param name="type">The type associated with the claims.</param>
/// <returns>The claim values.</returns>
public static ImmutableArray<string> GetClaims([NotNull] this ClaimsIdentity identity, [NotNull] string type)
public static ImmutableArray<string> GetClaims(this ClaimsIdentity identity, string type)
{
if (identity == null)
{
@ -910,7 +875,7 @@ namespace OpenIddict.Abstractions
/// <param name="identity">The claims identity.</param>
/// <param name="type">The claim type.</param>
/// <returns><c>true</c> if the identity contains at least one claim of the specified type.</returns>
public static bool HasClaim([NotNull] this ClaimsIdentity identity, [NotNull] string type)
public static bool HasClaim(this ClaimsIdentity identity, string type)
{
if (identity == null)
{
@ -931,7 +896,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The principal.</param>
/// <param name="type">The type associated with the claims.</param>
/// <returns>The claim values.</returns>
public static ImmutableArray<string> GetClaims([NotNull] this ClaimsPrincipal principal, [NotNull] string type)
public static ImmutableArray<string> GetClaims(this ClaimsPrincipal principal, string type)
{
if (principal == null)
{
@ -952,7 +917,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="type">The claim type.</param>
/// <returns><c>true</c> if the principal contains at least one claim of the specified type.</returns>
public static bool HasClaim([NotNull] this ClaimsPrincipal principal, [NotNull] string type)
public static bool HasClaim(this ClaimsPrincipal principal, string type)
{
if (principal == null)
{
@ -973,7 +938,7 @@ namespace OpenIddict.Abstractions
/// <param name="identity">The identity.</param>
/// <param name="type">The type associated with the claims.</param>
/// <returns>The claims identity.</returns>
public static ClaimsIdentity RemoveClaims([NotNull] this ClaimsIdentity identity, [NotNull] string type)
public static ClaimsIdentity RemoveClaims(this ClaimsIdentity identity, string type)
{
if (identity == null)
{
@ -999,7 +964,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The principal.</param>
/// <param name="type">The type associated with the claims.</param>
/// <returns>The claims identity.</returns>
public static ClaimsPrincipal RemoveClaims([NotNull] this ClaimsPrincipal principal, [NotNull] string type)
public static ClaimsPrincipal RemoveClaims(this ClaimsPrincipal principal, string type)
{
if (principal == null)
{
@ -1029,9 +994,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The type associated with the claims.</param>
/// <param name="value">The claim value.</param>
/// <returns>The claims identity.</returns>
public static ClaimsIdentity SetClaims(
[NotNull] this ClaimsIdentity identity,
[NotNull] string type, [CanBeNull] string value)
public static ClaimsIdentity SetClaims(this ClaimsIdentity identity, string type, string? value)
{
if (identity == null)
{
@ -1060,9 +1023,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The type associated with the claims.</param>
/// <param name="value">The claim value.</param>
/// <returns>The claims identity.</returns>
public static ClaimsPrincipal SetClaim(
[NotNull] this ClaimsPrincipal principal,
[NotNull] string type, [CanBeNull] string value)
public static ClaimsPrincipal SetClaim(this ClaimsPrincipal principal, string type, string? value)
{
if (principal == null)
{
@ -1091,8 +1052,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The type associated with the claims.</param>
/// <param name="values">The claim values.</param>
/// <returns>The claims identity.</returns>
public static ClaimsIdentity SetClaims([NotNull] this ClaimsIdentity identity,
[NotNull] string type, [NotNull] ImmutableArray<string> values)
public static ClaimsIdentity SetClaims(this ClaimsIdentity identity, string type, ImmutableArray<string> values)
{
if (identity == null)
{
@ -1121,8 +1081,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The type associated with the claims.</param>
/// <param name="values">The claim values.</param>
/// <returns>The claims identity.</returns>
public static ClaimsPrincipal SetClaims([NotNull] this ClaimsPrincipal principal,
[NotNull] string type, [NotNull] ImmutableArray<string> values)
public static ClaimsPrincipal SetClaims(this ClaimsPrincipal principal, string type, ImmutableArray<string> values)
{
if (principal == null)
{
@ -1149,7 +1108,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The creation date or <c>null</c> if the claim cannot be found.</returns>
public static DateTimeOffset? GetCreationDate([NotNull] this ClaimsPrincipal principal)
public static DateTimeOffset? GetCreationDate(this ClaimsPrincipal principal)
{
if (principal == null)
{
@ -1175,7 +1134,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The expiration date or <c>null</c> if the claim cannot be found.</returns>
public static DateTimeOffset? GetExpirationDate([NotNull] this ClaimsPrincipal principal)
public static DateTimeOffset? GetExpirationDate(this ClaimsPrincipal principal)
{
if (principal == null)
{
@ -1201,7 +1160,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The audiences list or an empty set if the claims cannot be found.</returns>
public static ImmutableArray<string> GetAudiences([NotNull] this ClaimsPrincipal principal)
public static ImmutableArray<string> GetAudiences(this ClaimsPrincipal principal)
=> principal.GetClaims(Claims.Private.Audience);
/// <summary>
@ -1209,7 +1168,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The presenters list or an empty set if the claims cannot be found.</returns>
public static ImmutableArray<string> GetPresenters([NotNull] this ClaimsPrincipal principal)
public static ImmutableArray<string> GetPresenters(this ClaimsPrincipal principal)
=> principal.GetClaims(Claims.Private.Presenter);
/// <summary>
@ -1217,7 +1176,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The resources list or an empty set if the claims cannot be found.</returns>
public static ImmutableArray<string> GetResources([NotNull] this ClaimsPrincipal principal)
public static ImmutableArray<string> GetResources(this ClaimsPrincipal principal)
=> principal.GetClaims(Claims.Private.Resource);
/// <summary>
@ -1225,7 +1184,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The scopes list or an empty set if the claim cannot be found.</returns>
public static ImmutableArray<string> GetScopes([NotNull] this ClaimsPrincipal principal)
public static ImmutableArray<string> GetScopes(this ClaimsPrincipal principal)
=> principal.GetClaims(Claims.Private.Scope);
/// <summary>
@ -1233,7 +1192,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The access token lifetime or <c>null</c> if the claim cannot be found.</returns>
public static TimeSpan? GetAccessTokenLifetime([NotNull] this ClaimsPrincipal principal)
public static TimeSpan? GetAccessTokenLifetime(this ClaimsPrincipal principal)
=> GetLifetime(principal, Claims.Private.AccessTokenLifetime);
/// <summary>
@ -1241,7 +1200,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The authorization code lifetime or <c>null</c> if the claim cannot be found.</returns>
public static TimeSpan? GetAuthorizationCodeLifetime([NotNull] this ClaimsPrincipal principal)
public static TimeSpan? GetAuthorizationCodeLifetime(this ClaimsPrincipal principal)
=> GetLifetime(principal, Claims.Private.AuthorizationCodeLifetime);
/// <summary>
@ -1249,7 +1208,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The device code lifetime or <c>null</c> if the claim cannot be found.</returns>
public static TimeSpan? GetDeviceCodeLifetime([NotNull] this ClaimsPrincipal principal)
public static TimeSpan? GetDeviceCodeLifetime(this ClaimsPrincipal principal)
=> GetLifetime(principal, Claims.Private.DeviceCodeLifetime);
/// <summary>
@ -1257,7 +1216,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The identity token lifetime or <c>null</c> if the claim cannot be found.</returns>
public static TimeSpan? GetIdentityTokenLifetime([NotNull] this ClaimsPrincipal principal)
public static TimeSpan? GetIdentityTokenLifetime(this ClaimsPrincipal principal)
=> GetLifetime(principal, Claims.Private.IdentityTokenLifetime);
/// <summary>
@ -1265,7 +1224,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The refresh token lifetime or <c>null</c> if the claim cannot be found.</returns>
public static TimeSpan? GetRefreshTokenLifetime([NotNull] this ClaimsPrincipal principal)
public static TimeSpan? GetRefreshTokenLifetime(this ClaimsPrincipal principal)
=> GetLifetime(principal, Claims.Private.RefreshTokenLifetime);
/// <summary>
@ -1273,7 +1232,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The user code lifetime or <c>null</c> if the claim cannot be found.</returns>
public static TimeSpan? GetUserCodeLifetime([NotNull] this ClaimsPrincipal principal)
public static TimeSpan? GetUserCodeLifetime(this ClaimsPrincipal principal)
=> GetLifetime(principal, Claims.Private.UserCodeLifetime);
/// <summary>
@ -1281,7 +1240,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The unique identifier or <c>null</c> if the claim cannot be found.</returns>
public static string GetAuthorizationId([NotNull] this ClaimsPrincipal principal)
public static string? GetAuthorizationId(this ClaimsPrincipal principal)
=> principal.GetClaim(Claims.Private.AuthorizationId);
/// <summary>
@ -1289,7 +1248,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The unique identifier or <c>null</c> if the claim cannot be found.</returns>
public static string GetTokenId([NotNull] this ClaimsPrincipal principal)
public static string? GetTokenId(this ClaimsPrincipal principal)
=> principal.GetClaim(Claims.Private.TokenId);
/// <summary>
@ -1297,7 +1256,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns>The token type or <c>null</c> if the claim cannot be found.</returns>
public static string GetTokenType([NotNull] this ClaimsPrincipal principal)
public static string? GetTokenType(this ClaimsPrincipal principal)
=> principal.GetClaim(Claims.Private.TokenType);
/// <summary>
@ -1305,7 +1264,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns><c>true</c> if the principal contains at least one audience.</returns>
public static bool HasAudience([NotNull] this ClaimsPrincipal principal)
public static bool HasAudience(this ClaimsPrincipal principal)
=> principal.HasClaim(Claims.Private.Audience);
/// <summary>
@ -1314,7 +1273,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="audience">The audience.</param>
/// <returns><c>true</c> if the principal contains the given audience.</returns>
public static bool HasAudience([NotNull] this ClaimsPrincipal principal, [NotNull] string audience)
public static bool HasAudience(this ClaimsPrincipal principal, string audience)
{
if (principal == null)
{
@ -1334,7 +1293,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns><c>true</c> if the principal contains at least one presenter.</returns>
public static bool HasPresenter([NotNull] this ClaimsPrincipal principal)
public static bool HasPresenter(this ClaimsPrincipal principal)
=> principal.HasClaim(Claims.Private.Presenter);
/// <summary>
@ -1343,7 +1302,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="presenter">The presenter.</param>
/// <returns><c>true</c> if the principal contains the given presenter.</returns>
public static bool HasPresenter([NotNull] this ClaimsPrincipal principal, [NotNull] string presenter)
public static bool HasPresenter(this ClaimsPrincipal principal, string presenter)
{
if (principal == null)
{
@ -1363,7 +1322,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns><c>true</c> if the principal contains at least one resource.</returns>
public static bool HasResource([NotNull] this ClaimsPrincipal principal)
public static bool HasResource(this ClaimsPrincipal principal)
=> principal.HasClaim(Claims.Private.Resource);
/// <summary>
@ -1372,7 +1331,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="resource">The resource.</param>
/// <returns><c>true</c> if the principal contains the given resource.</returns>
public static bool HasResource([NotNull] this ClaimsPrincipal principal, [NotNull] string resource)
public static bool HasResource(this ClaimsPrincipal principal, string resource)
{
if (principal == null)
{
@ -1392,7 +1351,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="principal">The claims principal.</param>
/// <returns><c>true</c> if the principal contains at least one scope.</returns>
public static bool HasScope([NotNull] this ClaimsPrincipal principal)
public static bool HasScope(this ClaimsPrincipal principal)
=> principal.HasClaim(Claims.Private.Scope);
/// <summary>
@ -1401,7 +1360,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="scope">The scope.</param>
/// <returns><c>true</c> if the principal contains the given scope.</returns>
public static bool HasScope([NotNull] this ClaimsPrincipal principal, [NotNull] string scope)
public static bool HasScope(this ClaimsPrincipal principal, string scope)
{
if (principal == null)
{
@ -1422,7 +1381,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="type">The token type.</param>
/// <returns><c>true</c> if the token type matches the specified type.</returns>
public static bool HasTokenType([NotNull] this ClaimsPrincipal principal, [NotNull] string type)
public static bool HasTokenType(this ClaimsPrincipal principal, string type)
{
if (principal == null)
{
@ -1443,7 +1402,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="date">The creation date</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetCreationDate([NotNull] this ClaimsPrincipal principal, [CanBeNull] DateTimeOffset? date)
public static ClaimsPrincipal SetCreationDate(this ClaimsPrincipal principal, DateTimeOffset? date)
=> principal.SetClaim(Claims.Private.CreationDate, date?.ToString("r", CultureInfo.InvariantCulture));
/// <summary>
@ -1452,7 +1411,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="date">The expiration date</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetExpirationDate([NotNull] this ClaimsPrincipal principal, [CanBeNull] DateTimeOffset? date)
public static ClaimsPrincipal SetExpirationDate(this ClaimsPrincipal principal, DateTimeOffset? date)
=> principal.SetClaim(Claims.Private.ExpirationDate, date?.ToString("r", CultureInfo.InvariantCulture));
/// <summary>
@ -1462,8 +1421,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="audiences">The audiences to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetAudiences(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] ImmutableArray<string> audiences)
public static ClaimsPrincipal SetAudiences(this ClaimsPrincipal principal, ImmutableArray<string> audiences)
=> principal.SetClaims(Claims.Private.Audience, audiences);
/// <summary>
@ -1473,8 +1431,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="audiences">The audiences to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetAudiences(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] IEnumerable<string> audiences)
public static ClaimsPrincipal SetAudiences(this ClaimsPrincipal principal, IEnumerable<string>? audiences)
=> principal.SetAudiences(audiences?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1484,8 +1441,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="audiences">The audiences to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetAudiences(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] params string[] audiences)
public static ClaimsPrincipal SetAudiences(this ClaimsPrincipal principal, params string[]? audiences)
=> principal.SetAudiences(audiences?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1495,8 +1451,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="presenters">The presenters to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetPresenters(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] ImmutableArray<string> presenters)
public static ClaimsPrincipal SetPresenters(this ClaimsPrincipal principal, ImmutableArray<string> presenters)
=> principal.SetClaims(Claims.Private.Presenter, presenters);
/// <summary>
@ -1506,8 +1461,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="presenters">The presenters to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetPresenters(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] IEnumerable<string> presenters)
public static ClaimsPrincipal SetPresenters(this ClaimsPrincipal principal, IEnumerable<string>? presenters)
=> principal.SetPresenters(presenters?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1517,8 +1471,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="presenters">The presenters to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetPresenters(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] params string[] presenters)
public static ClaimsPrincipal SetPresenters(this ClaimsPrincipal principal, params string[]? presenters)
=> principal.SetPresenters(presenters?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1528,8 +1481,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="resources">The resources to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetResources(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] ImmutableArray<string> resources)
public static ClaimsPrincipal SetResources(this ClaimsPrincipal principal, ImmutableArray<string> resources)
=> principal.SetClaims(Claims.Private.Resource, resources);
/// <summary>
@ -1539,8 +1491,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="resources">The resources to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetResources(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] IEnumerable<string> resources)
public static ClaimsPrincipal SetResources(this ClaimsPrincipal principal, IEnumerable<string>? resources)
=> principal.SetResources(resources?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1550,8 +1501,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="resources">The resources to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetResources(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] params string[] resources)
public static ClaimsPrincipal SetResources(this ClaimsPrincipal principal, params string[]? resources)
=> principal.SetResources(resources?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1561,8 +1511,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="scopes">The scopes to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetScopes(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] ImmutableArray<string> scopes)
public static ClaimsPrincipal SetScopes(this ClaimsPrincipal principal, ImmutableArray<string> scopes)
=> principal.SetClaims(Claims.Private.Scope, scopes);
/// <summary>
@ -1572,8 +1521,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="scopes">The scopes to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetScopes(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] IEnumerable<string> scopes)
public static ClaimsPrincipal SetScopes(this ClaimsPrincipal principal, IEnumerable<string>? scopes)
=> principal.SetScopes(scopes?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1583,8 +1531,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="scopes">The scopes to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetScopes(
[NotNull] this ClaimsPrincipal principal, [CanBeNull] params string[] scopes)
public static ClaimsPrincipal SetScopes(this ClaimsPrincipal principal, params string[]? scopes)
=> principal.SetScopes(scopes?.ToImmutableArray() ?? ImmutableArray.Create<string>());
/// <summary>
@ -1593,7 +1540,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="lifetime">The access token lifetime to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetAccessTokenLifetime([NotNull] this ClaimsPrincipal principal, TimeSpan? lifetime)
public static ClaimsPrincipal SetAccessTokenLifetime(this ClaimsPrincipal principal, TimeSpan? lifetime)
=> principal.SetClaim(Claims.Private.AccessTokenLifetime, lifetime?.TotalSeconds.ToString(CultureInfo.InvariantCulture));
/// <summary>
@ -1602,7 +1549,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="lifetime">The authorization code lifetime to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetAuthorizationCodeLifetime([NotNull] this ClaimsPrincipal principal, TimeSpan? lifetime)
public static ClaimsPrincipal SetAuthorizationCodeLifetime(this ClaimsPrincipal principal, TimeSpan? lifetime)
=> principal.SetClaim(Claims.Private.AuthorizationCodeLifetime, lifetime?.TotalSeconds.ToString(CultureInfo.InvariantCulture));
/// <summary>
@ -1611,7 +1558,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="lifetime">The device code lifetime to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetDeviceCodeLifetime([NotNull] this ClaimsPrincipal principal, TimeSpan? lifetime)
public static ClaimsPrincipal SetDeviceCodeLifetime(this ClaimsPrincipal principal, TimeSpan? lifetime)
=> principal.SetClaim(Claims.Private.DeviceCodeLifetime, lifetime?.TotalSeconds.ToString(CultureInfo.InvariantCulture));
/// <summary>
@ -1620,7 +1567,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="lifetime">The identity token lifetime to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetIdentityTokenLifetime([NotNull] this ClaimsPrincipal principal, TimeSpan? lifetime)
public static ClaimsPrincipal SetIdentityTokenLifetime(this ClaimsPrincipal principal, TimeSpan? lifetime)
=> principal.SetClaim(Claims.Private.IdentityTokenLifetime, lifetime?.TotalSeconds.ToString(CultureInfo.InvariantCulture));
/// <summary>
@ -1629,7 +1576,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="lifetime">The refresh token lifetime to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetRefreshTokenLifetime([NotNull] this ClaimsPrincipal principal, TimeSpan? lifetime)
public static ClaimsPrincipal SetRefreshTokenLifetime(this ClaimsPrincipal principal, TimeSpan? lifetime)
=> principal.SetClaim(Claims.Private.RefreshTokenLifetime, lifetime?.TotalSeconds.ToString(CultureInfo.InvariantCulture));
/// <summary>
@ -1638,7 +1585,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="lifetime">The user code lifetime to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetUserCodeLifetime([NotNull] this ClaimsPrincipal principal, TimeSpan? lifetime)
public static ClaimsPrincipal SetUserCodeLifetime(this ClaimsPrincipal principal, TimeSpan? lifetime)
=> principal.SetClaim(Claims.Private.UserCodeLifetime, lifetime?.TotalSeconds.ToString(CultureInfo.InvariantCulture));
/// <summary>
@ -1647,7 +1594,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="identifier">The unique identifier to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetAuthorizationId([NotNull] this ClaimsPrincipal principal, string identifier)
public static ClaimsPrincipal SetAuthorizationId(this ClaimsPrincipal principal, string? identifier)
=> principal.SetClaim(Claims.Private.AuthorizationId, identifier);
/// <summary>
@ -1656,7 +1603,7 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="identifier">The unique identifier to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetTokenId([NotNull] this ClaimsPrincipal principal, string identifier)
public static ClaimsPrincipal SetTokenId(this ClaimsPrincipal principal, string? identifier)
=> principal.SetClaim(Claims.Private.TokenId, identifier);
/// <summary>
@ -1665,13 +1612,19 @@ namespace OpenIddict.Abstractions
/// <param name="principal">The claims principal.</param>
/// <param name="type">The token type to store.</param>
/// <returns>The claims principal.</returns>
public static ClaimsPrincipal SetTokenType([NotNull] this ClaimsPrincipal principal, string type)
public static ClaimsPrincipal SetTokenType(this ClaimsPrincipal principal, string? type)
=> principal.SetClaim(Claims.Private.TokenType, type);
private static IEnumerable<string> GetValues(string source, char[] separators)
private static ImmutableArray<string> GetValues(string? source, char[] separators)
{
Debug.Assert(!string.IsNullOrEmpty(source), SR.GetResourceString(SR.ID5000));
Debug.Assert(separators?.Length != 0, SR.GetResourceString(SR.ID5001));
Debug.Assert(separators != null && separators.Length != 0, SR.GetResourceString(SR.ID5001));
if (string.IsNullOrEmpty(source))
{
return ImmutableArray.Create<string>();
}
var builder = ImmutableArray.CreateBuilder<string>();
foreach (var element in new StringTokenizer(source, separators))
{
@ -1681,22 +1634,27 @@ namespace OpenIddict.Abstractions
continue;
}
yield return segment.Value;
if (builder.Contains(segment.Value, StringComparer.Ordinal))
{
continue;
}
builder.Add(segment.Value);
}
yield break;
return builder.ToImmutable();
}
private static bool HasValue(string source, string value, char[] separators)
private static bool HasValue(string? source, string value, char[] separators)
{
Debug.Assert(!string.IsNullOrEmpty(value), SR.GetResourceString(SR.ID5002));
Debug.Assert(separators != null && separators.Length != 0, SR.GetResourceString(SR.ID5001));
if (string.IsNullOrEmpty(source))
{
return false;
}
Debug.Assert(!string.IsNullOrEmpty(value), SR.GetResourceString(SR.ID5002));
Debug.Assert(separators?.Length != 0, SR.GetResourceString(SR.ID5001));
foreach (var element in new StringTokenizer(source, separators))
{
var segment = Trim(element, separators);
@ -1716,7 +1674,7 @@ namespace OpenIddict.Abstractions
private static StringSegment TrimStart(StringSegment segment, char[] separators)
{
Debug.Assert(separators?.Length != 0, SR.GetResourceString(SR.ID5001));
Debug.Assert(separators != null && separators.Length != 0, SR.GetResourceString(SR.ID5001));
var index = segment.Offset;
@ -1735,7 +1693,7 @@ namespace OpenIddict.Abstractions
private static StringSegment TrimEnd(StringSegment segment, char[] separators)
{
Debug.Assert(separators?.Length != 0, SR.GetResourceString(SR.ID5001));
Debug.Assert(separators != null && separators.Length != 0, SR.GetResourceString(SR.ID5001));
var index = segment.Offset + segment.Length - 1;
@ -1754,16 +1712,16 @@ namespace OpenIddict.Abstractions
private static StringSegment Trim(StringSegment segment, char[] separators)
{
Debug.Assert(separators?.Length != 0, SR.GetResourceString(SR.ID5001));
Debug.Assert(separators != null && separators.Length != 0, SR.GetResourceString(SR.ID5001));
return TrimEnd(TrimStart(segment, separators), separators);
}
private static bool IsSeparator(char character, char[] separators)
{
Debug.Assert(separators?.Length != 0, SR.GetResourceString(SR.ID5001));
Debug.Assert(separators != null && separators.Length != 0, SR.GetResourceString(SR.ID5001));
for (var index = 0; index < separators.Length; index++)
for (var index = 0; index < separators!.Length; index++)
{
if (character == separators[index])
{

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

@ -14,7 +14,6 @@ using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using JetBrains.Annotations;
using Microsoft.Extensions.Primitives;
using SR = OpenIddict.Abstractions.OpenIddictResources;
@ -67,7 +66,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict message.
/// </summary>
/// <param name="parameters">The message parameters.</param>
public OpenIddictMessage([NotNull] IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
public OpenIddictMessage(IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
{
if (parameters == null)
{
@ -84,7 +83,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict message.
/// </summary>
/// <param name="parameters">The message parameters.</param>
public OpenIddictMessage([NotNull] IEnumerable<KeyValuePair<string, string>> parameters)
public OpenIddictMessage(IEnumerable<KeyValuePair<string, string?>> parameters)
{
if (parameters == null)
{
@ -112,7 +111,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict message.
/// </summary>
/// <param name="parameters">The message parameters.</param>
public OpenIddictMessage([NotNull] IEnumerable<KeyValuePair<string, string[]>> parameters)
public OpenIddictMessage(IEnumerable<KeyValuePair<string, string?[]?>> parameters)
{
if (parameters == null)
{
@ -139,7 +138,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict message.
/// </summary>
/// <param name="parameters">The message parameters.</param>
public OpenIddictMessage([NotNull] IEnumerable<KeyValuePair<string, StringValues>> parameters)
public OpenIddictMessage(IEnumerable<KeyValuePair<string, StringValues>> parameters)
{
if (parameters == null)
{
@ -189,7 +188,7 @@ namespace OpenIddict.Abstractions
/// <param name="name">The parameter name.</param>
/// <param name="value">The parameter value.</param>
/// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage AddParameter([NotNull] string name, OpenIddictParameter value)
public OpenIddictMessage AddParameter(string name, OpenIddictParameter value)
{
if (string.IsNullOrEmpty(name))
{
@ -211,7 +210,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="name">The parameter name.</param>
/// <returns>The parameter value, or <c>null</c> if it cannot be found.</returns>
public OpenIddictParameter? GetParameter([NotNull] string name)
public OpenIddictParameter? GetParameter(string name)
{
if (string.IsNullOrEmpty(name))
{
@ -238,7 +237,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="name">The parameter name.</param>
/// <returns><c>true</c> if the parameter is present, <c>false</c> otherwise.</returns>
public bool HasParameter([NotNull] string name)
public bool HasParameter(string name)
{
if (string.IsNullOrEmpty(name))
{
@ -253,7 +252,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="name">The parameter name.</param>
/// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage RemoveParameter([NotNull] string name)
public OpenIddictMessage RemoveParameter(string name)
{
if (string.IsNullOrEmpty(name))
{
@ -272,7 +271,7 @@ namespace OpenIddict.Abstractions
/// <param name="name">The parameter name.</param>
/// <param name="value">The parameter value.</param>
/// <returns>The current instance, which allows chaining calls.</returns>
public OpenIddictMessage SetParameter([NotNull] string name, [CanBeNull] OpenIddictParameter? value)
public OpenIddictMessage SetParameter(string name, OpenIddictParameter? value)
{
if (string.IsNullOrEmpty(name))
{
@ -299,7 +298,7 @@ namespace OpenIddict.Abstractions
/// <param name="name">The parameter name.</param>
/// <param name="value">The parameter value.</param>
/// <returns><c>true</c> if the parameter could be found, <c>false</c> otherwise.</returns>
public bool TryGetParameter([NotNull] string name, out OpenIddictParameter value)
public bool TryGetParameter(string name, out OpenIddictParameter value)
{
if (string.IsNullOrEmpty(name))
{

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

@ -12,7 +12,6 @@ using System.Globalization;
using System.Linq;
using System.Text.Encodings.Web;
using System.Text.Json;
using JetBrains.Annotations;
using SR = OpenIddict.Abstractions.OpenIddictResources;
namespace OpenIddict.Abstractions
@ -57,13 +56,13 @@ namespace OpenIddict.Abstractions
/// Initializes a new parameter using the specified value.
/// </summary>
/// <param name="value">The parameter value.</param>
public OpenIddictParameter(string value) => Value = value;
public OpenIddictParameter(string? value) => Value = value;
/// <summary>
/// Initializes a new parameter using the specified value.
/// </summary>
/// <param name="value">The parameter value.</param>
public OpenIddictParameter(string[] value) => Value = value;
public OpenIddictParameter(string?[]? value) => Value = value;
/// <summary>
/// Gets the child item corresponding to the specified index.
@ -86,7 +85,7 @@ namespace OpenIddict.Abstractions
public int Count => Value switch
{
// If the parameter is a primitive array of strings, return its length.
string[] value => value.Length,
string?[] value => value.Length,
// If the parameter is a JSON array, return its length.
JsonElement value when value.ValueKind == JsonValueKind.Array => value.GetArrayLength(),
@ -100,7 +99,7 @@ namespace OpenIddict.Abstractions
/// (e.g bool, string, long), an array of strings or a complex JSON object.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public object Value { get; }
public object? Value { get; }
/// <summary>
/// Determines whether the current <see cref="OpenIddictParameter"/>
@ -121,7 +120,7 @@ namespace OpenIddict.Abstractions
(_, null) => false,
// If the two parameters are string arrays, use SequenceEqual().
(string[] left, string[] right) => left.SequenceEqual(right),
(string?[] left, string?[] right) => left.SequenceEqual(right),
// If the two parameters are JsonElement instances, use the custom comparer.
(JsonElement left, JsonElement right) => Equals(left, right),
@ -220,7 +219,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="obj">The other object to which to compare this instance.</param>
/// <returns><c>true</c> if the two instances are equal, <c>false</c> otherwise.</returns>
public override bool Equals(object obj) => obj is OpenIddictParameter parameter && Equals(parameter);
public override bool Equals(object? obj) => obj is OpenIddictParameter parameter && Equals(parameter);
/// <summary>
/// Returns the hash code of the current <see cref="OpenIddictParameter"/> instance.
@ -295,7 +294,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="name">The name of the child item.</param>
/// <returns>An <see cref="OpenIddictParameter"/> instance containing the item value.</returns>
public OpenIddictParameter? GetNamedParameter([NotNull] string name)
public OpenIddictParameter? GetNamedParameter(string name)
{
if (string.IsNullOrEmpty(name))
{
@ -328,7 +327,7 @@ namespace OpenIddict.Abstractions
throw new ArgumentOutOfRangeException(nameof(index), SR.GetResourceString(SR.ID1192));
}
if (Value is string[] array)
if (Value is string?[] array)
{
// If the specified index goes beyond the
// number of items in the array, return null.
@ -385,7 +384,7 @@ namespace OpenIddict.Abstractions
/// <returns>An enumeration of all the unnamed parameters associated with the current instance.</returns>
public IReadOnlyList<OpenIddictParameter> GetUnnamedParameters()
{
if (Value is string[] array)
if (Value is string?[] array)
{
var parameters = new List<OpenIddictParameter>();
@ -416,12 +415,12 @@ namespace OpenIddict.Abstractions
/// Returns the <see cref="string"/> representation of the current instance.
/// </summary>
/// <returns>The <see cref="string"/> representation associated with the parameter value.</returns>
public override string ToString() => Value switch
public override string? ToString() => Value switch
{
null => string.Empty,
string value => value,
string[] value => string.Join(", ", value),
string value => value,
string?[] value => string.Join(", ", value),
JsonElement value => value.ToString(),
@ -434,11 +433,11 @@ namespace OpenIddict.Abstractions
/// <param name="name">The name of the child item.</param>
/// <param name="value">An <see cref="OpenIddictParameter"/> instance containing the item value.</param>
/// <returns><c>true</c> if the parameter could be found, <c>false</c> otherwise.</returns>
public bool TryGetParameter([NotNull] string name, out OpenIddictParameter value)
public bool TryGetNamedParameter(string name, out OpenIddictParameter value)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID1189), nameof(name));
throw new ArgumentException(SR.GetResourceString(SR.ID1191), nameof(name));
}
if (Value is JsonElement element && element.ValueKind == JsonValueKind.Object &&
@ -454,6 +453,52 @@ namespace OpenIddict.Abstractions
return false;
}
/// <summary>
/// Tries to get the child item corresponding to the specified index.
/// </summary>
/// <param name="index">The index of the child item.</param>
/// <param name="value">An <see cref="OpenIddictParameter"/> instance containing the item value.</param>
/// <returns><c>true</c> if the parameter could be found, <c>false</c> otherwise.</returns>
public bool TryGetUnnamedParameter(int index, out OpenIddictParameter value)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index), SR.GetResourceString(SR.ID1192));
}
if (Value is string?[] array)
{
if (index >= array.Length)
{
value = default;
return false;
}
value = new OpenIddictParameter(array[index]);
return true;
}
if (Value is JsonElement element && element.ValueKind == JsonValueKind.Array)
{
if (index >= element.GetArrayLength())
{
value = default;
return false;
}
value = new OpenIddictParameter(element[index]);
return true;
}
value = default;
return false;
}
/// <summary>
/// Writes the parameter value to the specified JSON writer.
/// </summary>
@ -485,7 +530,7 @@ namespace OpenIddict.Abstractions
writer.WriteStringValue(value);
break;
case string[] value:
case string?[] value:
writer.WriteStartArray();
for (var index = 0; index < value.Length; index++)
@ -654,7 +699,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="parameter">The parameter to convert.</param>
/// <returns>The converted value.</returns>
public static explicit operator string(OpenIddictParameter? parameter) => parameter?.Value switch
public static explicit operator string?(OpenIddictParameter? parameter) => parameter?.Value switch
{
// When the parameter is a null value, return null.
null => null,
@ -692,7 +737,7 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="parameter">The parameter to convert.</param>
/// <returns>The converted value.</returns>
public static explicit operator string[](OpenIddictParameter? parameter)
public static explicit operator string?[]?(OpenIddictParameter? parameter)
{
return parameter?.Value switch
{
@ -700,16 +745,16 @@ namespace OpenIddict.Abstractions
null => null,
// When the parameter is already an array of strings, return it as-is.
string[] value => value,
string?[] value => value,
// When the parameter is a string value, return an array with a single entry.
string value => new string[] { value },
string value => new string?[] { value },
// When the parameter is a boolean value, return an array with its string representation.
bool value => new string[] { value.ToString() },
bool value => new string?[] { value.ToString() },
// When the parameter is an integer, return an array with its string representation.
long value => new string[] { value.ToString(CultureInfo.InvariantCulture) },
long value => new string?[] { value.ToString(CultureInfo.InvariantCulture) },
// When the parameter is a JsonElement representing null, return null.
JsonElement value when value.ValueKind == JsonValueKind.Undefined => null,
@ -717,15 +762,15 @@ namespace OpenIddict.Abstractions
// When the parameter is a JsonElement representing a string, return an array with a single entry.
JsonElement value when value.ValueKind == JsonValueKind.String
=> new string[] { value.GetString() },
=> new string?[] { value.GetString() },
// When the parameter is a JsonElement representing a number, return an array with a single entry.
JsonElement value when value.ValueKind == JsonValueKind.Number
=> new string[] { value.GetInt64().ToString(CultureInfo.InvariantCulture) },
=> new string?[] { value.GetInt64().ToString(CultureInfo.InvariantCulture) },
// When the parameter is a JsonElement representing a boolean, return an array with a single entry.
JsonElement value when value.ValueKind == JsonValueKind.False => new string[] { bool.FalseString },
JsonElement value when value.ValueKind == JsonValueKind.True => new string[] { bool.TrueString },
JsonElement value when value.ValueKind == JsonValueKind.False => new string?[] { bool.FalseString },
JsonElement value when value.ValueKind == JsonValueKind.True => new string?[] { bool.TrueString },
// When the parameter is a JsonElement representing an array of strings, return it.
JsonElement value when value.ValueKind == JsonValueKind.Array => CreateArray(value),
@ -734,7 +779,7 @@ namespace OpenIddict.Abstractions
_ => null
};
static string[] CreateArray(JsonElement value)
static string?[]? CreateArray(JsonElement value)
{
var array = new string[value.GetArrayLength()];
using var enumerator = value.EnumerateArray();
@ -794,14 +839,14 @@ namespace OpenIddict.Abstractions
/// </summary>
/// <param name="value">The value to convert</param>
/// <returns>An <see cref="OpenIddictParameter"/> instance.</returns>
public static implicit operator OpenIddictParameter(string value) => new OpenIddictParameter(value);
public static implicit operator OpenIddictParameter(string? value) => new OpenIddictParameter(value);
/// <summary>
/// Converts an array of strings to an <see cref="OpenIddictParameter"/> instance.
/// </summary>
/// <param name="value">The value to convert</param>
/// <returns>An <see cref="OpenIddictParameter"/> instance.</returns>
public static implicit operator OpenIddictParameter(string[] value) => new OpenIddictParameter(value);
public static implicit operator OpenIddictParameter(string?[]? value) => new OpenIddictParameter(value);
/// <summary>
/// Determines whether a parameter is null or empty.
@ -814,8 +859,8 @@ namespace OpenIddict.Abstractions
{
null => true,
string value => string.IsNullOrEmpty(value),
string[] value => value.Length == 0,
string value => string.IsNullOrEmpty(value),
string?[] value => value.Length == 0,
JsonElement value when value.ValueKind == JsonValueKind.Undefined => true,
JsonElement value when value.ValueKind == JsonValueKind.Null => true,

161
src/OpenIddict.Abstractions/Primitives/OpenIddictRequest.cs

@ -8,7 +8,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;
using JetBrains.Annotations;
using Microsoft.Extensions.Primitives;
namespace OpenIddict.Abstractions
@ -46,7 +45,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict request.
/// </summary>
/// <param name="parameters">The request parameters.</param>
public OpenIddictRequest([NotNull] IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
public OpenIddictRequest(IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
: base(parameters)
{
}
@ -55,7 +54,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict request.
/// </summary>
/// <param name="parameters">The request parameters.</param>
public OpenIddictRequest([NotNull] IEnumerable<KeyValuePair<string, string>> parameters)
public OpenIddictRequest(IEnumerable<KeyValuePair<string, string?>> parameters)
: base(parameters)
{
}
@ -64,7 +63,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict request.
/// </summary>
/// <param name="parameters">The request parameters.</param>
public OpenIddictRequest([NotNull] IEnumerable<KeyValuePair<string, string[]>> parameters)
public OpenIddictRequest(IEnumerable<KeyValuePair<string, string?[]?>> parameters)
: base(parameters)
{
}
@ -73,7 +72,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict request.
/// </summary>
/// <param name="parameters">The request parameters.</param>
public OpenIddictRequest([NotNull] IEnumerable<KeyValuePair<string, StringValues>> parameters)
public OpenIddictRequest(IEnumerable<KeyValuePair<string, StringValues>> parameters)
: base(parameters)
{
}
@ -81,36 +80,36 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the "access_token" parameter.
/// </summary>
public string AccessToken
public string? AccessToken
{
get => (string) GetParameter(OpenIddictConstants.Parameters.AccessToken);
get => (string?) GetParameter(OpenIddictConstants.Parameters.AccessToken);
set => SetParameter(OpenIddictConstants.Parameters.AccessToken, value);
}
/// <summary>
/// Gets or sets the "acr_values" parameter.
/// </summary>
public string AcrValues
public string? AcrValues
{
get => (string) GetParameter(OpenIddictConstants.Parameters.AcrValues);
get => (string?) GetParameter(OpenIddictConstants.Parameters.AcrValues);
set => SetParameter(OpenIddictConstants.Parameters.AcrValues, value);
}
/// <summary>
/// Gets or sets the "assertion" parameter.
/// </summary>
public string Assertion
public string? Assertion
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Assertion);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Assertion);
set => SetParameter(OpenIddictConstants.Parameters.Assertion, value);
}
/// <summary>
/// Gets or sets the "audience" parameters.
/// </summary>
public string[] Audiences
public string[]? Audiences
{
get => (string[]) GetParameter(OpenIddictConstants.Parameters.Audience);
get => (string[]?) GetParameter(OpenIddictConstants.Parameters.Audience);
set => SetParameter(OpenIddictConstants.Parameters.Audience, value);
}
@ -126,135 +125,135 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the "claims_locales" parameter.
/// </summary>
public string ClaimsLocales
public string? ClaimsLocales
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ClaimsLocales);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ClaimsLocales);
set => SetParameter(OpenIddictConstants.Parameters.ClaimsLocales, value);
}
/// <summary>
/// Gets or sets the "client_assertion" parameter.
/// </summary>
public string ClientAssertion
public string? ClientAssertion
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ClientAssertion);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ClientAssertion);
set => SetParameter(OpenIddictConstants.Parameters.ClientAssertion, value);
}
/// <summary>
/// Gets or sets the "client_assertion_type" parameter.
/// </summary>
public string ClientAssertionType
public string? ClientAssertionType
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ClientAssertionType);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ClientAssertionType);
set => SetParameter(OpenIddictConstants.Parameters.ClientAssertionType, value);
}
/// <summary>
/// Gets or sets the "client_id" parameter.
/// </summary>
public string ClientId
public string? ClientId
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ClientId);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ClientId);
set => SetParameter(OpenIddictConstants.Parameters.ClientId, value);
}
/// <summary>
/// Gets or sets the "client_secret" parameter.
/// </summary>
public string ClientSecret
public string? ClientSecret
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ClientSecret);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ClientSecret);
set => SetParameter(OpenIddictConstants.Parameters.ClientSecret, value);
}
/// <summary>
/// Gets or sets the "code" parameter.
/// </summary>
public string Code
public string? Code
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Code);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Code);
set => SetParameter(OpenIddictConstants.Parameters.Code, value);
}
/// <summary>
/// Gets or sets the "code_challenge" parameter.
/// </summary>
public string CodeChallenge
public string? CodeChallenge
{
get => (string) GetParameter(OpenIddictConstants.Parameters.CodeChallenge);
get => (string?) GetParameter(OpenIddictConstants.Parameters.CodeChallenge);
set => SetParameter(OpenIddictConstants.Parameters.CodeChallenge, value);
}
/// <summary>
/// Gets or sets the "code_challenge_method" parameter.
/// </summary>
public string CodeChallengeMethod
public string? CodeChallengeMethod
{
get => (string) GetParameter(OpenIddictConstants.Parameters.CodeChallengeMethod);
get => (string?) GetParameter(OpenIddictConstants.Parameters.CodeChallengeMethod);
set => SetParameter(OpenIddictConstants.Parameters.CodeChallengeMethod, value);
}
/// <summary>
/// Gets or sets the "code_verifier" parameter.
/// </summary>
public string CodeVerifier
public string? CodeVerifier
{
get => (string) GetParameter(OpenIddictConstants.Parameters.CodeVerifier);
get => (string?) GetParameter(OpenIddictConstants.Parameters.CodeVerifier);
set => SetParameter(OpenIddictConstants.Parameters.CodeVerifier, value);
}
/// <summary>
/// Gets or sets the "device_code" parameter.
/// </summary>
public string DeviceCode
public string? DeviceCode
{
get => (string) GetParameter(OpenIddictConstants.Parameters.DeviceCode);
get => (string?) GetParameter(OpenIddictConstants.Parameters.DeviceCode);
set => SetParameter(OpenIddictConstants.Parameters.DeviceCode, value);
}
/// <summary>
/// Gets or sets the "display" parameter.
/// </summary>
public string Display
public string? Display
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Display);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Display);
set => SetParameter(OpenIddictConstants.Parameters.Display, value);
}
/// <summary>
/// Gets or sets the "grant_type" parameter.
/// </summary>
public string GrantType
public string? GrantType
{
get => (string) GetParameter(OpenIddictConstants.Parameters.GrantType);
get => (string?) GetParameter(OpenIddictConstants.Parameters.GrantType);
set => SetParameter(OpenIddictConstants.Parameters.GrantType, value);
}
/// <summary>
/// Gets or sets the "identity_provider" parameter.
/// </summary>
public string IdentityProvider
public string? IdentityProvider
{
get => (string) GetParameter(OpenIddictConstants.Parameters.IdentityProvider);
get => (string?) GetParameter(OpenIddictConstants.Parameters.IdentityProvider);
set => SetParameter(OpenIddictConstants.Parameters.IdentityProvider, value);
}
/// <summary>
/// Gets or sets the "id_token_hint" parameter.
/// </summary>
public string IdTokenHint
public string? IdTokenHint
{
get => (string) GetParameter(OpenIddictConstants.Parameters.IdTokenHint);
get => (string?) GetParameter(OpenIddictConstants.Parameters.IdTokenHint);
set => SetParameter(OpenIddictConstants.Parameters.IdTokenHint, value);
}
/// <summary>
/// Gets or sets the "login_hint" parameter.
/// </summary>
public string LoginHint
public string? LoginHint
{
get => (string) GetParameter(OpenIddictConstants.Parameters.LoginHint);
get => (string?) GetParameter(OpenIddictConstants.Parameters.LoginHint);
set => SetParameter(OpenIddictConstants.Parameters.LoginHint, value);
}
@ -270,144 +269,144 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the "nonce" parameter.
/// </summary>
public string Nonce
public string? Nonce
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Nonce);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Nonce);
set => SetParameter(OpenIddictConstants.Parameters.Nonce, value);
}
/// <summary>
/// Gets or sets the "password" parameter.
/// </summary>
public string Password
public string? Password
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Password);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Password);
set => SetParameter(OpenIddictConstants.Parameters.Password, value);
}
/// <summary>
/// Gets or sets the "post_logout_redirect_uri" parameter.
/// </summary>
public string PostLogoutRedirectUri
public string? PostLogoutRedirectUri
{
get => (string) GetParameter(OpenIddictConstants.Parameters.PostLogoutRedirectUri);
get => (string?) GetParameter(OpenIddictConstants.Parameters.PostLogoutRedirectUri);
set => SetParameter(OpenIddictConstants.Parameters.PostLogoutRedirectUri, value);
}
/// <summary>
/// Gets or sets the "prompt" parameter.
/// </summary>
public string Prompt
public string? Prompt
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Prompt);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Prompt);
set => SetParameter(OpenIddictConstants.Parameters.Prompt, value);
}
/// <summary>
/// Gets or sets the "redirect_uri" parameter.
/// </summary>
public string RedirectUri
public string? RedirectUri
{
get => (string) GetParameter(OpenIddictConstants.Parameters.RedirectUri);
get => (string?) GetParameter(OpenIddictConstants.Parameters.RedirectUri);
set => SetParameter(OpenIddictConstants.Parameters.RedirectUri, value);
}
/// <summary>
/// Gets or sets the "refresh_token" parameter.
/// </summary>
public string RefreshToken
public string? RefreshToken
{
get => (string) GetParameter(OpenIddictConstants.Parameters.RefreshToken);
get => (string?) GetParameter(OpenIddictConstants.Parameters.RefreshToken);
set => SetParameter(OpenIddictConstants.Parameters.RefreshToken, value);
}
/// <summary>
/// Gets or sets the "request" parameter.
/// </summary>
public string Request
public string? Request
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Request);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Request);
set => SetParameter(OpenIddictConstants.Parameters.Request, value);
}
/// <summary>
/// Gets or sets the "request_id" parameter.
/// </summary>
public string RequestId
public string? RequestId
{
get => (string) GetParameter(OpenIddictConstants.Parameters.RequestId);
get => (string?) GetParameter(OpenIddictConstants.Parameters.RequestId);
set => SetParameter(OpenIddictConstants.Parameters.RequestId, value);
}
/// <summary>
/// Gets or sets the "request_uri" parameter.
/// </summary>
public string RequestUri
public string? RequestUri
{
get => (string) GetParameter(OpenIddictConstants.Parameters.RequestUri);
get => (string?) GetParameter(OpenIddictConstants.Parameters.RequestUri);
set => SetParameter(OpenIddictConstants.Parameters.RequestUri, value);
}
/// <summary>
/// Gets or sets the "resource" parameters.
/// </summary>
public string[] Resources
public string[]? Resources
{
get => (string[]) GetParameter(OpenIddictConstants.Parameters.Resource);
get => (string[]?) GetParameter(OpenIddictConstants.Parameters.Resource);
set => SetParameter(OpenIddictConstants.Parameters.Resource, value);
}
/// <summary>
/// Gets or sets the "response_mode" parameter.
/// </summary>
public string ResponseMode
public string? ResponseMode
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ResponseMode);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ResponseMode);
set => SetParameter(OpenIddictConstants.Parameters.ResponseMode, value);
}
/// <summary>
/// Gets or sets the "response_type" parameter.
/// </summary>
public string ResponseType
public string? ResponseType
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ResponseType);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ResponseType);
set => SetParameter(OpenIddictConstants.Parameters.ResponseType, value);
}
/// <summary>
/// Gets or sets the "scope" parameter.
/// </summary>
public string Scope
public string? Scope
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Scope);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Scope);
set => SetParameter(OpenIddictConstants.Parameters.Scope, value);
}
/// <summary>
/// Gets or sets the "state" parameter.
/// </summary>
public string State
public string? State
{
get => (string) GetParameter(OpenIddictConstants.Parameters.State);
get => (string?) GetParameter(OpenIddictConstants.Parameters.State);
set => SetParameter(OpenIddictConstants.Parameters.State, value);
}
/// <summary>
/// Gets or sets the "token" parameter.
/// </summary>
public string Token
public string? Token
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Token);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Token);
set => SetParameter(OpenIddictConstants.Parameters.Token, value);
}
/// <summary>
/// Gets or sets the "token_type_hint" parameter.
/// </summary>
public string TokenTypeHint
public string? TokenTypeHint
{
get => (string) GetParameter(OpenIddictConstants.Parameters.TokenTypeHint);
get => (string?) GetParameter(OpenIddictConstants.Parameters.TokenTypeHint);
set => SetParameter(OpenIddictConstants.Parameters.TokenTypeHint, value);
}
@ -423,27 +422,27 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the "ui_locales" parameter.
/// </summary>
public string UiLocales
public string? UiLocales
{
get => (string) GetParameter(OpenIddictConstants.Parameters.UiLocales);
get => (string?) GetParameter(OpenIddictConstants.Parameters.UiLocales);
set => SetParameter(OpenIddictConstants.Parameters.UiLocales, value);
}
/// <summary>
/// Gets or sets the "user_code" parameter.
/// </summary>
public string UserCode
public string? UserCode
{
get => (string) GetParameter(OpenIddictConstants.Parameters.UserCode);
get => (string?) GetParameter(OpenIddictConstants.Parameters.UserCode);
set => SetParameter(OpenIddictConstants.Parameters.UserCode, value);
}
/// <summary>
/// Gets or sets the "username" parameter.
/// </summary>
public string Username
public string? Username
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Username);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Username);
set => SetParameter(OpenIddictConstants.Parameters.Username, value);
}
}

57
src/OpenIddict.Abstractions/Primitives/OpenIddictResponse.cs

@ -8,7 +8,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;
using JetBrains.Annotations;
using Microsoft.Extensions.Primitives;
namespace OpenIddict.Abstractions
@ -46,7 +45,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict response.
/// </summary>
/// <param name="parameters">The response parameters.</param>
public OpenIddictResponse([NotNull] IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
public OpenIddictResponse(IEnumerable<KeyValuePair<string, OpenIddictParameter>> parameters)
: base(parameters)
{
}
@ -55,7 +54,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict response.
/// </summary>
/// <param name="parameters">The response parameters.</param>
public OpenIddictResponse([NotNull] IEnumerable<KeyValuePair<string, string>> parameters)
public OpenIddictResponse(IEnumerable<KeyValuePair<string, string?>> parameters)
: base(parameters)
{
}
@ -64,7 +63,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict response.
/// </summary>
/// <param name="parameters">The response parameters.</param>
public OpenIddictResponse([NotNull] IEnumerable<KeyValuePair<string, string[]>> parameters)
public OpenIddictResponse(IEnumerable<KeyValuePair<string, string?[]?>> parameters)
: base(parameters)
{
}
@ -73,7 +72,7 @@ namespace OpenIddict.Abstractions
/// Initializes a new OpenIddict response.
/// </summary>
/// <param name="parameters">The response parameters.</param>
public OpenIddictResponse([NotNull] IEnumerable<KeyValuePair<string, StringValues>> parameters)
public OpenIddictResponse(IEnumerable<KeyValuePair<string, StringValues>> parameters)
: base(parameters)
{
}
@ -81,54 +80,54 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the "access_token" parameter.
/// </summary>
public string AccessToken
public string? AccessToken
{
get => (string) GetParameter(OpenIddictConstants.Parameters.AccessToken);
get => (string?) GetParameter(OpenIddictConstants.Parameters.AccessToken);
set => SetParameter(OpenIddictConstants.Parameters.AccessToken, value);
}
/// <summary>
/// Gets or sets the "code" parameter.
/// </summary>
public string Code
public string? Code
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Code);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Code);
set => SetParameter(OpenIddictConstants.Parameters.Code, value);
}
/// <summary>
/// Gets or sets the "device_code" parameter.
/// </summary>
public string DeviceCode
public string? DeviceCode
{
get => (string) GetParameter(OpenIddictConstants.Parameters.DeviceCode);
get => (string?) GetParameter(OpenIddictConstants.Parameters.DeviceCode);
set => SetParameter(OpenIddictConstants.Parameters.DeviceCode, value);
}
/// <summary>
/// Gets or sets the "error" parameter.
/// </summary>
public string Error
public string? Error
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Error);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Error);
set => SetParameter(OpenIddictConstants.Parameters.Error, value);
}
/// <summary>
/// Gets or sets the "error_description" parameter.
/// </summary>
public string ErrorDescription
public string? ErrorDescription
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ErrorDescription);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ErrorDescription);
set => SetParameter(OpenIddictConstants.Parameters.ErrorDescription, value);
}
/// <summary>
/// Gets or sets the "error_uri" parameter.
/// </summary>
public string ErrorUri
public string? ErrorUri
{
get => (string) GetParameter(OpenIddictConstants.Parameters.ErrorUri);
get => (string?) GetParameter(OpenIddictConstants.Parameters.ErrorUri);
set => SetParameter(OpenIddictConstants.Parameters.ErrorUri, value);
}
@ -144,54 +143,54 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets or sets the "id_token" parameter.
/// </summary>
public string IdToken
public string? IdToken
{
get => (string) GetParameter(OpenIddictConstants.Parameters.IdToken);
get => (string?) GetParameter(OpenIddictConstants.Parameters.IdToken);
set => SetParameter(OpenIddictConstants.Parameters.IdToken, value);
}
/// <summary>
/// Gets or sets the "refresh_token" parameter.
/// </summary>
public string RefreshToken
public string? RefreshToken
{
get => (string) GetParameter(OpenIddictConstants.Parameters.RefreshToken);
get => (string?) GetParameter(OpenIddictConstants.Parameters.RefreshToken);
set => SetParameter(OpenIddictConstants.Parameters.RefreshToken, value);
}
/// <summary>
/// Gets or sets the "scope" parameter.
/// </summary>
public string Scope
public string? Scope
{
get => (string) GetParameter(OpenIddictConstants.Parameters.Scope);
get => (string?) GetParameter(OpenIddictConstants.Parameters.Scope);
set => SetParameter(OpenIddictConstants.Parameters.Scope, value);
}
/// <summary>
/// Gets or sets the "state" parameter.
/// </summary>
public string State
public string? State
{
get => (string) GetParameter(OpenIddictConstants.Parameters.State);
get => (string?) GetParameter(OpenIddictConstants.Parameters.State);
set => SetParameter(OpenIddictConstants.Parameters.State, value);
}
/// <summary>
/// Gets or sets the "token_type" parameter.
/// </summary>
public string TokenType
public string? TokenType
{
get => (string) GetParameter(OpenIddictConstants.Parameters.TokenType);
get => (string?) GetParameter(OpenIddictConstants.Parameters.TokenType);
set => SetParameter(OpenIddictConstants.Parameters.TokenType, value);
}
/// <summary>
/// Gets or sets the "user_code" parameter.
/// </summary>
public string UserCode
public string? UserCode
{
get => (string) GetParameter(OpenIddictConstants.Parameters.UserCode);
get => (string?) GetParameter(OpenIddictConstants.Parameters.UserCode);
set => SetParameter(OpenIddictConstants.Parameters.UserCode, value);
}
}

17
src/OpenIddict.Abstractions/Resources/OpenIddictResources.resx

@ -1451,7 +1451,7 @@ Consider creating non-generic classes derived from the default entities for the
<value>Callback URLs must be valid absolute URLs.</value>
</data>
<data name="ID5000" xml:space="preserve">
<value>The source string shouldn't be null or empty.</value>
<value>The '{0}' parameter shouldn't be null or empty at this point.</value>
</data>
<data name="ID5001" xml:space="preserve">
<value>The separators collection shouldn't be null or empty.</value>
@ -1468,6 +1468,21 @@ Consider creating non-generic classes derived from the default entities for the
<data name="ID5005" xml:space="preserve">
<value>ECDsa.ExportParameters() shouldn't return an unnamed curve.</value>
</data>
<data name="ID5006" xml:space="preserve">
<value>The principal shouldn't be null at this point.</value>
</data>
<data name="ID5007" xml:space="preserve">
<value>The response shouldn't be null at this point.</value>
</data>
<data name="ID5008" xml:space="preserve">
<value>The request shouldn't be null at this point.</value>
</data>
<data name="ID5009" xml:space="preserve">
<value>The token type shouldn't be null or empty.</value>
</data>
<data name="ID5010" xml:space="preserve">
<value>The token shouldn't be null or empty at this point.</value>
</data>
<data name="ID7000" xml:space="preserve">
<value>An error occurred while validating the token '{Token}'.</value>
</data>

77
src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs

@ -12,7 +12,6 @@ using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -42,7 +41,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken);
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Creates a new application.
@ -50,7 +49,7 @@ namespace OpenIddict.Abstractions
/// <param name="application">The application to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask CreateAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Removes an existing application.
@ -58,7 +57,7 @@ namespace OpenIddict.Abstractions
/// <param name="application">The application to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask DeleteAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves an application using its unique identifier.
@ -69,7 +68,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
ValueTask<TApplication> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TApplication?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves an application using its client identifier.
@ -80,7 +79,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
ValueTask<TApplication> FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TApplication?> FindByClientIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves all the applications associated with the specified post_logout_redirect_uri.
@ -88,7 +87,7 @@ namespace OpenIddict.Abstractions
/// <param name="address">The post_logout_redirect_uri associated with the applications.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The client applications corresponding to the specified post_logout_redirect_uri.</returns>
IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync([NotNull] string address, CancellationToken cancellationToken);
IAsyncEnumerable<TApplication> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken);
/// <summary>
/// Retrieves all the applications associated with the specified redirect_uri.
@ -96,7 +95,7 @@ namespace OpenIddict.Abstractions
/// <param name="address">The redirect_uri associated with the applications.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The client applications corresponding to the specified redirect_uri.</returns>
IAsyncEnumerable<TApplication> FindByRedirectUriAsync([NotNull] string address, CancellationToken cancellationToken);
IAsyncEnumerable<TApplication> FindByRedirectUriAsync(string address, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns the first element.
@ -111,8 +110,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the client identifier associated with an application.
@ -123,7 +122,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client identifier associated with the application.
/// </returns>
ValueTask<string> GetClientIdAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<string?> GetClientIdAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the client secret associated with an application.
@ -136,7 +135,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client secret associated with the application.
/// </returns>
ValueTask<string> GetClientSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<string?> GetClientSecretAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the client type associated with an application.
@ -147,7 +146,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client type of the application (by default, "public").
/// </returns>
ValueTask<string> GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<string?> GetClientTypeAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the consent type associated with an application.
@ -158,7 +157,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the consent type of the application (by default, "explicit").
/// </returns>
ValueTask<string> GetConsentTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<string?> GetConsentTypeAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the display name associated with an application.
@ -169,7 +168,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the application.
/// </returns>
ValueTask<string> GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<string?> GetDisplayNameAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the localized display names associated with an application.
@ -180,7 +179,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the localized display names associated with the application.
/// </returns>
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the unique identifier associated with an application.
@ -191,7 +190,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the application.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<string?> GetIdAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the permissions associated with an application.
@ -202,7 +201,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the permissions associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetPermissionsAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<ImmutableArray<string>> GetPermissionsAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the logout callback addresses associated with an application.
@ -213,7 +212,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the post_logout_redirect_uri associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the additional properties associated with an application.
@ -224,7 +223,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the application.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the callback addresses associated with an application.
@ -235,7 +234,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the redirect_uri associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<ImmutableArray<string>> GetRedirectUrisAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the requirements associated with an application.
@ -246,7 +245,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the requirements associated with the application.
/// </returns>
ValueTask<ImmutableArray<string>> GetRequirementsAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<ImmutableArray<string>> GetRequirementsAsync(TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Instantiates a new application.
@ -265,7 +264,7 @@ namespace OpenIddict.Abstractions
/// <param name="offset">The number of results to skip.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TApplication> ListAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken);
IAsyncEnumerable<TApplication> ListAsync(int? count, int? offset, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -277,8 +276,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Sets the client identifier associated with an application.
@ -287,7 +286,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The client identifier associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetClientIdAsync([NotNull] TApplication application, [CanBeNull] string identifier, CancellationToken cancellationToken);
ValueTask SetClientIdAsync(TApplication application, string? identifier, CancellationToken cancellationToken);
/// <summary>
/// Sets the client secret associated with an application.
@ -298,7 +297,7 @@ namespace OpenIddict.Abstractions
/// <param name="secret">The client secret associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetClientSecretAsync([NotNull] TApplication application, [CanBeNull] string secret, CancellationToken cancellationToken);
ValueTask SetClientSecretAsync(TApplication application, string? secret, CancellationToken cancellationToken);
/// <summary>
/// Sets the client type associated with an application.
@ -307,7 +306,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The client type associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetClientTypeAsync([NotNull] TApplication application, [CanBeNull] string type, CancellationToken cancellationToken);
ValueTask SetClientTypeAsync(TApplication application, string? type, CancellationToken cancellationToken);
/// <summary>
/// Sets the consent type associated with an application.
@ -316,7 +315,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The consent type associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetConsentTypeAsync([NotNull] TApplication application, [CanBeNull] string type, CancellationToken cancellationToken);
ValueTask SetConsentTypeAsync(TApplication application, string? type, CancellationToken cancellationToken);
/// <summary>
/// Sets the display name associated with an application.
@ -325,7 +324,7 @@ namespace OpenIddict.Abstractions
/// <param name="name">The display name associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetDisplayNameAsync([NotNull] TApplication application, [CanBeNull] string name, CancellationToken cancellationToken);
ValueTask SetDisplayNameAsync(TApplication application, string? name, CancellationToken cancellationToken);
/// <summary>
/// Sets the localized display names associated with an application.
@ -334,8 +333,8 @@ namespace OpenIddict.Abstractions
/// <param name="names">The localized display names associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetDisplayNamesAsync([NotNull] TApplication application,
[CanBeNull] ImmutableDictionary<CultureInfo, string> names, CancellationToken cancellationToken);
ValueTask SetDisplayNamesAsync(TApplication application,
ImmutableDictionary<CultureInfo, string> names, CancellationToken cancellationToken);
/// <summary>
/// Sets the permissions associated with an application.
@ -344,7 +343,7 @@ namespace OpenIddict.Abstractions
/// <param name="permissions">The permissions associated with the application </param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPermissionsAsync([NotNull] TApplication application, ImmutableArray<string> permissions, CancellationToken cancellationToken);
ValueTask SetPermissionsAsync(TApplication application, ImmutableArray<string> permissions, CancellationToken cancellationToken);
/// <summary>
/// Sets the logout callback addresses associated with an application.
@ -353,7 +352,7 @@ namespace OpenIddict.Abstractions
/// <param name="addresses">The logout callback addresses associated with the application </param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPostLogoutRedirectUrisAsync([NotNull] TApplication application,
ValueTask SetPostLogoutRedirectUrisAsync(TApplication application,
ImmutableArray<string> addresses, CancellationToken cancellationToken);
/// <summary>
@ -363,8 +362,8 @@ namespace OpenIddict.Abstractions
/// <param name="properties">The additional properties associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TApplication application,
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
ValueTask SetPropertiesAsync(TApplication application,
ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the callback addresses associated with an application.
@ -373,7 +372,7 @@ namespace OpenIddict.Abstractions
/// <param name="addresses">The callback addresses associated with the application </param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetRedirectUrisAsync([NotNull] TApplication application,
ValueTask SetRedirectUrisAsync(TApplication application,
ImmutableArray<string> addresses, CancellationToken cancellationToken);
/// <summary>
@ -383,7 +382,7 @@ namespace OpenIddict.Abstractions
/// <param name="requirements">The requirements associated with the application </param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetRequirementsAsync([NotNull] TApplication application, ImmutableArray<string> requirements, CancellationToken cancellationToken);
ValueTask SetRequirementsAsync(TApplication application, ImmutableArray<string> requirements, CancellationToken cancellationToken);
/// <summary>
/// Updates an existing application.
@ -391,6 +390,6 @@ namespace OpenIddict.Abstractions
/// <param name="application">The application to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask UpdateAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken);
}
}

71
src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs

@ -11,7 +11,6 @@ using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -41,7 +40,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of authorizations that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken);
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Creates a new authorization.
@ -49,7 +48,7 @@ namespace OpenIddict.Abstractions
/// <param name="authorization">The authorization to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Removes an existing authorization.
@ -57,7 +56,7 @@ namespace OpenIddict.Abstractions
/// <param name="authorization">The authorization to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask DeleteAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations corresponding to the specified
@ -67,7 +66,7 @@ namespace OpenIddict.Abstractions
/// <param name="client">The client associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the subject/client.</returns>
IAsyncEnumerable<TAuthorization> FindAsync([NotNull] string subject, [NotNull] string client, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> FindAsync(string subject, string client, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -78,8 +77,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<TAuthorization> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, CancellationToken cancellationToken);
string subject, string client,
string status, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -91,8 +90,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<TAuthorization> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, [NotNull] string type, CancellationToken cancellationToken);
string subject, string client,
string status, string type, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -105,8 +104,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the criteria.</returns>
IAsyncEnumerable<TAuthorization> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, [NotNull] string type,
string subject, string client,
string status, string type,
ImmutableArray<string> scopes, CancellationToken cancellationToken);
/// <summary>
@ -115,7 +114,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The application identifier associated with the authorizations.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the specified application.</returns>
IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves an authorization using its unique identifier.
@ -126,7 +125,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the identifier.
/// </returns>
ValueTask<TAuthorization> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TAuthorization?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves all the authorizations corresponding to the specified subject.
@ -134,7 +133,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The authorizations corresponding to the specified subject.</returns>
IAsyncEnumerable<TAuthorization> FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> FindBySubjectAsync(string subject, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the optional application identifier associated with an authorization.
@ -145,7 +144,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the application identifier associated with the authorization.
/// </returns>
ValueTask<string> GetApplicationIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<string?> GetApplicationIdAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns the first element.
@ -160,8 +159,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the unique identifier associated with an authorization.
@ -172,7 +171,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the authorization.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<string?> GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the additional properties associated with an authorization.
@ -183,7 +182,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the authorization.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the scopes associated with an authorization.
@ -194,7 +193,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scopes associated with the specified authorization.
/// </returns>
ValueTask<ImmutableArray<string>> GetScopesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<ImmutableArray<string>> GetScopesAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the status associated with an authorization.
@ -205,7 +204,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the status associated with the specified authorization.
/// </returns>
ValueTask<string> GetStatusAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<string?> GetStatusAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the subject associated with an authorization.
@ -216,7 +215,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the subject associated with the specified authorization.
/// </returns>
ValueTask<string> GetSubjectAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<string?> GetSubjectAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the type associated with an authorization.
@ -227,7 +226,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the type associated with the specified authorization.
/// </returns>
ValueTask<string> GetTypeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<string?> GetTypeAsync(TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Instantiates a new authorization.
@ -246,7 +245,7 @@ namespace OpenIddict.Abstractions
/// <param name="offset">The number of results to skip.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TAuthorization> ListAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken);
IAsyncEnumerable<TAuthorization> ListAsync(int? count, int? offset, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -258,8 +257,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Removes the authorizations that are marked as invalid and the ad-hoc ones that have no valid/nonexpired token attached.
@ -275,8 +274,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The unique identifier associated with the client application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetApplicationIdAsync([NotNull] TAuthorization authorization,
[CanBeNull] string identifier, CancellationToken cancellationToken);
ValueTask SetApplicationIdAsync(TAuthorization authorization, string? identifier, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with an authorization.
@ -285,8 +283,8 @@ namespace OpenIddict.Abstractions
/// <param name="properties">The additional properties associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization,
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
ValueTask SetPropertiesAsync(TAuthorization authorization,
ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the scopes associated with an authorization.
@ -295,7 +293,7 @@ namespace OpenIddict.Abstractions
/// <param name="scopes">The scopes associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetScopesAsync([NotNull] TAuthorization authorization,
ValueTask SetScopesAsync(TAuthorization authorization,
ImmutableArray<string> scopes, CancellationToken cancellationToken);
/// <summary>
@ -305,8 +303,7 @@ namespace OpenIddict.Abstractions
/// <param name="status">The status associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetStatusAsync([NotNull] TAuthorization authorization,
[CanBeNull] string status, CancellationToken cancellationToken);
ValueTask SetStatusAsync(TAuthorization authorization, string? status, CancellationToken cancellationToken);
/// <summary>
/// Sets the subject associated with an authorization.
@ -315,8 +312,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetSubjectAsync([NotNull] TAuthorization authorization,
[CanBeNull] string subject, CancellationToken cancellationToken);
ValueTask SetSubjectAsync(TAuthorization authorization, string? subject, CancellationToken cancellationToken);
/// <summary>
/// Sets the type associated with an authorization.
@ -325,8 +321,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The type associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetTypeAsync([NotNull] TAuthorization authorization,
[CanBeNull] string type, CancellationToken cancellationToken);
ValueTask SetTypeAsync(TAuthorization authorization, string? type, CancellationToken cancellationToken);
/// <summary>
/// Updates an existing authorization.
@ -334,6 +329,6 @@ namespace OpenIddict.Abstractions
/// <param name="authorization">The authorization to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask UpdateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken);
}
}

61
src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs

@ -12,7 +12,6 @@ using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -42,7 +41,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken);
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Creates a new scope.
@ -50,7 +49,7 @@ namespace OpenIddict.Abstractions
/// <param name="scope">The scope to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Removes an existing scope.
@ -58,7 +57,7 @@ namespace OpenIddict.Abstractions
/// <param name="scope">The scope to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask DeleteAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a scope using its unique identifier.
@ -69,7 +68,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the identifier.
/// </returns>
ValueTask<TScope> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TScope?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a scope using its name.
@ -80,7 +79,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the specified name.
/// </returns>
ValueTask<TScope> FindByNameAsync([NotNull] string name, CancellationToken cancellationToken);
ValueTask<TScope?> FindByNameAsync(string name, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a list of scopes using their name.
@ -96,7 +95,7 @@ namespace OpenIddict.Abstractions
/// <param name="resource">The resource associated with the scopes.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The scopes associated with the specified resource.</returns>
IAsyncEnumerable<TScope> FindByResourceAsync([NotNull] string resource, CancellationToken cancellationToken);
IAsyncEnumerable<TScope> FindByResourceAsync(string resource, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns the first element.
@ -111,8 +110,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the description associated with a scope.
@ -123,7 +122,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the description associated with the specified scope.
/// </returns>
ValueTask<string> GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<string?> GetDescriptionAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the localized descriptions associated with a scope.
@ -134,7 +133,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the localized descriptions associated with the specified scope.
/// </returns>
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the display name associated with a scope.
@ -145,7 +144,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the display name associated with the scope.
/// </returns>
ValueTask<string> GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<string?> GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the localized display names associated with a scope.
@ -156,7 +155,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the localized display names associated with the scope.
/// </returns>
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the unique identifier associated with a scope.
@ -167,7 +166,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the scope.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<string?> GetIdAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the name associated with a scope.
@ -178,7 +177,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the name associated with the specified scope.
/// </returns>
ValueTask<string> GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<string?> GetNameAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the additional properties associated with a scope.
@ -189,7 +188,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the scope.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the resources associated with a scope.
@ -200,7 +199,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the resources associated with the scope.
/// </returns>
ValueTask<ImmutableArray<string>> GetResourcesAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<ImmutableArray<string>> GetResourcesAsync(TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Instantiates a new scope.
@ -219,7 +218,7 @@ namespace OpenIddict.Abstractions
/// <param name="offset">The number of results to skip.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TScope> ListAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken);
IAsyncEnumerable<TScope> ListAsync(int? count, int? offset, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -231,8 +230,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Sets the description associated with a scope.
@ -241,7 +240,7 @@ namespace OpenIddict.Abstractions
/// <param name="description">The description associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetDescriptionAsync([NotNull] TScope scope, [CanBeNull] string description, CancellationToken cancellationToken);
ValueTask SetDescriptionAsync(TScope scope, string? description, CancellationToken cancellationToken);
/// <summary>
/// Sets the localized descriptions associated with a scope.
@ -250,8 +249,8 @@ namespace OpenIddict.Abstractions
/// <param name="descriptions">The localized descriptions associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetDescriptionsAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<CultureInfo, string> descriptions, CancellationToken cancellationToken);
ValueTask SetDescriptionsAsync(TScope scope,
ImmutableDictionary<CultureInfo, string> descriptions, CancellationToken cancellationToken);
/// <summary>
/// Sets the display name associated with a scope.
@ -260,7 +259,7 @@ namespace OpenIddict.Abstractions
/// <param name="name">The display name associated with the scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetDisplayNameAsync([NotNull] TScope scope, [CanBeNull] string name, CancellationToken cancellationToken);
ValueTask SetDisplayNameAsync(TScope scope, string? name, CancellationToken cancellationToken);
/// <summary>
/// Sets the localized display names associated with a scope.
@ -269,8 +268,8 @@ namespace OpenIddict.Abstractions
/// <param name="names">The localized display names associated with the scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetDisplayNamesAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<CultureInfo, string> names, CancellationToken cancellationToken);
ValueTask SetDisplayNamesAsync(TScope scope,
ImmutableDictionary<CultureInfo, string> names, CancellationToken cancellationToken);
/// <summary>
/// Sets the name associated with a scope.
@ -279,7 +278,7 @@ namespace OpenIddict.Abstractions
/// <param name="name">The name associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetNameAsync([NotNull] TScope scope, [CanBeNull] string name, CancellationToken cancellationToken);
ValueTask SetNameAsync(TScope scope, string? name, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with a scope.
@ -288,8 +287,8 @@ namespace OpenIddict.Abstractions
/// <param name="properties">The additional properties associated with the scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
ValueTask SetPropertiesAsync(TScope scope,
ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the resources associated with a scope.
@ -298,7 +297,7 @@ namespace OpenIddict.Abstractions
/// <param name="resources">The resources associated with the scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetResourcesAsync([NotNull] TScope scope, ImmutableArray<string> resources, CancellationToken cancellationToken);
ValueTask SetResourcesAsync(TScope scope, ImmutableArray<string> resources, CancellationToken cancellationToken);
/// <summary>
/// Updates an existing scope.
@ -306,6 +305,6 @@ namespace OpenIddict.Abstractions
/// <param name="scope">The scope to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask UpdateAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken);
}
}

83
src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs

@ -11,7 +11,6 @@ using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace OpenIddict.Abstractions
{
@ -41,7 +40,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of tokens that match the specified query.
/// </returns>
ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken);
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Creates a new token.
@ -49,7 +48,7 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask CreateAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Removes a token.
@ -57,7 +56,7 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to delete.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask DeleteAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the tokens corresponding to the specified
@ -67,7 +66,7 @@ namespace OpenIddict.Abstractions
/// <param name="client">The client associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the subject/client.</returns>
IAsyncEnumerable<TToken> FindAsync([NotNull] string subject, [NotNull] string client, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindAsync(string subject, string client, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the tokens matching the specified parameters.
@ -78,8 +77,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the criteria.</returns>
IAsyncEnumerable<TToken> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, CancellationToken cancellationToken);
string subject, string client,
string status, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the tokens matching the specified parameters.
@ -91,8 +90,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the criteria.</returns>
IAsyncEnumerable<TToken> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, [NotNull] string type, CancellationToken cancellationToken);
string subject, string client,
string status, string type, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified application identifier.
@ -100,7 +99,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The application identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified application.</returns>
IAsyncEnumerable<TToken> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified authorization identifier.
@ -108,7 +107,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The authorization identifier associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified authorization.</returns>
IAsyncEnumerable<TToken> FindByAuthorizationIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a token using its unique identifier.
@ -119,7 +118,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token corresponding to the unique identifier.
/// </returns>
ValueTask<TToken> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TToken?> FindByIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified reference identifier.
@ -131,7 +130,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified reference identifier.
/// </returns>
ValueTask<TToken> FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
ValueTask<TToken?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of tokens corresponding to the specified subject.
@ -139,7 +138,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the tokens.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>The tokens corresponding to the specified subject.</returns>
IAsyncEnumerable<TToken> FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> FindBySubjectAsync(string subject, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the optional application identifier associated with a token.
@ -150,7 +149,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the application identifier associated with the token.
/// </returns>
ValueTask<string> GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetApplicationIdAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns the first element.
@ -165,8 +164,8 @@ namespace OpenIddict.Abstractions
/// whose result returns the first element returned when executing the query.
/// </returns>
ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the optional authorization identifier associated with a token.
@ -177,7 +176,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization identifier associated with the token.
/// </returns>
ValueTask<string> GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the creation date associated with a token.
@ -188,7 +187,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the creation date associated with the specified token.
/// </returns>
ValueTask<DateTimeOffset?> GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<DateTimeOffset?> GetCreationDateAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the expiration date associated with a token.
@ -199,7 +198,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the expiration date associated with the specified token.
/// </returns>
ValueTask<DateTimeOffset?> GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<DateTimeOffset?> GetExpirationDateAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the unique identifier associated with a token.
@ -210,7 +209,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the token.
/// </returns>
ValueTask<string> GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetIdAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the payload associated with a token.
@ -221,7 +220,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the payload associated with the specified token.
/// </returns>
ValueTask<string> GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetPayloadAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the additional properties associated with a token.
@ -232,7 +231,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the token.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the reference identifier associated with a token.
@ -245,7 +244,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the reference identifier associated with the specified token.
/// </returns>
ValueTask<string> GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetReferenceIdAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the status associated with a token.
@ -256,7 +255,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the status associated with the specified token.
/// </returns>
ValueTask<string> GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetStatusAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the subject associated with a token.
@ -267,7 +266,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the subject associated with the specified token.
/// </returns>
ValueTask<string> GetSubjectAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetSubjectAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the token type associated with a token.
@ -278,7 +277,7 @@ namespace OpenIddict.Abstractions
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token type associated with the specified token.
/// </returns>
ValueTask<string> GetTypeAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<string?> GetTypeAsync(TToken token, CancellationToken cancellationToken);
/// <summary>
/// Instantiates a new token.
@ -297,7 +296,7 @@ namespace OpenIddict.Abstractions
/// <param name="offset">The number of results to skip.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TToken> ListAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken);
IAsyncEnumerable<TToken> ListAsync(int? count, int? offset, CancellationToken cancellationToken);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -309,8 +308,8 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>All the elements returned when executing the specified query.</returns>
IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken);
Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
TState state, CancellationToken cancellationToken);
/// <summary>
/// Removes the tokens that are marked as expired or invalid.
@ -326,7 +325,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The unique identifier associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetApplicationIdAsync([NotNull] TToken token, [CanBeNull] string identifier, CancellationToken cancellationToken);
ValueTask SetApplicationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken);
/// <summary>
/// Sets the authorization identifier associated with a token.
@ -335,7 +334,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The unique identifier associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetAuthorizationIdAsync([NotNull] TToken token, [CanBeNull] string identifier, CancellationToken cancellationToken);
ValueTask SetAuthorizationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken);
/// <summary>
/// Sets the creation date associated with a token.
@ -344,7 +343,7 @@ namespace OpenIddict.Abstractions
/// <param name="date">The creation date.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetCreationDateAsync([NotNull] TToken token, [CanBeNull] DateTimeOffset? date, CancellationToken cancellationToken);
ValueTask SetCreationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken);
/// <summary>
/// Sets the expiration date associated with a token.
@ -353,7 +352,7 @@ namespace OpenIddict.Abstractions
/// <param name="date">The expiration date.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetExpirationDateAsync([NotNull] TToken token, [CanBeNull] DateTimeOffset? date, CancellationToken cancellationToken);
ValueTask SetExpirationDateAsync(TToken token, DateTimeOffset? date, CancellationToken cancellationToken);
/// <summary>
/// Sets the payload associated with a token.
@ -362,7 +361,7 @@ namespace OpenIddict.Abstractions
/// <param name="payload">The payload associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPayloadAsync([NotNull] TToken token, [CanBeNull] string payload, CancellationToken cancellationToken);
ValueTask SetPayloadAsync(TToken token, string? payload, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with a token.
@ -371,8 +370,8 @@ namespace OpenIddict.Abstractions
/// <param name="properties">The additional properties associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TToken token,
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
ValueTask SetPropertiesAsync(TToken token,
ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the reference identifier associated with a token.
@ -383,7 +382,7 @@ namespace OpenIddict.Abstractions
/// <param name="identifier">The reference identifier associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetReferenceIdAsync([NotNull] TToken token, [CanBeNull] string identifier, CancellationToken cancellationToken);
ValueTask SetReferenceIdAsync(TToken token, string? identifier, CancellationToken cancellationToken);
/// <summary>
/// Sets the status associated with a token.
@ -392,7 +391,7 @@ namespace OpenIddict.Abstractions
/// <param name="status">The status associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetStatusAsync([NotNull] TToken token, [CanBeNull] string status, CancellationToken cancellationToken);
ValueTask SetStatusAsync(TToken token, string? status, CancellationToken cancellationToken);
/// <summary>
/// Sets the subject associated with a token.
@ -401,7 +400,7 @@ namespace OpenIddict.Abstractions
/// <param name="subject">The subject associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetSubjectAsync([NotNull] TToken token, [CanBeNull] string subject, CancellationToken cancellationToken);
ValueTask SetSubjectAsync(TToken token, string? subject, CancellationToken cancellationToken);
/// <summary>
/// Sets the token type associated with a token.
@ -410,7 +409,7 @@ namespace OpenIddict.Abstractions
/// <param name="type">The token type associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetTypeAsync([NotNull] TToken token, [CanBeNull] string type, CancellationToken cancellationToken);
ValueTask SetTypeAsync(TToken token, string? type, CancellationToken cancellationToken);
/// <summary>
/// Updates an existing token.
@ -418,6 +417,6 @@ namespace OpenIddict.Abstractions
/// <param name="token">The token to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask UpdateAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken);
}
}

2
src/OpenIddict.Validation/OpenIddictValidationHandlers.Discovery.cs

@ -304,7 +304,7 @@ namespace OpenIddict.Validation
key.X5t = (string) keys[index][JsonWebKeyParameterNames.X5t];
key.X5tS256 = (string) keys[index][JsonWebKeyParameterNames.X5tS256];
if (keys[index].TryGetParameter(JsonWebKeyParameterNames.X5c, out var chain))
if (keys[index].TryGetNamedParameter(JsonWebKeyParameterNames.X5c, out var chain))
{
foreach (var certificate in chain.GetNamedParameters())
{

147
test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictParameterTests.cs

@ -351,7 +351,7 @@ namespace OpenIddict.Abstractions.Tests.Primitives
}
[Fact]
public void GetParameter_ReturnsNullForOutOfRangeArrayIndex()
public void GetUnnamedParameter_ReturnsNullForOutOfRangeArrayIndex()
{
// Arrange
var parameter = new OpenIddictParameter(new[]
@ -689,40 +689,169 @@ namespace OpenIddict.Abstractions.Tests.Primitives
[Theory]
[InlineData(null)]
[InlineData("")]
public void TryGetParameter_ThrowsAnExceptionForNullOrEmptyName(string name)
public void TryGetNamedParameter_ThrowsAnExceptionForNullOrEmptyName(string name)
{
// Arrange
var parameter = new OpenIddictParameter();
// Act
var exception = Assert.Throws<ArgumentException>(() => parameter.TryGetParameter(name, out var value));
var exception = Assert.Throws<ArgumentException>(() => parameter.TryGetNamedParameter(name, out _));
// Assert
Assert.Equal("name", exception.ParamName);
Assert.StartsWith(SR.GetResourceString(SR.ID1189), exception.Message);
Assert.StartsWith(SR.GetResourceString(SR.ID1191), exception.Message);
}
[Fact]
public void TryGetNamedParameter_ReturnsFalseForPrimitiveValues()
{
// Arrange
var parameter = new OpenIddictParameter(42);
// Act and assert
Assert.False(parameter.TryGetNamedParameter("parameter", out var value));
Assert.Equal(default, value);
}
[Fact]
public void TryGetNamedParameter_ReturnsFalseForArrays()
{
// Arrange
var parameter = new OpenIddictParameter(new[]
{
"Fabrikam",
"Contoso"
});
// Act and assert
Assert.False(parameter.TryGetNamedParameter("Fabrikam", out var value));
Assert.Equal(default, value);
}
[Fact]
public void TryGetParameter_ReturnsTrueAndExpectedParameter()
public void TryGetNamedParameter_ReturnsFalseForNonexistentItem()
{
// Arrange
var parameter = new OpenIddictParameter(new JsonElement());
// Act and assert
Assert.False(parameter.TryGetNamedParameter("parameter", out var value));
Assert.Equal(default, value);
}
[Fact]
public void TryGetNamedParameter_ReturnsFalseForJsonArrays()
{
// Arrange
var parameter = new OpenIddictParameter(
JsonSerializer.Deserialize<JsonElement>(@"[""Fabrikam"",""Contoso""]"));
// Act and assert
Assert.False(parameter.TryGetNamedParameter("Fabrikam", out var value));
Assert.Equal(default, value);
}
[Fact]
public void TryGetNamedParameter_ReturnsExpectedParameterForJsonObject()
{
// Arrange
var parameter = new OpenIddictParameter(
JsonSerializer.Deserialize<JsonElement>(@"{""parameter"":""value""}"));
// Act and assert
Assert.True(parameter.TryGetParameter("parameter", out var value));
Assert.True(parameter.TryGetNamedParameter("parameter", out var value));
Assert.Equal("value", (string) value);
}
[Fact]
public void TryGetParameter_ReturnsFalse()
public void TryGetUnnamedParameter_ThrowsAnExceptionForNegativeIndex()
{
// Arrange
var parameter = new OpenIddictParameter();
// Act
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => parameter.TryGetUnnamedParameter(-1, out _));
// Assert
Assert.Equal("index", exception.ParamName);
Assert.StartsWith(SR.GetResourceString(SR.ID1192), exception.Message);
}
[Fact]
public void TryGetUnnamedParameter_ReturnsFalseForPrimitiveValues()
{
// Arrange
var parameter = new OpenIddictParameter(42);
// Act and assert
Assert.False(parameter.TryGetUnnamedParameter(0, out var value));
Assert.Equal(default, value);
}
[Fact]
public void GetParameter_ReturnsFalseForOutOfRangeArrayIndex()
{
// Arrange
var parameter = new OpenIddictParameter(new[]
{
"Fabrikam",
"Contoso"
});
// Act and assert
Assert.False(parameter.TryGetUnnamedParameter(2, out var value));
Assert.Equal(default, value);
}
[Fact]
public void TryGetUnnamedParameter_ReturnsExpectedNodeForArray()
{
// Arrange
var parameter = new OpenIddictParameter(new[]
{
"Fabrikam",
"Contoso"
});
// Act and assert
Assert.True(parameter.TryGetUnnamedParameter(0, out var value));
Assert.Equal("Fabrikam", (string) value);
}
[Fact]
public void TryGetUnnamedParameter_ReturnsFalseForOutOfRangeJsonArrayIndex()
{
// Arrange
var parameter = new OpenIddictParameter(
JsonSerializer.Deserialize<JsonElement>(@"[""Fabrikam"",""Contoso""]"));
// Act and assert
Assert.False(parameter.TryGetUnnamedParameter(2, out var value));
Assert.Equal(default, value);
}
[Fact]
public void TryGetUnnamedParameter_ReturnsFalseForJsonObjects()
{
// Arrange
var parameter = new OpenIddictParameter(
JsonSerializer.Deserialize<JsonElement>(@"{""parameter"":""value""}"));
// Act and assert
Assert.False(parameter.TryGetUnnamedParameter(0, out var value));
Assert.Equal(default, value);
}
[Fact]
public void TryGetUnnamedParameter_ReturnsExpectedNodeForJsonArray()
{
// Arrange
var parameter = new OpenIddictParameter(
JsonSerializer.Deserialize<JsonElement>(@"[""Fabrikam"",""Contoso""]"));
// Act and assert
Assert.False(parameter.TryGetParameter("parameter", out var value));
Assert.Null(value.Value);
Assert.True(parameter.TryGetUnnamedParameter(0, out var value));
Assert.Equal("Fabrikam", (string) value);
}
[Fact]

Loading…
Cancel
Save