diff --git a/build/dependencies.props b/build/dependencies.props index d37b8f56..8d155c26 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -15,6 +15,7 @@ 4.7.63 4.0.1 1.0.0 + 4.0.0 15.0.0 4.1.0 4.1.0 diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs index 295acc5a..e9099c30 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs @@ -327,10 +327,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client identifier associated with the application. /// - public virtual Task GetClientIdAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetClientIdAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -346,10 +346,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client type of the application (by default, "public"). /// - public virtual async Task GetClientTypeAsync( + public virtual ValueTask GetClientTypeAsync( [NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) @@ -357,18 +357,23 @@ namespace OpenIddict.Core throw new ArgumentNullException(nameof(application)); } - var type = await Store.GetClientTypeAsync(application, cancellationToken); - - // Ensure the application type returned by the store is supported by the manager. - if (!string.Equals(type, OpenIddictConstants.ClientTypes.Confidential, StringComparison.OrdinalIgnoreCase) && - !string.Equals(type, OpenIddictConstants.ClientTypes.Hybrid, StringComparison.OrdinalIgnoreCase) && - !string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase)) + async Task ResolveClientTypeAsync() { - throw new InvalidOperationException("Only 'confidential', 'hybrid' or 'public' applications are " + - "supported by the default application manager."); + var type = await Store.GetClientTypeAsync(application, cancellationToken); + + // Ensure the application type returned by the store is supported by the manager. + if (!string.Equals(type, OpenIddictConstants.ClientTypes.Confidential, StringComparison.OrdinalIgnoreCase) && + !string.Equals(type, OpenIddictConstants.ClientTypes.Hybrid, StringComparison.OrdinalIgnoreCase) && + !string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidOperationException("Only 'confidential', 'hybrid' or 'public' applications are " + + "supported by the default application manager."); + } + + return type; } - return type; + return new ValueTask(ResolveClientTypeAsync()); } /// @@ -377,23 +382,28 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the consent type of the application (by default, "explicit"). /// - public virtual async Task GetConsentTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetConsentTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) { throw new ArgumentNullException(nameof(application)); } - var type = await Store.GetConsentTypeAsync(application, cancellationToken); - if (string.IsNullOrEmpty(type)) + async Task ResolveConsentTypeAsync() { - return OpenIddictConstants.ConsentTypes.Explicit; + var type = await Store.GetConsentTypeAsync(application, cancellationToken); + if (string.IsNullOrEmpty(type)) + { + return OpenIddictConstants.ConsentTypes.Explicit; + } + + return type; } - return type; + return new ValueTask(ResolveConsentTypeAsync()); } /// @@ -402,10 +412,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the application. /// - public virtual Task GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -421,10 +431,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the application. /// - public virtual Task GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -440,10 +450,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the permissions associated with the application. /// - public virtual Task> GetPermissionsAsync( + public virtual ValueTask> GetPermissionsAsync( [NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) @@ -460,10 +470,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the post_logout_redirect_uri associated with the application. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the post_logout_redirect_uri associated with the application. /// - public virtual Task> GetPostLogoutRedirectUrisAsync( + public virtual ValueTask> GetPostLogoutRedirectUrisAsync( [NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) @@ -480,10 +490,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the redirect_uri associated with the application. /// - public virtual Task> GetRedirectUrisAsync( + public virtual ValueTask> GetRedirectUrisAsync( [NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) diff --git a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs index c362a269..c944105c 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs @@ -386,10 +386,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the authorization. /// - public virtual Task GetApplicationIdAsync( + public virtual ValueTask GetApplicationIdAsync( [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) @@ -446,10 +446,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the authorization. /// - public virtual Task GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -465,10 +465,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the scopes associated with the specified authorization. /// - public virtual Task> GetScopesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask> GetScopesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -484,10 +484,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified authorization. /// - public virtual Task GetStatusAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetStatusAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -503,10 +503,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the subject associated with the specified authorization. /// - public virtual Task GetSubjectAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetSubjectAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -522,10 +522,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the type associated with the specified authorization. /// - public virtual Task GetTypeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetTypeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index b0eecfb4..ec4015d4 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -248,10 +248,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the description associated with the specified scope. /// - public virtual Task GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -267,10 +267,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the scope. /// - public virtual Task GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -286,10 +286,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the scope. /// - public virtual Task GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -305,10 +305,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the name associated with the specified scope. /// - public virtual Task GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -324,10 +324,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the resources associated with the scope. /// - public virtual Task> GetResourcesAsync( + public virtual ValueTask> GetResourcesAsync( [NotNull] TScope scope, CancellationToken cancellationToken = default) { if (scope == null) diff --git a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs index 6dc9cad0..2ea62973 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs @@ -279,10 +279,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the token. /// - public virtual Task GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -338,10 +338,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization identifier associated with the token. /// - public virtual Task GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -357,10 +357,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the creation date associated with the specified token. /// - public virtual Task GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -376,10 +376,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the expiration date associated with the specified token. /// - public virtual Task GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -395,10 +395,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the token. /// - public virtual Task GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -414,10 +414,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the payload associated with the specified token. /// - public virtual Task GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -435,10 +435,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the reference identifier associated with the specified token. /// - public virtual Task GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -454,10 +454,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified token. /// - public virtual Task GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -467,6 +467,44 @@ namespace OpenIddict.Core return Store.GetStatusAsync(token, cancellationToken); } + /// + /// Retrieves the subject associated with a token. + /// + /// The token. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation, + /// whose result returns the subject associated with the specified token. + /// + public virtual ValueTask GetSubjectAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + { + if (token == null) + { + throw new ArgumentNullException(nameof(token)); + } + + return Store.GetSubjectAsync(token, cancellationToken); + } + + /// + /// Retrieves the token type associated with a token. + /// + /// The token. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation, + /// whose result returns the token type associated with the specified token. + /// + public virtual ValueTask GetTokenTypeAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + { + if (token == null) + { + throw new ArgumentNullException(nameof(token)); + } + + return Store.GetTokenTypeAsync(token, cancellationToken); + } + /// /// Determines whether a given token has already been redemeed. /// diff --git a/src/OpenIddict.Core/OpenIddict.Core.csproj b/src/OpenIddict.Core/OpenIddict.Core.csproj index f8081a3d..316ea0d6 100644 --- a/src/OpenIddict.Core/OpenIddict.Core.csproj +++ b/src/OpenIddict.Core/OpenIddict.Core.csproj @@ -26,6 +26,7 @@ + diff --git a/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs index 11f11698..c9f023e7 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs @@ -128,10 +128,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client identifier associated with the application. /// - Task GetClientIdAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask GetClientIdAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the client secret associated with an application. @@ -141,10 +141,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client secret associated with the application. /// - Task GetClientSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask GetClientSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the client type associated with an application. @@ -152,10 +152,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client type of the application (by default, "public"). /// - Task GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the consent type associated with an application. @@ -163,10 +163,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the consent type of the application (by default, "explicit"). /// - Task GetConsentTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask GetConsentTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the display name associated with an application. @@ -174,10 +174,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the application. /// - Task GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the unique identifier associated with an application. @@ -185,10 +185,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the application. /// - Task GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the permissions associated with an application. @@ -196,10 +196,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the permissions associated with the application. /// - Task> GetPermissionsAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask> GetPermissionsAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the logout callback addresses associated with an application. @@ -207,10 +207,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the post_logout_redirect_uri associated with the application. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the post_logout_redirect_uri associated with the application. /// - Task> GetPostLogoutRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask> GetPostLogoutRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the additional properties associated with an application. @@ -218,10 +218,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the additional properties associated with the application. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the additional properties associated with the application. /// - Task GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the callback addresses associated with an application. @@ -229,20 +229,20 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the redirect_uri associated with the application. /// - Task> GetRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask> GetRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Instantiates a new application. /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose result - /// returns the instantiated application, that can be persisted in the database. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns the instantiated application, that can be persisted in the database. /// - Task InstantiateAsync(CancellationToken cancellationToken); + ValueTask InstantiateAsync(CancellationToken cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs index 38073448..95dd042d 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs @@ -135,10 +135,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the authorization. /// - Task GetApplicationIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask GetApplicationIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Executes the specified query and returns the first element. @@ -162,10 +162,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the authorization. /// - Task GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Retrieves the additional properties associated with an authorization. @@ -173,10 +173,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the additional properties associated with the authorization. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the additional properties associated with the authorization. /// - Task GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Retrieves the scopes associated with an authorization. @@ -184,10 +184,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the scopes associated with the specified authorization. /// - Task> GetScopesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask> GetScopesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Retrieves the status associated with an authorization. @@ -195,10 +195,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified authorization. /// - Task GetStatusAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask GetStatusAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Retrieves the subject associated with an authorization. @@ -206,10 +206,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the subject associated with the specified authorization. /// - Task GetSubjectAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask GetSubjectAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Retrieves the type associated with an authorization. @@ -217,20 +217,20 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the type associated with the specified authorization. /// - Task GetTypeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask GetTypeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Instantiates a new authorization. /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose result - /// returns the instantiated authorization, that can be persisted in the database. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns the instantiated authorization, that can be persisted in the database. /// - Task InstantiateAsync(CancellationToken cancellationToken); + ValueTask InstantiateAsync(CancellationToken cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs index f0f2ade9..996405db 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs @@ -117,10 +117,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the description associated with the specified scope. /// - Task GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken); + ValueTask GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken); /// /// Retrieves the display name associated with a scope. @@ -128,10 +128,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the scope. /// - Task GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken); + ValueTask GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken); /// /// Retrieves the unique identifier associated with a scope. @@ -139,10 +139,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the scope. /// - Task GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken); + ValueTask GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken); /// /// Retrieves the name associated with a scope. @@ -150,10 +150,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the name associated with the specified scope. /// - Task GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken); + ValueTask GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken); /// /// Retrieves the additional properties associated with a scope. @@ -161,10 +161,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose + /// A that can be used to monitor the asynchronous operation, whose /// result returns all the additional properties associated with the scope. /// - Task GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken); + ValueTask GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken); /// /// Retrieves the resources associated with a scope. @@ -172,20 +172,20 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the resources associated with the scope. /// - Task> GetResourcesAsync([NotNull] TScope scope, CancellationToken cancellationToken); + ValueTask> GetResourcesAsync([NotNull] TScope scope, CancellationToken cancellationToken); /// /// Instantiates a new scope. /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the instantiated scope, that can be persisted in the database. /// - Task InstantiateAsync(CancellationToken cancellationToken); + ValueTask InstantiateAsync(CancellationToken cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs index 57daeb73..59f4cef3 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs @@ -122,10 +122,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the token. /// - Task GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Executes the specified query and returns the first element. @@ -149,10 +149,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization identifier associated with the token. /// - Task GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the creation date associated with a token. @@ -160,10 +160,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the creation date associated with the specified token. /// - Task GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the expiration date associated with a token. @@ -171,10 +171,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the expiration date associated with the specified token. /// - Task GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the unique identifier associated with a token. @@ -182,10 +182,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the token. /// - Task GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the payload associated with a token. @@ -193,10 +193,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the payload associated with the specified token. /// - Task GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the additional properties associated with a token. @@ -204,10 +204,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the additional properties associated with the token. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the additional properties associated with the token. /// - Task GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the reference identifier associated with a token. @@ -217,10 +217,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the reference identifier associated with the specified token. /// - Task GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the status associated with a token. @@ -228,10 +228,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified token. /// - Task GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the subject associated with a token. @@ -239,10 +239,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the subject associated with the specified token. /// - Task GetSubjectAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetSubjectAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the token type associated with a token. @@ -250,20 +250,20 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the token type associated with the specified token. /// - Task GetTokenTypeAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask GetTokenTypeAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Instantiates a new token. /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the instantiated token, that can be persisted in the database. /// - Task InstantiateAsync(CancellationToken cancellationToken); + ValueTask InstantiateAsync(CancellationToken cancellationToken); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs index 9956092b..08142fd5 100644 --- a/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs @@ -255,17 +255,17 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client identifier associated with the application. /// - public virtual Task GetClientIdAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask GetClientIdAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } - return Task.FromResult(application.ClientId); + return new ValueTask(application.ClientId); } /// @@ -276,17 +276,17 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client secret associated with the application. /// - public virtual Task GetClientSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask GetClientSecretAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } - return Task.FromResult(application.ClientSecret); + return new ValueTask(application.ClientSecret); } /// @@ -295,17 +295,17 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the client type of the application (by default, "public"). /// - public virtual Task GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask GetClientTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } - return Task.FromResult(application.Type); + return new ValueTask(application.Type); } /// @@ -314,17 +314,17 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the consent type of the application (by default, "explicit"). /// - public virtual Task GetConsentTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask GetConsentTypeAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } - return Task.FromResult(application.ConsentType); + return new ValueTask(application.ConsentType); } /// @@ -333,17 +333,17 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the application. /// - public virtual Task GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask GetDisplayNameAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } - return Task.FromResult(application.DisplayName); + return new ValueTask(application.DisplayName); } /// @@ -352,17 +352,17 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the application. /// - public virtual Task GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { throw new ArgumentNullException(nameof(application)); } - return Task.FromResult(ConvertIdentifierToString(application.Id)); + return new ValueTask(ConvertIdentifierToString(application.Id)); } /// @@ -371,10 +371,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the permissions associated with the application. /// - public virtual Task> GetPermissionsAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPermissionsAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -383,7 +383,7 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(application.Permissions)) { - return Task.FromResult(ImmutableArray.Create()); + return new ValueTask>(ImmutableArray.Create()); } // Note: parsing the stringified permissions is an expensive operation. @@ -398,7 +398,7 @@ namespace OpenIddict.Core .ToImmutableArray()); } - return Task.FromResult(permissions.GetValueOrDefault()); + return new ValueTask>(permissions.GetValueOrDefault()); } /// @@ -407,10 +407,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the post_logout_redirect_uri associated with the application. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the post_logout_redirect_uri associated with the application. /// - public virtual Task> GetPostLogoutRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPostLogoutRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -419,7 +419,7 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(application.PostLogoutRedirectUris)) { - return Task.FromResult(ImmutableArray.Create()); + return new ValueTask>(ImmutableArray.Create()); } // Note: parsing the stringified addresses is an expensive operation. @@ -434,7 +434,7 @@ namespace OpenIddict.Core .ToImmutableArray()); } - return Task.FromResult(addresses.GetValueOrDefault()); + return new ValueTask>(addresses.GetValueOrDefault()); } /// @@ -443,10 +443,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the additional properties associated with the application. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the additional properties associated with the application. /// - public virtual Task GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -455,10 +455,10 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(application.Properties)) { - return Task.FromResult(new JObject()); + return new ValueTask(new JObject()); } - return Task.FromResult(JObject.Parse(application.Properties)); + return new ValueTask(JObject.Parse(application.Properties)); } /// @@ -467,10 +467,10 @@ namespace OpenIddict.Core /// The application. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the redirect_uri associated with the application. /// - public virtual Task> GetRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetRedirectUrisAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -479,7 +479,7 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(application.RedirectUris)) { - return Task.FromResult(ImmutableArray.Create()); + return new ValueTask>(ImmutableArray.Create()); } // Note: parsing the stringified addresses is an expensive operation. @@ -494,7 +494,7 @@ namespace OpenIddict.Core .ToImmutableArray()); } - return Task.FromResult(addresses.GetValueOrDefault()); + return new ValueTask>(addresses.GetValueOrDefault()); } /// @@ -502,10 +502,11 @@ namespace OpenIddict.Core /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose result - /// returns the instantiated application, that can be persisted in the database. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns the instantiated application, that can be persisted in the database. /// - public virtual Task InstantiateAsync(CancellationToken cancellationToken) => Task.FromResult(new TApplication()); + public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) + => new ValueTask(new TApplication()); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs index 2d0689cf..6eae3a68 100644 --- a/src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs @@ -278,10 +278,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the authorization. /// - public virtual async Task GetApplicationIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask GetApplicationIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { @@ -290,17 +290,22 @@ namespace OpenIddict.Core if (authorization.Application != null) { - return ConvertIdentifierToString(authorization.Application.Id); + return new ValueTask(ConvertIdentifierToString(authorization.Application.Id)); } - IQueryable Query(IQueryable authorizations, TKey key) - => from element in authorizations - where element.Id.Equals(key) && - element.Application != null - select element.Application.Id; + async Task RetrieveApplicationIdAsync() + { + IQueryable Query(IQueryable authorizations, TKey key) + => from element in authorizations + where element.Id.Equals(key) && + element.Application != null + select element.Application.Id; + + return ConvertIdentifierToString(await GetAsync( + (authorizations, key) => Query(authorizations, key), authorization.Id, cancellationToken)); + } - return ConvertIdentifierToString(await GetAsync( - (authorizations, key) => Query(authorizations, key), authorization.Id, cancellationToken)); + return new ValueTask(RetrieveApplicationIdAsync()); } /// @@ -325,17 +330,17 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the authorization. /// - public virtual Task GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { throw new ArgumentNullException(nameof(authorization)); } - return Task.FromResult(ConvertIdentifierToString(authorization.Id)); + return new ValueTask(ConvertIdentifierToString(authorization.Id)); } /// @@ -344,10 +349,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the additional properties associated with the authorization. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the additional properties associated with the authorization. /// - public virtual Task GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { @@ -356,10 +361,10 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(authorization.Properties)) { - return Task.FromResult(new JObject()); + return new ValueTask(new JObject()); } - return Task.FromResult(JObject.Parse(authorization.Properties)); + return new ValueTask(JObject.Parse(authorization.Properties)); } /// @@ -368,10 +373,10 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the scopes associated with the specified authorization. /// - public virtual Task> GetScopesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> GetScopesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { @@ -380,10 +385,10 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(authorization.Scopes)) { - return Task.FromResult(ImmutableArray.Create()); + return new ValueTask>(ImmutableArray.Create()); } - return Task.FromResult(JArray.Parse(authorization.Scopes).Select(element => (string) element).ToImmutableArray()); + return new ValueTask>(JArray.Parse(authorization.Scopes).Select(element => (string) element).ToImmutableArray()); } /// @@ -392,12 +397,17 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified authorization. /// - public virtual Task GetStatusAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask GetStatusAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { - return Task.FromResult(authorization.Status); + if (authorization == null) + { + throw new ArgumentNullException(nameof(authorization)); + } + + return new ValueTask(authorization.Status); } /// @@ -406,17 +416,17 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the subject associated with the specified authorization. /// - public virtual Task GetSubjectAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask GetSubjectAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { throw new ArgumentNullException(nameof(authorization)); } - return Task.FromResult(authorization.Subject); + return new ValueTask(authorization.Subject); } /// @@ -425,17 +435,17 @@ namespace OpenIddict.Core /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the type associated with the specified authorization. /// - public virtual Task GetTypeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask GetTypeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { throw new ArgumentNullException(nameof(authorization)); } - return Task.FromResult(authorization.Type); + return new ValueTask(authorization.Type); } /// @@ -443,10 +453,11 @@ namespace OpenIddict.Core /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose result - /// returns the instantiated authorization, that can be persisted in the database. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns the instantiated authorization, that can be persisted in the database. /// - public virtual Task InstantiateAsync(CancellationToken cancellationToken) => Task.FromResult(new TAuthorization()); + public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) + => new ValueTask(new TAuthorization()); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs index 290d3e78..4f7771c4 100644 --- a/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs @@ -184,17 +184,17 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the description associated with the specified scope. /// - public virtual Task GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } - return Task.FromResult(scope.Description); + return new ValueTask(scope.Description); } /// @@ -203,17 +203,17 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the scope. /// - public virtual Task GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } - return Task.FromResult(scope.DisplayName); + return new ValueTask(scope.DisplayName); } /// @@ -222,17 +222,17 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the scope. /// - public virtual Task GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } - return Task.FromResult(ConvertIdentifierToString(scope.Id)); + return new ValueTask(ConvertIdentifierToString(scope.Id)); } /// @@ -241,17 +241,17 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the name associated with the specified scope. /// - public virtual Task GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } - return Task.FromResult(scope.Name); + return new ValueTask(scope.Name); } /// @@ -260,10 +260,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the additional properties associated with the scope. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the additional properties associated with the scope. /// - public virtual Task GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { @@ -272,10 +272,10 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(scope.Properties)) { - return Task.FromResult(new JObject()); + return new ValueTask(new JObject()); } - return Task.FromResult(JObject.Parse(scope.Properties)); + return new ValueTask(JObject.Parse(scope.Properties)); } /// @@ -284,10 +284,10 @@ namespace OpenIddict.Core /// The scope. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns all the resources associated with the scope. /// - public virtual Task> GetResourcesAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetResourcesAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { @@ -296,7 +296,7 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(scope.Resources)) { - return Task.FromResult(ImmutableArray.Create()); + return new ValueTask>(ImmutableArray.Create()); } // Note: parsing the stringified resources is an expensive operation. @@ -311,7 +311,7 @@ namespace OpenIddict.Core .ToImmutableArray()); } - return Task.FromResult(resources.GetValueOrDefault()); + return new ValueTask>(resources.GetValueOrDefault()); } /// @@ -319,10 +319,11 @@ namespace OpenIddict.Core /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the instantiated scope, that can be persisted in the database. /// - public virtual Task InstantiateAsync(CancellationToken cancellationToken) => Task.FromResult(new TScope()); + public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) + => new ValueTask(new TScope()); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs index d969fdaa..510cb210 100644 --- a/src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs @@ -236,10 +236,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the token. /// - public virtual async Task GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -248,16 +248,21 @@ namespace OpenIddict.Core if (token.Application != null) { - return ConvertIdentifierToString(token.Application.Id); + return new ValueTask(ConvertIdentifierToString(token.Application.Id)); } - IQueryable Query(IQueryable tokens, TKey key) - => from element in tokens - where element.Id.Equals(key) && - element.Application != null - select element.Application.Id; + async Task RetrieveApplicationIdAsync() + { + IQueryable Query(IQueryable tokens, TKey key) + => from element in tokens + where element.Id.Equals(key) && + element.Application != null + select element.Application.Id; - return ConvertIdentifierToString(await GetAsync((tokens, key) => Query(tokens, key), token.Id, cancellationToken)); + return ConvertIdentifierToString(await GetAsync((tokens, key) => Query(tokens, key), token.Id, cancellationToken)); + } + + return new ValueTask(RetrieveApplicationIdAsync()); } /// @@ -266,10 +271,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization identifier associated with the token. /// - public virtual async Task GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -278,16 +283,21 @@ namespace OpenIddict.Core if (token.Authorization != null) { - return ConvertIdentifierToString(token.Authorization.Id); + return new ValueTask(ConvertIdentifierToString(token.Authorization.Id)); } - IQueryable Query(IQueryable tokens, TKey key) - => from element in tokens - where element.Id.Equals(key) && - element.Authorization != null - select element.Authorization.Id; + async Task RetrieveAuthorizationIdAsync() + { + IQueryable Query(IQueryable tokens, TKey key) + => from element in tokens + where element.Id.Equals(key) && + element.Authorization != null + select element.Authorization.Id; + + return ConvertIdentifierToString(await GetAsync((tokens, key) => Query(tokens, key), token.Id, cancellationToken)); + } - return ConvertIdentifierToString(await GetAsync((tokens, key) => Query(tokens, key), token.Id, cancellationToken)); + return new ValueTask(RetrieveAuthorizationIdAsync()); } /// @@ -296,17 +306,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the creation date associated with the specified token. /// - public virtual Task GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(token.CreationDate); + return new ValueTask(token.CreationDate); } /// @@ -315,17 +325,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the expiration date associated with the specified token. /// - public virtual Task GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(token.ExpirationDate); + return new ValueTask(token.ExpirationDate); } /// @@ -334,17 +344,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the token. /// - public virtual Task GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(ConvertIdentifierToString(token.Id)); + return new ValueTask(ConvertIdentifierToString(token.Id)); } /// @@ -353,17 +363,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the payload associated with the specified token. /// - public virtual Task GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(token.Payload); + return new ValueTask(token.Payload); } /// @@ -372,10 +382,10 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, whose - /// result returns all the additional properties associated with the token. + /// A that can be used to monitor the asynchronous operation, + /// whose result returns all the additional properties associated with the token. /// - public virtual Task GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -384,10 +394,10 @@ namespace OpenIddict.Core if (string.IsNullOrEmpty(token.Properties)) { - return Task.FromResult(new JObject()); + return new ValueTask(new JObject()); } - return Task.FromResult(JObject.Parse(token.Properties)); + return new ValueTask(JObject.Parse(token.Properties)); } /// @@ -398,17 +408,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the reference identifier associated with the specified token. /// - public virtual Task GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(token.ReferenceId); + return new ValueTask(token.ReferenceId); } /// @@ -417,17 +427,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified token. /// - public virtual Task GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(token.Status); + return new ValueTask(token.Status); } /// @@ -436,17 +446,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the subject associated with the specified token. /// - public virtual Task GetSubjectAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetSubjectAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(token.Subject); + return new ValueTask(token.Subject); } /// @@ -455,17 +465,17 @@ namespace OpenIddict.Core /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the token type associated with the specified token. /// - public virtual Task GetTokenTypeAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask GetTokenTypeAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - return Task.FromResult(token.Type); + return new ValueTask(token.Type); } /// @@ -473,10 +483,11 @@ namespace OpenIddict.Core /// /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the instantiated token, that can be persisted in the database. /// - public virtual Task InstantiateAsync(CancellationToken cancellationToken) => Task.FromResult(new TToken()); + public virtual ValueTask InstantiateAsync(CancellationToken cancellationToken) + => new ValueTask(new TToken()); /// /// Executes the specified query and returns all the corresponding elements. diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs index dc436919..00b4cef1 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs @@ -213,18 +213,22 @@ namespace OpenIddict.EntityFramework /// The authorization. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the authorization. /// - public override async Task GetApplicationIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public override ValueTask GetApplicationIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { throw new ArgumentNullException(nameof(authorization)); } - // If the application is not attached to the authorization, try to load it manually. - if (authorization.Application == null) + if (authorization.Application != null) + { + return new ValueTask(ConvertIdentifierToString(authorization.Application.Id)); + } + + async Task RetrieveApplicationIdAsync() { var reference = Context.Entry(authorization).Reference(entry => entry.Application); if (reference.EntityEntry.State == EntityState.Detached) @@ -233,14 +237,16 @@ namespace OpenIddict.EntityFramework } await reference.LoadAsync(cancellationToken); - } - if (authorization.Application == null) - { - return null; + if (authorization.Application == null) + { + return null; + } + + return ConvertIdentifierToString(authorization.Application.Id); } - return ConvertIdentifierToString(authorization.Application.Id); + return new ValueTask(RetrieveApplicationIdAsync()); } /// diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs index bc34ecc9..32cdd988 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs @@ -200,18 +200,22 @@ namespace OpenIddict.EntityFramework /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the token. /// - public override async Task GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) + public override ValueTask GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - // If the application is not attached to the token, try to load it manually. - if (token.Application == null) + if (token.Application != null) + { + return new ValueTask(ConvertIdentifierToString(token.Application.Id)); + } + + async Task RetrieveApplicationIdAsync() { var reference = Context.Entry(token).Reference(entry => entry.Application); if (reference.EntityEntry.State == EntityState.Detached) @@ -220,14 +224,16 @@ namespace OpenIddict.EntityFramework } await reference.LoadAsync(cancellationToken); - } - if (token.Application == null) - { - return null; + if (token.Application == null) + { + return null; + } + + return ConvertIdentifierToString(token.Application.Id); } - return ConvertIdentifierToString(token.Application.Id); + return new ValueTask(RetrieveApplicationIdAsync()); } /// @@ -262,18 +268,22 @@ namespace OpenIddict.EntityFramework /// The token. /// The that can be used to abort the operation. /// - /// A that can be used to monitor the asynchronous operation, + /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization identifier associated with the token. /// - public override async Task GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) + public override ValueTask GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { throw new ArgumentNullException(nameof(token)); } - // If the authorization is not attached to the token, try to load it manually. - if (token.Authorization == null) + if (token.Authorization != null) + { + return new ValueTask(ConvertIdentifierToString(token.Authorization.Id)); + } + + async Task RetrieveAuthorizationIdAsync() { var reference = Context.Entry(token).Reference(entry => entry.Authorization); if (reference.EntityEntry.State == EntityState.Detached) @@ -282,14 +292,16 @@ namespace OpenIddict.EntityFramework } await reference.LoadAsync(cancellationToken); - } - if (token.Authorization == null) - { - return null; + if (token.Authorization == null) + { + return null; + } + + return ConvertIdentifierToString(token.Authorization.Id); } - return ConvertIdentifierToString(token.Authorization.Id); + return new ValueTask(RetrieveAuthorizationIdAsync()); } /// diff --git a/test/OpenIddict.Tests/OpenIddictProviderTests.Authentication.cs b/test/OpenIddict.Tests/OpenIddictProviderTests.Authentication.cs index c7da6614..34b412ec 100644 --- a/test/OpenIddict.Tests/OpenIddictProviderTests.Authentication.cs +++ b/test/OpenIddict.Tests/OpenIddictProviderTests.Authentication.cs @@ -236,7 +236,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.HasPermissionAsync(application, OpenIddictConstants.Permissions.Endpoints.Authorization, It.IsAny())) @@ -297,7 +297,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.HasPermissionAsync(application, OpenIddictConstants.Permissions.Endpoints.Authorization, It.IsAny())) @@ -525,7 +525,7 @@ namespace OpenIddict.Tests .ReturnsAsync(application); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); }); var server = CreateAuthorizationServer(builder => @@ -821,7 +821,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(cache.Object); @@ -891,10 +891,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(CreateTokenManager(instance => @@ -905,7 +905,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); }); @@ -974,7 +974,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(cache.Object); diff --git a/test/OpenIddict.Tests/OpenIddictProviderTests.Exchange.cs b/test/OpenIddict.Tests/OpenIddictProviderTests.Exchange.cs index 6377260f..d46bc023 100644 --- a/test/OpenIddict.Tests/OpenIddictProviderTests.Exchange.cs +++ b/test/OpenIddict.Tests/OpenIddictProviderTests.Exchange.cs @@ -399,7 +399,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); }); var server = CreateAuthorizationServer(builder => @@ -449,7 +449,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); }); var server = CreateAuthorizationServer(builder => @@ -501,7 +501,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); }); var server = CreateAuthorizationServer(builder => @@ -553,7 +553,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Hybrid); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Hybrid)); }); var server = CreateAuthorizationServer(builder => @@ -605,7 +605,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(false); @@ -665,7 +665,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -757,7 +757,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Configure(options => options.AuthorizationCodeFormat = format.Object); @@ -817,7 +817,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Configure(options => options.RefreshTokenFormat = format.Object); @@ -882,7 +882,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -949,7 +949,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -999,7 +999,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -1023,7 +1023,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -1075,7 +1075,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103951EFBA23A56")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -1099,7 +1099,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -1169,7 +1169,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(CreateTokenManager(instance => @@ -1180,10 +1180,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetAuthorizationIdAsync(token, It.IsAny())) - .ReturnsAsync("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0"); + .Returns(new ValueTask("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -1260,7 +1260,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(CreateTokenManager(instance => @@ -1271,10 +1271,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetAuthorizationIdAsync(token, It.IsAny())) - .ReturnsAsync("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0"); + .Returns(new ValueTask("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -1335,16 +1335,16 @@ namespace OpenIddict.Tests .ReturnsAsync(tokens[0]); instance.Setup(mock => mock.GetIdAsync(tokens[0], It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetIdAsync(tokens[1], It.IsAny())) - .ReturnsAsync("481FCAC6-06BC-43EE-92DB-37A78AA09B59"); + .Returns(new ValueTask("481FCAC6-06BC-43EE-92DB-37A78AA09B595073CC313103")); instance.Setup(mock => mock.GetIdAsync(tokens[2], It.IsAny())) - .ReturnsAsync("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8"); + .Returns(new ValueTask("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8")); instance.Setup(mock => mock.GetAuthorizationIdAsync(tokens[0], It.IsAny())) - .ReturnsAsync("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0"); + .Returns(new ValueTask("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0")); instance.Setup(mock => mock.IsRedeemedAsync(tokens[0], It.IsAny())) .ReturnsAsync(true); @@ -1371,7 +1371,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(CreateAuthorizationManager(instance => @@ -1438,16 +1438,16 @@ namespace OpenIddict.Tests .ReturnsAsync(tokens[0]); instance.Setup(mock => mock.GetIdAsync(tokens[0], It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetIdAsync(tokens[1], It.IsAny())) - .ReturnsAsync("481FCAC6-06BC-43EE-92DB-37A78AA09B59"); + .Returns(new ValueTask("481FCAC6-06BC-43EE-92DB-37A78AA09B595073CC313103")); instance.Setup(mock => mock.GetIdAsync(tokens[2], It.IsAny())) - .ReturnsAsync("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8"); + .Returns(new ValueTask("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8")); instance.Setup(mock => mock.GetAuthorizationIdAsync(tokens[0], It.IsAny())) - .ReturnsAsync("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0"); + .Returns(new ValueTask("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0")); instance.Setup(mock => mock.IsRedeemedAsync(tokens[0], It.IsAny())) .ReturnsAsync(true); @@ -1474,7 +1474,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(CreateAuthorizationManager(instance => @@ -1536,7 +1536,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -1563,7 +1563,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -1616,7 +1616,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103951EFBA23A56")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -1643,7 +1643,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -1712,7 +1712,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103951EFBA23A56")); instance.Setup(mock => mock.IsValidAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -1752,7 +1752,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); diff --git a/test/OpenIddict.Tests/OpenIddictProviderTests.Introspection.cs b/test/OpenIddict.Tests/OpenIddictProviderTests.Introspection.cs index 90dd3671..bfa1a9ca 100644 --- a/test/OpenIddict.Tests/OpenIddictProviderTests.Introspection.cs +++ b/test/OpenIddict.Tests/OpenIddictProviderTests.Introspection.cs @@ -155,7 +155,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); }); var server = CreateAuthorizationServer(builder => @@ -199,7 +199,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(false); @@ -268,7 +268,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -326,7 +326,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -385,7 +385,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -436,7 +436,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -494,10 +494,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync("2YotnFZFEjr1zCsicMWpAA"); + .Returns(new ValueTask("2YotnFZFEjr1zCsicMWpAA")); instance.Setup(mock => mock.FindByIdAsync("3E228451-1555-46F7-A471-951EFBA23A56", It.IsAny())) .ReturnsAsync(token); @@ -520,7 +520,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); diff --git a/test/OpenIddict.Tests/OpenIddictProviderTests.Revocation.cs b/test/OpenIddict.Tests/OpenIddictProviderTests.Revocation.cs index 48c93acc..22f77925 100644 --- a/test/OpenIddict.Tests/OpenIddictProviderTests.Revocation.cs +++ b/test/OpenIddict.Tests/OpenIddictProviderTests.Revocation.cs @@ -158,7 +158,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); }); var server = CreateAuthorizationServer(builder => @@ -203,7 +203,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); }); var server = CreateAuthorizationServer(builder => @@ -248,7 +248,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Hybrid); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Hybrid)); }); var server = CreateAuthorizationServer(builder => @@ -293,7 +293,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(false); @@ -522,7 +522,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => diff --git a/test/OpenIddict.Tests/OpenIddictProviderTests.Serialization.cs b/test/OpenIddict.Tests/OpenIddictProviderTests.Serialization.cs index 5e47b499..d72b1b96 100644 --- a/test/OpenIddict.Tests/OpenIddictProviderTests.Serialization.cs +++ b/test/OpenIddict.Tests/OpenIddictProviderTests.Serialization.cs @@ -47,7 +47,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -125,7 +125,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -166,7 +166,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync(value: null); + .Returns(new ValueTask(result: null)); }); var server = CreateAuthorizationServer(builder => @@ -183,7 +183,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -225,10 +225,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync(value: null); + .Returns(new ValueTask(result: null)); }); var server = CreateAuthorizationServer(builder => @@ -245,7 +245,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -292,10 +292,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync("2YotnFZFEjr1zCsicMWpAA"); + .Returns(new ValueTask("2YotnFZFEjr1zCsicMWpAA")); }); var server = CreateAuthorizationServer(builder => @@ -312,7 +312,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -373,10 +373,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync("2YotnFZFEjr1zCsicMWpAA"); + .Returns(new ValueTask("2YotnFZFEjr1zCsicMWpAA")); instance.Setup(mock => mock.FindByIdAsync("3E228451-1555-46F7-A471-951EFBA23A56", It.IsAny())) .ReturnsAsync(token); @@ -385,10 +385,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetCreationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero))); instance.Setup(mock => mock.GetExpirationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero))); }); var server = CreateAuthorizationServer(builder => @@ -405,7 +405,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -471,7 +471,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -532,7 +532,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsValidAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -556,7 +556,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -598,7 +598,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync(value: null); + .Returns(new ValueTask(result: null)); }); var server = CreateAuthorizationServer(builder => @@ -619,7 +619,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -662,10 +662,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync(value: null); + .Returns(new ValueTask(result: null)); }); var server = CreateAuthorizationServer(builder => @@ -686,7 +686,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -734,10 +734,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync("2YotnFZFEjr1zCsicMWpAA"); + .Returns(new ValueTask("2YotnFZFEjr1zCsicMWpAA")); }); var server = CreateAuthorizationServer(builder => @@ -758,7 +758,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -819,10 +819,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync("2YotnFZFEjr1zCsicMWpAA"); + .Returns(new ValueTask("2YotnFZFEjr1zCsicMWpAA")); instance.Setup(mock => mock.FindByIdAsync("3E228451-1555-46F7-A471-951EFBA23A56", It.IsAny())) .ReturnsAsync(token); @@ -831,10 +831,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetCreationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero))); instance.Setup(mock => mock.GetExpirationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero))); }); var server = CreateAuthorizationServer(builder => @@ -855,7 +855,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -929,7 +929,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -982,7 +982,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -1038,16 +1038,16 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsValidAsync(token, It.IsAny())) .ReturnsAsync(true); instance.Setup(mock => mock.GetCreationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero))); instance.Setup(mock => mock.GetExpirationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero))); }); var server = CreateAuthorizationServer(builder => @@ -1068,7 +1068,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -1125,7 +1125,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Confidential); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Confidential)); instance.Setup(mock => mock.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny())) .ReturnsAsync(true); @@ -1182,7 +1182,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsValidAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -1223,7 +1223,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync(value: null); + .Returns(new ValueTask(result: null)); }); var server = CreateAuthorizationServer(builder => @@ -1262,10 +1262,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync(value: null); + .Returns(new ValueTask(result: null)); }); var server = CreateAuthorizationServer(builder => @@ -1309,10 +1309,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync("2YotnFZFEjr1zCsicMWpAA"); + .Returns(new ValueTask("2YotnFZFEjr1zCsicMWpAA")); }); var server = CreateAuthorizationServer(builder => @@ -1367,10 +1367,10 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.GetPayloadAsync(token, It.IsAny())) - .ReturnsAsync("2YotnFZFEjr1zCsicMWpAA"); + .Returns(new ValueTask("2YotnFZFEjr1zCsicMWpAA")); instance.Setup(mock => mock.FindByIdAsync("3E228451-1555-46F7-A471-951EFBA23A56", It.IsAny())) .ReturnsAsync(token); @@ -1379,10 +1379,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetCreationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero))); instance.Setup(mock => mock.GetExpirationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero))); }); var server = CreateAuthorizationServer(builder => @@ -1510,16 +1510,16 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsValidAsync(token, It.IsAny())) .ReturnsAsync(true); instance.Setup(mock => mock.GetCreationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 01, 00, 00, 00, TimeSpan.Zero))); instance.Setup(mock => mock.GetExpirationDateAsync(token, It.IsAny())) - .ReturnsAsync(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero)); + .Returns(new ValueTask(new DateTimeOffset(2017, 01, 10, 00, 00, 00, TimeSpan.Zero))); }); var server = CreateAuthorizationServer(builder => @@ -1599,7 +1599,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.ObfuscateReferenceIdAsync(It.IsAny(), It.IsAny())) .ReturnsAsync("B1F0D503-55A4-4B03-B05B-EF07713C18E1"); @@ -1658,7 +1658,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => @@ -1679,10 +1679,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(manager); @@ -1725,7 +1725,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => @@ -1791,7 +1791,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -1836,7 +1836,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => @@ -1860,10 +1860,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(manager); @@ -1915,7 +1915,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.ObfuscateReferenceIdAsync(It.IsAny(), It.IsAny())) .ReturnsAsync("B1F0D503-55A4-4B03-B05B-EF07713C18E1"); @@ -1942,10 +1942,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(manager); @@ -1998,7 +1998,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => @@ -2022,10 +2022,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(manager); @@ -2064,7 +2064,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => @@ -2088,10 +2088,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(CreateAuthorizationManager(instance => @@ -2154,7 +2154,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103951EFBA23A56")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -2247,7 +2247,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => @@ -2302,7 +2302,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.ObfuscateReferenceIdAsync(It.IsAny(), It.IsAny())) .ReturnsAsync("B1F0D503-55A4-4B03-B05B-EF07713C18E1"); @@ -2361,7 +2361,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => @@ -2382,10 +2382,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(manager); @@ -2426,7 +2426,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); }); var server = CreateAuthorizationServer(builder => diff --git a/test/OpenIddict.Tests/OpenIddictProviderTests.cs b/test/OpenIddict.Tests/OpenIddictProviderTests.cs index 2f11a261..7a659199 100644 --- a/test/OpenIddict.Tests/OpenIddictProviderTests.cs +++ b/test/OpenIddict.Tests/OpenIddictProviderTests.cs @@ -71,7 +71,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); }); @@ -157,7 +157,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -225,7 +225,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -252,7 +252,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -309,7 +309,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -427,7 +427,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsValidAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -451,7 +451,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -504,7 +504,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); instance.Setup(mock => mock.IsValidAsync(token, It.IsAny())) .ReturnsAsync(true); @@ -531,7 +531,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); builder.Services.AddSingleton(manager); @@ -590,7 +590,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -656,7 +656,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -788,16 +788,16 @@ namespace OpenIddict.Tests .ReturnsAsync(tokens[0]); instance.Setup(mock => mock.GetIdAsync(tokens[0], It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.GetIdAsync(tokens[1], It.IsAny())) - .ReturnsAsync("481FCAC6-06BC-43EE-92DB-37A78AA09B59"); + .Returns(new ValueTask("481FCAC6-06BC-43EE-92DB-37A78AA09B595073CC313103")); instance.Setup(mock => mock.GetIdAsync(tokens[2], It.IsAny())) - .ReturnsAsync("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8"); + .Returns(new ValueTask("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8")); instance.Setup(mock => mock.GetAuthorizationIdAsync(tokens[0], It.IsAny())) - .ReturnsAsync("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0"); + .Returns(new ValueTask("18D15F73-BE2B-6867-DC01-B3C1E8AFDED0")); instance.Setup(mock => mock.IsRedeemedAsync(tokens[0], It.IsAny())) .ReturnsAsync(false); @@ -869,13 +869,13 @@ namespace OpenIddict.Tests .ReturnsAsync(tokens[0]); instance.Setup(mock => mock.GetIdAsync(tokens[0], It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.GetIdAsync(tokens[1], It.IsAny())) - .ReturnsAsync("481FCAC6-06BC-43EE-92DB-37A78AA09B59"); + .Returns(new ValueTask("481FCAC6-06BC-43EE-92DB-37A78AA09B595073CC313103")); instance.Setup(mock => mock.GetIdAsync(tokens[2], It.IsAny())) - .ReturnsAsync("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8"); + .Returns(new ValueTask("3BEA7A94-5ADA-49AF-9F41-8AB6156E31A8")); instance.Setup(mock => mock.IsRedeemedAsync(tokens[0], It.IsAny())) .ReturnsAsync(false); @@ -941,7 +941,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -1076,7 +1076,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("60FFF7EA-F98E-437B-937E-5073CC313103"); + .Returns(new ValueTask("60FFF7EA-F98E-437B-937E-5073CC313103")); instance.Setup(mock => mock.IsRedeemedAsync(token, It.IsAny())) .ReturnsAsync(false); @@ -1151,10 +1151,10 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); instance.Setup(mock => mock.GetIdAsync(application, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(CreateTokenManager(instance => @@ -1163,7 +1163,7 @@ namespace OpenIddict.Tests .ReturnsAsync(token); instance.Setup(mock => mock.GetIdAsync(token, It.IsAny())) - .ReturnsAsync("3E228451-1555-46F7-A471-951EFBA23A56"); + .Returns(new ValueTask("3E228451-1555-46F7-A471-951EFBA23A56")); })); builder.Services.AddSingleton(manager); @@ -1215,7 +1215,7 @@ namespace OpenIddict.Tests .ReturnsAsync(true); instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny())) - .ReturnsAsync(OpenIddictConstants.ClientTypes.Public); + .Returns(new ValueTask(OpenIddictConstants.ClientTypes.Public)); })); });