From 7a6e1237349fc097565e8d9fb8fe997695895090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 26 Jul 2020 06:40:04 +0200 Subject: [PATCH] Add nullable annotations to OpenIddict.Core --- .../Caches/OpenIddictApplicationCache.cs | 96 +++------ .../Caches/OpenIddictAuthorizationCache.cs | 130 +++--------- .../Caches/OpenIddictScopeCache.cs | 94 +++------ .../Caches/OpenIddictTokenCache.cs | 145 ++++---------- .../Managers/OpenIddictApplicationManager.cs | 185 +++++++++++------- .../OpenIddictAuthorizationManager.cs | 154 +++++++++------ .../Managers/OpenIddictScopeManager.cs | 134 ++++++++----- .../Managers/OpenIddictTokenManager.cs | 183 ++++++++++------- src/OpenIddict.Core/OpenIddict.Core.csproj | 1 + src/OpenIddict.Core/OpenIddictCoreBuilder.cs | 45 ++--- .../OpenIddictCoreExtensions.cs | 7 +- src/OpenIddict.Core/OpenIddictCoreOptions.cs | 8 +- .../OpenIddictApplicationStoreResolver.cs | 3 +- .../OpenIddictAuthorizationStoreResolver.cs | 3 +- .../Resolvers/OpenIddictScopeStoreResolver.cs | 3 +- .../Resolvers/OpenIddictTokenStoreResolver.cs | 3 +- 16 files changed, 551 insertions(+), 643 deletions(-) diff --git a/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs b/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs index a192f65f..7e48f32d 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs @@ -11,7 +11,6 @@ using System.Collections.Immutable; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; @@ -31,8 +30,8 @@ namespace OpenIddict.Core private readonly IOpenIddictApplicationStore _store; public OpenIddictApplicationCache( - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictApplicationStoreResolver resolver) + IOptionsMonitor options, + IOpenIddictApplicationStoreResolver resolver) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -43,13 +42,8 @@ namespace OpenIddict.Core _store = resolver.Get(); } - /// - /// Add the specified application to the cache. - /// - /// The application to add to the cache. - /// The that can be used to abort the operation. - /// A that can be used to monitor the asynchronous operation. - public async ValueTask AddAsync([NotNull] TApplication application, CancellationToken cancellationToken) + /// + public async ValueTask AddAsync(TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -99,9 +93,7 @@ namespace OpenIddict.Core }, application, cancellationToken); } - /// - /// Disposes the resources held by this instance. - /// + /// public void Dispose() { foreach (var signal in _signals) @@ -112,16 +104,8 @@ namespace OpenIddict.Core _cache.Dispose(); } - /// - /// Retrieves an application using its client identifier. - /// - /// The client identifier associated with the application. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation, - /// whose result returns the client application corresponding to the identifier. - /// - public ValueTask FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + /// + public ValueTask FindByClientIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -134,14 +118,14 @@ namespace OpenIddict.Core Identifier = identifier }; - if (_cache.TryGetValue(parameters, out TApplication application)) + if (_cache.TryGetValue(parameters, out TApplication? application)) { - return new ValueTask(application); + return new ValueTask(application); } - return new ValueTask(ExecuteAsync()); + return new ValueTask(ExecuteAsync()); - async Task ExecuteAsync() + async Task ExecuteAsync() { if ((application = await _store.FindByClientIdAsync(identifier, cancellationToken)) != null) { @@ -154,16 +138,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves an application using its unique identifier. - /// - /// The unique identifier associated with the application. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation, - /// whose result returns the client application corresponding to the identifier. - /// - public ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + /// + public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -176,14 +152,14 @@ namespace OpenIddict.Core Identifier = identifier }; - if (_cache.TryGetValue(parameters, out TApplication application)) + if (_cache.TryGetValue(parameters, out TApplication? application)) { - return new ValueTask(application); + return new ValueTask(application); } - return new ValueTask(ExecuteAsync()); + return new ValueTask(ExecuteAsync()); - async Task ExecuteAsync() + async Task ExecuteAsync() { if ((application = await _store.FindByIdAsync(identifier, cancellationToken)) != null) { @@ -196,14 +172,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves all the applications associated with the specified post_logout_redirect_uri. - /// - /// The post_logout_redirect_uri associated with the applications. - /// The that can be used to abort the operation. - /// The client applications corresponding to the specified post_logout_redirect_uri. - public IAsyncEnumerable FindByPostLogoutRedirectUriAsync( - [NotNull] string address, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(address)) { @@ -243,14 +213,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves all the applications associated with the specified redirect_uri. - /// - /// The redirect_uri associated with the applications. - /// The that can be used to abort the operation. - /// The client applications corresponding to the specified redirect_uri. - public IAsyncEnumerable FindByRedirectUriAsync( - [NotNull] string address, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindByRedirectUriAsync(string address, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(address)) { @@ -290,13 +254,8 @@ namespace OpenIddict.Core } } - /// - /// Removes the specified application from the cache. - /// - /// The application to remove from the cache. - /// The that can be used to abort the operation. - /// A that can be used to monitor the asynchronous operation. - public async ValueTask RemoveAsync([NotNull] TApplication application, CancellationToken cancellationToken) + /// + public async ValueTask RemoveAsync(TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -309,7 +268,7 @@ namespace OpenIddict.Core throw new InvalidOperationException(SR.GetResourceString(SR.ID1195)); } - if (_signals.TryRemove(identifier, out CancellationTokenSource signal)) + if (_signals.TryRemove(identifier, out CancellationTokenSource? signal)) { signal.Cancel(); signal.Dispose(); @@ -323,8 +282,7 @@ namespace OpenIddict.Core /// The application to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] TApplication application, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key, TApplication? application, CancellationToken cancellationToken) { if (key == null) { @@ -356,7 +314,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] ImmutableArray applications, CancellationToken cancellationToken) + object key, ImmutableArray applications, CancellationToken cancellationToken) { if (key == null) { @@ -391,7 +349,7 @@ namespace OpenIddict.Core /// whose result returns an expiration signal for the specified application. /// protected virtual async ValueTask CreateExpirationSignalAsync( - [NotNull] TApplication application, CancellationToken cancellationToken) + TApplication application, CancellationToken cancellationToken) { if (application == null) { diff --git a/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs b/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs index bd72992f..0ba2d90d 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs @@ -11,7 +11,6 @@ using System.Collections.Immutable; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; @@ -31,8 +30,8 @@ namespace OpenIddict.Core private readonly IOpenIddictAuthorizationStore _store; public OpenIddictAuthorizationCache( - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictAuthorizationStoreResolver resolver) + IOptionsMonitor options, + IOpenIddictAuthorizationStoreResolver resolver) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -43,14 +42,7 @@ namespace OpenIddict.Core _store = resolver.Get(); } - /// - /// Add the specified authorization to the cache. - /// - /// The authorization to add to the cache. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation. - /// + /// public async ValueTask AddAsync(TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) @@ -107,9 +99,7 @@ namespace OpenIddict.Core }, authorization, cancellationToken); } - /// - /// Disposes the resources held by this instance. - /// + /// public void Dispose() { foreach (var signal in _signals) @@ -120,16 +110,8 @@ namespace OpenIddict.Core _cache.Dispose(); } - /// - /// Retrieves the authorizations corresponding to the specified - /// subject and associated with the application identifier. - /// - /// The subject associated with the authorization. - /// The client associated with the authorization. - /// The that can be used to abort the operation. - /// The authorizations corresponding to the subject/client. - public IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindAsync(string subject, string client, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -175,17 +157,10 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the authorizations matching the specified parameters. - /// - /// The subject associated with the authorization. - /// The client associated with the authorization. - /// The authorization status. - /// The that can be used to abort the operation. - /// The authorizations corresponding to the criteria. + /// public IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, CancellationToken cancellationToken) + string subject, string client, + string status, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -237,18 +212,10 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the authorizations matching the specified parameters. - /// - /// The subject associated with the authorization. - /// The client associated with the authorization. - /// The authorization status. - /// The authorization type. - /// The that can be used to abort the operation. - /// The authorizations corresponding to the criteria. + /// public IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, [NotNull] string type, CancellationToken cancellationToken) + string subject, string client, + string status, string type, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -306,19 +273,10 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the authorizations matching the specified parameters. - /// - /// The subject associated with the authorization. - /// The client associated with the authorization. - /// The authorization status. - /// The authorization type. - /// The minimal scopes associated with the authorization. - /// The that can be used to abort the operation. - /// The authorizations corresponding to the criteria. + /// public IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, [NotNull] string type, + string subject, string client, + string status, string type, ImmutableArray scopes, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) @@ -356,14 +314,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the list of authorizations corresponding to the specified application identifier. - /// - /// The application identifier associated with the authorizations. - /// The that can be used to abort the operation. - /// The authorizations corresponding to the specified application. - public IAsyncEnumerable FindByApplicationIdAsync( - [NotNull] string identifier, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -403,16 +355,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves an authorization using its unique identifier. - /// - /// The unique identifier associated with the authorization. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation, - /// whose result returns the authorization corresponding to the identifier. - /// - public ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + /// + public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -425,14 +369,14 @@ namespace OpenIddict.Core Identifier = identifier }; - if (_cache.TryGetValue(parameters, out TAuthorization authorization)) + if (_cache.TryGetValue(parameters, out TAuthorization? authorization)) { - return new ValueTask(authorization); + return new ValueTask(authorization); } - return new ValueTask(ExecuteAsync()); + return new ValueTask(ExecuteAsync()); - async Task ExecuteAsync() + async Task ExecuteAsync() { if ((authorization = await _store.FindByIdAsync(identifier, cancellationToken)) != null) { @@ -445,14 +389,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves all the authorizations corresponding to the specified subject. - /// - /// The subject associated with the authorization. - /// The that can be used to abort the operation. - /// The authorizations corresponding to the specified subject. - public IAsyncEnumerable FindBySubjectAsync( - [NotNull] string subject, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindBySubjectAsync(string subject, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -492,13 +430,8 @@ namespace OpenIddict.Core } } - /// - /// Removes the specified authorization from the cache. - /// - /// The authorization to remove from the cache. - /// The that can be used to abort the operation. - /// A that can be used to monitor the asynchronous operation. - public async ValueTask RemoveAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + /// + public async ValueTask RemoveAsync(TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { @@ -511,7 +444,7 @@ namespace OpenIddict.Core throw new InvalidOperationException(SR.GetResourceString(SR.ID1195)); } - if (_signals.TryRemove(identifier, out CancellationTokenSource signal)) + if (_signals.TryRemove(identifier, out CancellationTokenSource? signal)) { signal.Cancel(); signal.Dispose(); @@ -525,8 +458,7 @@ namespace OpenIddict.Core /// The authorization to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] TAuthorization authorization, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key, TAuthorization? authorization, CancellationToken cancellationToken) { if (key == null) { @@ -558,7 +490,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] ImmutableArray authorizations, CancellationToken cancellationToken) + object key, ImmutableArray authorizations, CancellationToken cancellationToken) { if (key == null) { @@ -593,7 +525,7 @@ namespace OpenIddict.Core /// whose result returns an expiration signal for the specified authorization. /// protected virtual async ValueTask CreateExpirationSignalAsync( - [NotNull] TAuthorization authorization, CancellationToken cancellationToken) + TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { diff --git a/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs b/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs index 55ef8c58..0d254488 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs @@ -12,7 +12,6 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; @@ -32,8 +31,8 @@ namespace OpenIddict.Core private readonly IOpenIddictScopeStore _store; public OpenIddictScopeCache( - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictScopeStoreResolver resolver) + IOptionsMonitor options, + IOpenIddictScopeStoreResolver resolver) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -44,13 +43,8 @@ namespace OpenIddict.Core _store = resolver.Get(); } - /// - /// Add the specified scope to the cache. - /// - /// The scope to add to the cache. - /// The that can be used to abort the operation. - /// A that can be used to monitor the asynchronous operation. - public async ValueTask AddAsync([NotNull] TScope scope, CancellationToken cancellationToken) + /// + public async ValueTask AddAsync(TScope scope, CancellationToken cancellationToken) { if (scope == null) { @@ -91,9 +85,7 @@ namespace OpenIddict.Core }, scope, cancellationToken); } - /// - /// Disposes the resources held by this instance. - /// + /// public void Dispose() { foreach (var signal in _signals) @@ -104,16 +96,8 @@ namespace OpenIddict.Core _cache.Dispose(); } - /// - /// Retrieves a scope using its unique identifier. - /// - /// The unique identifier associated with the scope. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation, - /// whose result returns the scope corresponding to the identifier. - /// - public ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + /// + public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -126,12 +110,14 @@ namespace OpenIddict.Core Identifier = identifier }; - if (_cache.TryGetValue(parameters, out TScope scope)) + if (_cache.TryGetValue(parameters, out TScope? scope)) { - return new ValueTask(scope); + return new ValueTask(scope); } - async Task ExecuteAsync() + return new ValueTask(ExecuteAsync()); + + async Task ExecuteAsync() { if ((scope = await _store.FindByIdAsync(identifier, cancellationToken)) != null) { @@ -142,20 +128,10 @@ namespace OpenIddict.Core return scope; } - - return new ValueTask(ExecuteAsync()); } - /// - /// Retrieves a scope using its name. - /// - /// The name associated with the scope. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation, - /// whose result returns the scope corresponding to the specified name. - /// - public ValueTask FindByNameAsync([NotNull] string name, CancellationToken cancellationToken) + /// + public ValueTask FindByNameAsync(string name, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(name)) { @@ -168,12 +144,12 @@ namespace OpenIddict.Core Name = name }; - if (_cache.TryGetValue(parameters, out TScope scope)) + if (_cache.TryGetValue(parameters, out TScope? scope)) { - return new ValueTask(scope); + return new ValueTask(scope); } - async Task ExecuteAsync() + async Task ExecuteAsync() { if ((scope = await _store.FindByNameAsync(name, cancellationToken)) != null) { @@ -185,15 +161,10 @@ namespace OpenIddict.Core return scope; } - return new ValueTask(ExecuteAsync()); + return new ValueTask(ExecuteAsync()); } - /// - /// Retrieves a list of scopes using their name. - /// - /// The names associated with the scopes. - /// The that can be used to abort the operation. - /// The scopes corresponding to the specified names. + /// public IAsyncEnumerable FindByNamesAsync(ImmutableArray names, CancellationToken cancellationToken) { if (names.Any(name => string.IsNullOrEmpty(name))) @@ -216,13 +187,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves all the scopes that contain the specified resource. - /// - /// The resource associated with the scopes. - /// The that can be used to abort the operation. - /// The scopes associated with the specified resource. - public IAsyncEnumerable FindByResourceAsync([NotNull] string resource, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindByResourceAsync(string resource, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(resource)) { @@ -262,13 +228,8 @@ namespace OpenIddict.Core } } - /// - /// Removes the specified scope from the cache. - /// - /// The scope to remove from the cache. - /// The that can be used to abort the operation. - /// A that can be used to monitor the asynchronous operation. - public async ValueTask RemoveAsync([NotNull] TScope scope, CancellationToken cancellationToken) + /// + public async ValueTask RemoveAsync(TScope scope, CancellationToken cancellationToken) { if (scope == null) { @@ -281,7 +242,7 @@ namespace OpenIddict.Core throw new InvalidOperationException(SR.GetResourceString(SR.ID1195)); } - if (_signals.TryRemove(identifier, out CancellationTokenSource signal)) + if (_signals.TryRemove(identifier, out CancellationTokenSource? signal)) { signal.Cancel(); signal.Dispose(); @@ -295,8 +256,7 @@ namespace OpenIddict.Core /// The scope to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] TScope scope, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key, TScope? scope, CancellationToken cancellationToken) { if (key == null) { @@ -328,7 +288,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] ImmutableArray scopes, CancellationToken cancellationToken) + object key, ImmutableArray scopes, CancellationToken cancellationToken) { if (key == null) { @@ -362,7 +322,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns an expiration signal for the specified scope. /// - protected virtual async ValueTask CreateExpirationSignalAsync([NotNull] TScope scope, CancellationToken cancellationToken) + protected virtual async ValueTask CreateExpirationSignalAsync(TScope scope, CancellationToken cancellationToken) { if (scope == null) { diff --git a/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs b/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs index dbb9df0c..bc31f9c1 100644 --- a/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs +++ b/src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs @@ -11,7 +11,6 @@ using System.Collections.Immutable; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; @@ -31,8 +30,8 @@ namespace OpenIddict.Core private readonly IOpenIddictTokenStore _store; public OpenIddictTokenCache( - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictTokenStoreResolver resolver) + IOptionsMonitor options, + IOpenIddictTokenStoreResolver resolver) { _cache = new MemoryCache(new MemoryCacheOptions { @@ -43,13 +42,8 @@ namespace OpenIddict.Core _store = resolver.Get(); } - /// - /// Add the specified token to the cache. - /// - /// The token to add to the cache. - /// The that can be used to abort the operation. - /// A that can be used to monitor the asynchronous operation. - public async ValueTask AddAsync([NotNull] TToken token, CancellationToken cancellationToken) + /// + public async ValueTask AddAsync(TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -123,9 +117,7 @@ namespace OpenIddict.Core }, token, cancellationToken); } - /// - /// Disposes the resources held by this instance. - /// + /// public void Dispose() { foreach (var signal in _signals) @@ -136,16 +128,8 @@ namespace OpenIddict.Core _cache.Dispose(); } - /// - /// Retrieves the tokens corresponding to the specified - /// subject and associated with the application identifier. - /// - /// The subject associated with the token. - /// The client associated with the token. - /// The that can be used to abort the operation. - /// The tokens corresponding to the subject/client. - public IAsyncEnumerable FindAsync([NotNull] string subject, - [NotNull] string client, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindAsync(string subject, string client, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -191,17 +175,10 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the tokens matching the specified parameters. - /// - /// The subject associated with the token. - /// The client associated with the token. - /// The token status. - /// The that can be used to abort the operation. - /// The tokens corresponding to the criteria. + /// public IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, CancellationToken cancellationToken) + string subject, string client, + string status, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -253,18 +230,10 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the tokens matching the specified parameters. - /// - /// The subject associated with the token. - /// The client associated with the token. - /// The token status. - /// The token type. - /// The that can be used to abort the operation. - /// The tokens corresponding to the criteria. + /// public IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, [NotNull] string type, CancellationToken cancellationToken) + string subject, string client, + string status, string type, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -322,14 +291,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the list of tokens corresponding to the specified application identifier. - /// - /// The application identifier associated with the tokens. - /// The that can be used to abort the operation. - /// The tokens corresponding to the specified application. - public IAsyncEnumerable FindByApplicationIdAsync( - [NotNull] string identifier, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -369,14 +332,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the list of tokens corresponding to the specified authorization identifier. - /// - /// The authorization identifier associated with the tokens. - /// The that can be used to abort the operation. - /// The tokens corresponding to the specified authorization. - public IAsyncEnumerable FindByAuthorizationIdAsync( - [NotNull] string identifier, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -416,16 +373,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves a token using its unique identifier. - /// - /// The unique identifier associated with 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 corresponding to the unique identifier. - /// - public ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + /// + public ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -438,14 +387,14 @@ namespace OpenIddict.Core Identifier = identifier }; - if (_cache.TryGetValue(parameters, out TToken token)) + if (_cache.TryGetValue(parameters, out TToken? token)) { - return new ValueTask(token); + return new ValueTask(token); } - return new ValueTask(ExecuteAsync()); + return new ValueTask(ExecuteAsync()); - async Task ExecuteAsync() + async Task ExecuteAsync() { if ((token = await _store.FindByIdAsync(identifier, cancellationToken)) != null) { @@ -458,17 +407,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the list of tokens corresponding to the specified reference identifier. - /// Note: the reference identifier may be hashed or encrypted for security reasons. - /// - /// The reference identifier associated with the tokens. - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation, - /// whose result returns the tokens corresponding to the specified reference identifier. - /// - public ValueTask FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + /// + public ValueTask FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -481,14 +421,14 @@ namespace OpenIddict.Core Identifier = identifier }; - if (_cache.TryGetValue(parameters, out TToken token)) + if (_cache.TryGetValue(parameters, out TToken? token)) { - return new ValueTask(token); + return new ValueTask(token); } - return new ValueTask(ExecuteAsync()); + return new ValueTask(ExecuteAsync()); - async Task ExecuteAsync() + async Task ExecuteAsync() { if ((token = await _store.FindByReferenceIdAsync(identifier, cancellationToken)) != null) { @@ -501,13 +441,8 @@ namespace OpenIddict.Core } } - /// - /// Retrieves the list of tokens corresponding to the specified subject. - /// - /// The subject associated with the tokens. - /// The that can be used to abort the operation. - /// The tokens corresponding to the specified subject. - public IAsyncEnumerable FindBySubjectAsync([NotNull] string subject, CancellationToken cancellationToken) + /// + public IAsyncEnumerable FindBySubjectAsync(string subject, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(subject)) { @@ -547,13 +482,8 @@ namespace OpenIddict.Core } } - /// - /// Removes the specified token from the cache. - /// - /// The token to remove from the cache. - /// The that can be used to abort the operation. - /// A that can be used to monitor the asynchronous operation. - public async ValueTask RemoveAsync([NotNull] TToken token, CancellationToken cancellationToken) + /// + public async ValueTask RemoveAsync(TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -566,7 +496,7 @@ namespace OpenIddict.Core throw new InvalidOperationException(SR.GetResourceString(SR.ID1204)); } - if (_signals.TryRemove(identifier, out CancellationTokenSource signal)) + if (_signals.TryRemove(identifier, out CancellationTokenSource? signal)) { signal.Cancel(); signal.Dispose(); @@ -580,8 +510,7 @@ namespace OpenIddict.Core /// The token to store in the cache entry, if applicable. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] TToken token, CancellationToken cancellationToken) + protected virtual async ValueTask CreateEntryAsync(object key, TToken? token, CancellationToken cancellationToken) { if (key == null) { @@ -613,7 +542,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. protected virtual async ValueTask CreateEntryAsync( - [NotNull] object key, [CanBeNull] ImmutableArray tokens, CancellationToken cancellationToken) + object key, ImmutableArray tokens, CancellationToken cancellationToken) { if (key == null) { @@ -647,7 +576,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns an expiration signal for the specified token. /// - protected virtual async ValueTask CreateExpirationSignalAsync([NotNull] TToken token, CancellationToken cancellationToken) + protected virtual async ValueTask CreateExpirationSignalAsync(TToken token, CancellationToken cancellationToken) { if (token == null) { diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs index 89ffce60..144853d0 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs @@ -16,7 +16,6 @@ using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -50,11 +49,11 @@ namespace OpenIddict.Core public class OpenIddictApplicationManager : IOpenIddictApplicationManager where TApplication : class { public OpenIddictApplicationManager( - [NotNull] IOpenIddictApplicationCache cache, - [NotNull] IStringLocalizer localizer, - [NotNull] ILogger> logger, - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictApplicationStoreResolver resolver) + IOpenIddictApplicationCache cache, + IStringLocalizer localizer, + ILogger> logger, + IOptionsMonitor options, + IOpenIddictApplicationStoreResolver resolver) { Cache = cache; Localizer = localizer; @@ -110,7 +109,7 @@ namespace OpenIddict.Core /// whose result returns the number of applications that match the specified query. /// public virtual ValueTask CountAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -128,7 +127,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask CreateAsync(TApplication application, CancellationToken cancellationToken = default) => CreateAsync(application, secret: null, cancellationToken); /// @@ -142,9 +141,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync( - [NotNull] TApplication application, - [CanBeNull] string secret, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default) { if (application == null) { @@ -219,7 +216,7 @@ namespace OpenIddict.Core /// whose result returns the unique identifier associated with the application. /// public virtual async ValueTask CreateAsync( - [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -256,7 +253,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -280,8 +277,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the client application corresponding to the identifier. /// - public virtual async ValueTask FindByClientIdAsync( - [NotNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask FindByClientIdAsync( + string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -318,7 +315,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the client application corresponding to the identifier. /// - public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -353,7 +350,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The client applications corresponding to the specified post_logout_redirect_uri. public virtual IAsyncEnumerable FindByPostLogoutRedirectUriAsync( - [NotNull] string address, CancellationToken cancellationToken = default) + string address, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(address)) { @@ -395,7 +392,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The client applications corresponding to the specified redirect_uri. public virtual IAsyncEnumerable FindByRedirectUriAsync( - [NotNull] string address, CancellationToken cancellationToken = default) + string address, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(address)) { @@ -441,7 +438,7 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -464,8 +461,8 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -484,8 +481,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the client identifier associated with the application. /// - public virtual ValueTask GetClientIdAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetClientIdAsync( + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -504,8 +501,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the client type of the application (by default, "public"). /// - public virtual ValueTask GetClientTypeAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetClientTypeAsync( + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -524,8 +521,8 @@ namespace OpenIddict.Core /// 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 ValueTask GetConsentTypeAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual async ValueTask GetConsentTypeAsync( + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -550,8 +547,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the application. /// - public virtual ValueTask GetDisplayNameAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetDisplayNameAsync( + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -571,7 +568,7 @@ namespace OpenIddict.Core /// whose result returns all the localized display names associated with the application. /// public virtual async ValueTask> GetDisplayNamesAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -596,7 +593,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the application. /// - public virtual ValueTask GetIdAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync(TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -617,8 +614,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the matching localized display name associated with the application. /// - public virtual ValueTask GetLocalizedDisplayNameAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual ValueTask GetLocalizedDisplayNameAsync( + TApplication application, CancellationToken cancellationToken = default) => GetLocalizedDisplayNameAsync(application, CultureInfo.CurrentUICulture, cancellationToken); /// @@ -633,8 +630,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the matching localized display name associated with the application. /// - public virtual async ValueTask GetLocalizedDisplayNameAsync( - [NotNull] TApplication application, [NotNull] CultureInfo culture, CancellationToken cancellationToken = default) + public virtual async ValueTask GetLocalizedDisplayNameAsync( + TApplication application, CultureInfo culture, CancellationToken cancellationToken = default) { if (application == null) { @@ -677,7 +674,7 @@ namespace OpenIddict.Core /// whose result returns all the permissions associated with the application. /// public virtual ValueTask> GetPermissionsAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -697,7 +694,7 @@ namespace OpenIddict.Core /// whose result returns all the post_logout_redirect_uri associated with the application. /// public virtual ValueTask> GetPostLogoutRedirectUrisAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -717,7 +714,7 @@ namespace OpenIddict.Core /// whose result returns all the redirect_uri associated with the application. /// public virtual ValueTask> GetRedirectUrisAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -737,7 +734,7 @@ namespace OpenIddict.Core /// whose result returns all the requirements associated with the application. /// public virtual ValueTask> GetRequirementsAsync( - [NotNull] TApplication application, CancellationToken cancellationToken = default) + TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -755,7 +752,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// true if the application has the specified client type, false otherwise. public virtual async ValueTask HasClientTypeAsync( - [NotNull] TApplication application, [NotNull] string type, CancellationToken cancellationToken = default) + TApplication application, string type, CancellationToken cancellationToken = default) { if (application == null) { @@ -778,7 +775,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// true if the application has the specified consent type, false otherwise. public virtual async ValueTask HasConsentTypeAsync( - [NotNull] TApplication application, [NotNull] string type, CancellationToken cancellationToken = default) + TApplication application, string type, CancellationToken cancellationToken = default) { if (application == null) { @@ -801,7 +798,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// true if the application has been granted the specified permission, false otherwise. public virtual async ValueTask HasPermissionAsync( - [NotNull] TApplication application, [NotNull] string permission, CancellationToken cancellationToken = default) + TApplication application, string permission, CancellationToken cancellationToken = default) { if (application == null) { @@ -824,7 +821,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// true if the requirement has been enforced for the specified application, false otherwise. public virtual async ValueTask HasRequirementAsync( - [NotNull] TApplication application, [NotNull] string requirement, CancellationToken cancellationToken = default) + TApplication application, string requirement, CancellationToken cancellationToken = default) { if (application == null) { @@ -847,7 +844,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default) + int? count = null, int? offset = null, CancellationToken cancellationToken = default) => Store.ListAsync(count, offset, cancellationToken); /// @@ -858,7 +855,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -878,8 +875,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -898,8 +895,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync([NotNull] TApplication application, - [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TApplication application, + OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) { if (application == null) { @@ -935,8 +932,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - [NotNull] OpenIddictApplicationDescriptor descriptor, - [NotNull] TApplication application, CancellationToken cancellationToken = default) + OpenIddictApplicationDescriptor descriptor, + TApplication application, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -974,7 +971,7 @@ namespace OpenIddict.Core } // Ensure the address is a valid absolute URL. - if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) + if (!Uri.TryCreate(address, UriKind.Absolute, out Uri? uri) || !uri.IsWellFormedOriginalString()) { throw new ArgumentException(SR.GetResourceString(SR.ID1213)); } @@ -992,7 +989,7 @@ namespace OpenIddict.Core } // Ensure the address is a valid absolute URL. - if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) + if (!Uri.TryCreate(address, UriKind.Absolute, out Uri? uri) || !uri.IsWellFormedOriginalString()) { throw new ArgumentException(SR.GetResourceString(SR.ID1213)); } @@ -1009,7 +1006,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TApplication application, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TApplication application, CancellationToken cancellationToken = default) { if (application == null) { @@ -1064,8 +1061,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TApplication application, - [CanBeNull] string secret, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TApplication application, string? secret, CancellationToken cancellationToken = default) { if (application == null) { @@ -1095,8 +1091,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TApplication application, - [NotNull] OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TApplication application, + OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken = default) { if (application == null) { @@ -1131,7 +1127,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The validation error encountered when validating the application. public virtual async IAsyncEnumerable ValidateAsync( - [NotNull] TApplication application, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TApplication application, [EnumeratorCancellation] CancellationToken cancellationToken = default) { if (application == null) { @@ -1205,7 +1201,7 @@ namespace OpenIddict.Core } // Ensure the address is a valid absolute URL. - if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri) || !uri.IsWellFormedOriginalString()) + if (!Uri.TryCreate(address, UriKind.Absolute, out Uri? uri) || !uri.IsWellFormedOriginalString()) { yield return new ValidationResult(Localizer[SR.ID3120]); @@ -1234,7 +1230,7 @@ namespace OpenIddict.Core /// whose result returns a boolean indicating whether the client secret was valid. /// public virtual async ValueTask ValidateClientSecretAsync( - [NotNull] TApplication application, [NotNull] string secret, CancellationToken cancellationToken = default) + TApplication application, string secret, CancellationToken cancellationToken = default) { if (application == null) { @@ -1281,7 +1277,7 @@ namespace OpenIddict.Core /// whose result returns a boolean indicating whether the redirect_uri was valid. /// public virtual async ValueTask ValidateRedirectUriAsync( - [NotNull] TApplication application, [NotNull] string address, CancellationToken cancellationToken = default) + TApplication application, string address, CancellationToken cancellationToken = default) { if (application == null) { @@ -1317,7 +1313,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - protected virtual ValueTask ObfuscateClientSecretAsync([NotNull] string secret, CancellationToken cancellationToken = default) + protected virtual ValueTask ObfuscateClientSecretAsync(string secret, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(secret)) { @@ -1397,7 +1393,7 @@ namespace OpenIddict.Core /// whose result returns a boolean indicating whether the specified value was valid. /// protected virtual ValueTask ValidateClientSecretAsync( - [NotNull] string secret, [NotNull] string comparand, CancellationToken cancellationToken = default) + string secret, string comparand, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(secret)) { @@ -1506,120 +1502,159 @@ namespace OpenIddict.Core #endif } + /// ValueTask IOpenIddictApplicationManager.CountAsync(CancellationToken cancellationToken) => CountAsync(cancellationToken); + /// ValueTask IOpenIddictApplicationManager.CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) => CountAsync(query, cancellationToken); + /// async ValueTask IOpenIddictApplicationManager.CreateAsync(OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken) => await CreateAsync(descriptor, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.CreateAsync(object application, CancellationToken cancellationToken) => CreateAsync((TApplication) application, cancellationToken); - ValueTask IOpenIddictApplicationManager.CreateAsync(object application, string secret, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.CreateAsync(object application, string? secret, CancellationToken cancellationToken) => CreateAsync((TApplication) application, secret, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.DeleteAsync(object application, CancellationToken cancellationToken) => DeleteAsync((TApplication) application, cancellationToken); - async ValueTask IOpenIddictApplicationManager.FindByClientIdAsync(string identifier, CancellationToken cancellationToken) + /// + async ValueTask IOpenIddictApplicationManager.FindByClientIdAsync(string identifier, CancellationToken cancellationToken) => await FindByClientIdAsync(identifier, cancellationToken); - async ValueTask IOpenIddictApplicationManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) + /// + async ValueTask IOpenIddictApplicationManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) => await FindByIdAsync(identifier, cancellationToken); + /// IAsyncEnumerable IOpenIddictApplicationManager.FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken) => FindByPostLogoutRedirectUriAsync(address, cancellationToken); + /// IAsyncEnumerable IOpenIddictApplicationManager.FindByRedirectUriAsync(string address, CancellationToken cancellationToken) => FindByRedirectUriAsync(address, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.GetAsync(Func, IQueryable> query, CancellationToken cancellationToken) => GetAsync(query, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.GetAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => GetAsync(query, state, cancellationToken); - ValueTask IOpenIddictApplicationManager.GetClientIdAsync(object application, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.GetClientIdAsync(object application, CancellationToken cancellationToken) => GetClientIdAsync((TApplication) application, cancellationToken); - ValueTask IOpenIddictApplicationManager.GetClientTypeAsync(object application, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.GetClientTypeAsync(object application, CancellationToken cancellationToken) => GetClientTypeAsync((TApplication) application, cancellationToken); - ValueTask IOpenIddictApplicationManager.GetConsentTypeAsync(object application, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.GetConsentTypeAsync(object application, CancellationToken cancellationToken) => GetConsentTypeAsync((TApplication) application, cancellationToken); - ValueTask IOpenIddictApplicationManager.GetDisplayNameAsync(object application, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.GetDisplayNameAsync(object application, CancellationToken cancellationToken) => GetDisplayNameAsync((TApplication) application, cancellationToken); + /// ValueTask> IOpenIddictApplicationManager.GetDisplayNamesAsync(object application, CancellationToken cancellationToken) => GetDisplayNamesAsync((TApplication) application, cancellationToken); - ValueTask IOpenIddictApplicationManager.GetIdAsync(object application, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.GetIdAsync(object application, CancellationToken cancellationToken) => GetIdAsync((TApplication) application, cancellationToken); - ValueTask IOpenIddictApplicationManager.GetLocalizedDisplayNameAsync(object application, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.GetLocalizedDisplayNameAsync(object application, CancellationToken cancellationToken) => GetLocalizedDisplayNameAsync((TApplication) application, cancellationToken); - ValueTask IOpenIddictApplicationManager.GetLocalizedDisplayNameAsync(object application, CultureInfo culture, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.GetLocalizedDisplayNameAsync(object application, CultureInfo culture, CancellationToken cancellationToken) => GetLocalizedDisplayNameAsync((TApplication) application, culture, cancellationToken); + /// ValueTask> IOpenIddictApplicationManager.GetPermissionsAsync(object application, CancellationToken cancellationToken) => GetPermissionsAsync((TApplication) application, cancellationToken); + /// ValueTask> IOpenIddictApplicationManager.GetPostLogoutRedirectUrisAsync(object application, CancellationToken cancellationToken) => GetPostLogoutRedirectUrisAsync((TApplication) application, cancellationToken); + /// ValueTask> IOpenIddictApplicationManager.GetRedirectUrisAsync(object application, CancellationToken cancellationToken) => GetRedirectUrisAsync((TApplication) application, cancellationToken); + /// ValueTask> IOpenIddictApplicationManager.GetRequirementsAsync(object application, CancellationToken cancellationToken) => GetRequirementsAsync((TApplication) application, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.HasClientTypeAsync(object application, string type, CancellationToken cancellationToken) => HasClientTypeAsync((TApplication) application, type, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.HasConsentTypeAsync(object application, string type, CancellationToken cancellationToken) => HasConsentTypeAsync((TApplication) application, type, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.HasPermissionAsync(object application, string permission, CancellationToken cancellationToken) => HasPermissionAsync((TApplication) application, permission, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.HasRequirementAsync(object application, string requirement, CancellationToken cancellationToken) => HasRequirementAsync((TApplication) application, requirement, cancellationToken); + /// IAsyncEnumerable IOpenIddictApplicationManager.ListAsync(int? count, int? offset, CancellationToken cancellationToken) => ListAsync(count, offset, cancellationToken); + /// IAsyncEnumerable IOpenIddictApplicationManager.ListAsync(Func, IQueryable> query, CancellationToken cancellationToken) => ListAsync(query, cancellationToken); + /// IAsyncEnumerable IOpenIddictApplicationManager.ListAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => ListAsync(query, state, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.PopulateAsync(OpenIddictApplicationDescriptor descriptor, object application, CancellationToken cancellationToken) => PopulateAsync(descriptor, (TApplication) application, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.PopulateAsync(object application, OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken) => PopulateAsync((TApplication) application, descriptor, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.UpdateAsync(object application, CancellationToken cancellationToken) => UpdateAsync((TApplication) application, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.UpdateAsync(object application, OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken) => UpdateAsync((TApplication) application, descriptor, cancellationToken); - ValueTask IOpenIddictApplicationManager.UpdateAsync(object application, string secret, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictApplicationManager.UpdateAsync(object application, string? secret, CancellationToken cancellationToken) => UpdateAsync((TApplication) application, secret, cancellationToken); + /// IAsyncEnumerable IOpenIddictApplicationManager.ValidateAsync(object application, CancellationToken cancellationToken) => ValidateAsync((TApplication) application, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.ValidateClientSecretAsync(object application, string secret, CancellationToken cancellationToken) => ValidateClientSecretAsync((TApplication) application, secret, cancellationToken); + /// ValueTask IOpenIddictApplicationManager.ValidateRedirectUriAsync(object application, string address, CancellationToken cancellationToken) => ValidateRedirectUriAsync((TApplication) application, address, cancellationToken); } diff --git a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs index 69ddd316..5d8d75ae 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs @@ -14,7 +14,6 @@ using System.Security.Claims; using System.Text; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -37,11 +36,11 @@ namespace OpenIddict.Core public class OpenIddictAuthorizationManager : IOpenIddictAuthorizationManager where TAuthorization : class { public OpenIddictAuthorizationManager( - [NotNull] IOpenIddictAuthorizationCache cache, - [NotNull] IStringLocalizer localizer, - [NotNull] ILogger> logger, - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictAuthorizationStoreResolver resolver) + IOpenIddictAuthorizationCache cache, + IStringLocalizer localizer, + ILogger> logger, + IOptionsMonitor options, + IOpenIddictAuthorizationStoreResolver resolver) { Cache = cache; Localizer = localizer; @@ -97,7 +96,7 @@ namespace OpenIddict.Core /// whose result returns the number of authorizations that match the specified query. /// public virtual ValueTask CountAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -115,7 +114,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -173,7 +172,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, whose result returns the authorization. /// public virtual async ValueTask CreateAsync( - [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -205,8 +204,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, whose result returns the authorization. /// public virtual ValueTask CreateAsync( - [NotNull] ClaimsPrincipal principal, [NotNull] string subject, [NotNull] string client, - [NotNull] string type, ImmutableArray scopes, CancellationToken cancellationToken = default) + ClaimsPrincipal principal, string subject, string client, + string type, ImmutableArray scopes, CancellationToken cancellationToken = default) { if (principal == null) { @@ -250,7 +249,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -274,7 +273,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The authorizations corresponding to the subject/client. public virtual IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, CancellationToken cancellationToken = default) + string subject, string client, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -326,8 +325,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The authorizations corresponding to the criteria. public virtual IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, CancellationToken cancellationToken = default) + string subject, string client, + string status, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -381,8 +380,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The authorizations corresponding to the criteria. public virtual IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, [NotNull] string type, CancellationToken cancellationToken = default) + string subject, string client, + string status, string type, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -442,8 +441,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The authorizations corresponding to the criteria. public virtual IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, [NotNull] string type, + string subject, string client, + string status, string type, ImmutableArray scopes, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) @@ -507,7 +506,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The authorizations corresponding to the specified application. public virtual IAsyncEnumerable FindByApplicationIdAsync( - [NotNull] string identifier, CancellationToken cancellationToken = default) + string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -550,7 +549,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization corresponding to the identifier. /// - public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -585,7 +584,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The authorizations corresponding to the specified subject. public virtual IAsyncEnumerable FindBySubjectAsync( - [NotNull] string subject, CancellationToken cancellationToken = default) + string subject, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -628,8 +627,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the authorization. /// - public virtual ValueTask GetApplicationIdAsync( - [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetApplicationIdAsync( + TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -650,7 +649,7 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -673,8 +672,8 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -693,7 +692,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the authorization. /// - public virtual ValueTask GetIdAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync(TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -713,7 +712,7 @@ namespace OpenIddict.Core /// whose result returns the scopes associated with the specified authorization. /// public virtual ValueTask> GetScopesAsync( - [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -732,8 +731,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified authorization. /// - public virtual ValueTask GetStatusAsync( - [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetStatusAsync( + TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -752,8 +751,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the subject associated with the specified authorization. /// - public virtual ValueTask GetSubjectAsync( - [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetSubjectAsync( + TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -772,8 +771,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the type associated with the specified authorization. /// - public virtual ValueTask GetTypeAsync( - [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual ValueTask GetTypeAsync( + TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -790,7 +789,7 @@ namespace OpenIddict.Core /// The scopes. /// The that can be used to abort the operation. /// true if the scopes are included in the authorization, false otherwise. - public virtual async ValueTask HasScopesAsync([NotNull] TAuthorization authorization, + public virtual async ValueTask HasScopesAsync(TAuthorization authorization, ImmutableArray scopes, CancellationToken cancellationToken = default) { if (authorization == null) @@ -809,8 +808,8 @@ namespace OpenIddict.Core /// The expected status. /// The that can be used to abort the operation. /// true if the authorization has the specified status, false otherwise. - public virtual async ValueTask HasStatusAsync([NotNull] TAuthorization authorization, - [NotNull] string status, CancellationToken cancellationToken = default) + public virtual async ValueTask HasStatusAsync(TAuthorization authorization, + string status, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -833,7 +832,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// true if the authorization has the specified type, false otherwise. public virtual async ValueTask HasTypeAsync( - [NotNull] TAuthorization authorization, [NotNull] string type, CancellationToken cancellationToken = default) + TAuthorization authorization, string type, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -856,7 +855,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default) + int? count = null, int? offset = null, CancellationToken cancellationToken = default) => Store.ListAsync(count, offset, cancellationToken); /// @@ -867,7 +866,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -887,8 +886,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -907,8 +906,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync([NotNull] TAuthorization authorization, - [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TAuthorization authorization, + OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -937,8 +936,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - [NotNull] OpenIddictAuthorizationDescriptor descriptor, - [NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + OpenIddictAuthorizationDescriptor descriptor, + TAuthorization authorization, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -978,7 +977,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask SetApplicationIdAsync( - [NotNull] TAuthorization authorization, [CanBeNull] string identifier, CancellationToken cancellationToken = default) + TAuthorization authorization, string? identifier, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -995,7 +994,7 @@ namespace OpenIddict.Core /// The authorization to revoke. /// The that can be used to abort the operation. /// true if the authorization was successfully revoked, false otherwise. - public virtual async ValueTask TryRevokeAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRevokeAsync(TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -1042,7 +1041,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TAuthorization authorization, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -1095,8 +1094,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TAuthorization authorization, - [NotNull] OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TAuthorization authorization, + OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default) { if (authorization == null) { @@ -1119,7 +1118,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The validation error encountered when validating the authorization. public virtual async IAsyncEnumerable ValidateAsync( - [NotNull] TAuthorization authorization, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TAuthorization authorization, [EnumeratorCancellation] CancellationToken cancellationToken = default) { if (authorization == null) { @@ -1162,108 +1161,143 @@ namespace OpenIddict.Core } } + /// ValueTask IOpenIddictAuthorizationManager.CountAsync(CancellationToken cancellationToken) => CountAsync(cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) => CountAsync(query, cancellationToken); + /// async ValueTask IOpenIddictAuthorizationManager.CreateAsync(ClaimsPrincipal principal, string subject, string client, string type, ImmutableArray scopes, CancellationToken cancellationToken) => await CreateAsync(principal, subject, client, type, scopes, cancellationToken); + /// async ValueTask IOpenIddictAuthorizationManager.CreateAsync(OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken) => await CreateAsync(descriptor, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.CreateAsync(object authorization, CancellationToken cancellationToken) => CreateAsync((TAuthorization) authorization, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.DeleteAsync(object authorization, CancellationToken cancellationToken) => DeleteAsync((TAuthorization) authorization, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.FindAsync(string subject, string client, CancellationToken cancellationToken) => FindAsync(subject, client, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.FindAsync(string subject, string client, string status, CancellationToken cancellationToken) => FindAsync(subject, client, status, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.FindAsync(string subject, string client, string status, string type, CancellationToken cancellationToken) => FindAsync(subject, client, status, type, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.FindAsync(string subject, string client, string status, string type, ImmutableArray scopes, CancellationToken cancellationToken) => FindAsync(subject, client, status, type, scopes, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken) => FindByApplicationIdAsync(identifier, cancellationToken); - async ValueTask IOpenIddictAuthorizationManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) + /// + async ValueTask IOpenIddictAuthorizationManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) => await FindByIdAsync(identifier, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.FindBySubjectAsync(string subject, CancellationToken cancellationToken) => FindBySubjectAsync(subject, cancellationToken); - ValueTask IOpenIddictAuthorizationManager.GetApplicationIdAsync(object authorization, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictAuthorizationManager.GetApplicationIdAsync(object authorization, CancellationToken cancellationToken) => GetApplicationIdAsync((TAuthorization) authorization, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.GetAsync(Func, IQueryable> query, CancellationToken cancellationToken) => GetAsync(query, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.GetAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => GetAsync(query, state, cancellationToken); - ValueTask IOpenIddictAuthorizationManager.GetIdAsync(object authorization, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictAuthorizationManager.GetIdAsync(object authorization, CancellationToken cancellationToken) => GetIdAsync((TAuthorization) authorization, cancellationToken); + /// ValueTask> IOpenIddictAuthorizationManager.GetScopesAsync(object authorization, CancellationToken cancellationToken) => GetScopesAsync((TAuthorization) authorization, cancellationToken); - ValueTask IOpenIddictAuthorizationManager.GetStatusAsync(object authorization, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictAuthorizationManager.GetStatusAsync(object authorization, CancellationToken cancellationToken) => GetStatusAsync((TAuthorization) authorization, cancellationToken); - ValueTask IOpenIddictAuthorizationManager.GetSubjectAsync(object authorization, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictAuthorizationManager.GetSubjectAsync(object authorization, CancellationToken cancellationToken) => GetSubjectAsync((TAuthorization) authorization, cancellationToken); - ValueTask IOpenIddictAuthorizationManager.GetTypeAsync(object authorization, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictAuthorizationManager.GetTypeAsync(object authorization, CancellationToken cancellationToken) => GetTypeAsync((TAuthorization) authorization, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.HasScopesAsync(object authorization, ImmutableArray scopes, CancellationToken cancellationToken) => HasScopesAsync((TAuthorization) authorization, scopes, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.HasStatusAsync(object authorization, string status, CancellationToken cancellationToken) => HasStatusAsync((TAuthorization) authorization, status, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.HasTypeAsync(object authorization, string type, CancellationToken cancellationToken) => HasTypeAsync((TAuthorization) authorization, type, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.ListAsync(int? count, int? offset, CancellationToken cancellationToken) => ListAsync(count, offset, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.ListAsync(Func, IQueryable> query, CancellationToken cancellationToken) => ListAsync(query, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.ListAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => ListAsync(query, state, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.PopulateAsync(OpenIddictAuthorizationDescriptor descriptor, object authorization, CancellationToken cancellationToken) => PopulateAsync(descriptor, (TAuthorization) authorization, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.PopulateAsync(object authorization, OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken) => PopulateAsync((TAuthorization) authorization, descriptor, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.PruneAsync(CancellationToken cancellationToken) => PruneAsync(cancellationToken); - ValueTask IOpenIddictAuthorizationManager.SetApplicationIdAsync(object authorization, string identifier, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictAuthorizationManager.SetApplicationIdAsync(object authorization, string? identifier, CancellationToken cancellationToken) => SetApplicationIdAsync((TAuthorization) authorization, identifier, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.TryRevokeAsync(object authorization, CancellationToken cancellationToken) => TryRevokeAsync((TAuthorization) authorization, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.UpdateAsync(object authorization, CancellationToken cancellationToken) => UpdateAsync((TAuthorization) authorization, cancellationToken); + /// ValueTask IOpenIddictAuthorizationManager.UpdateAsync(object authorization, OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken) => UpdateAsync((TAuthorization) authorization, descriptor, cancellationToken); + /// IAsyncEnumerable IOpenIddictAuthorizationManager.ValidateAsync(object authorization, CancellationToken cancellationToken) => ValidateAsync((TAuthorization) authorization, cancellationToken); } diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index b6c0b458..2d66c5b6 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -14,7 +14,6 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -36,11 +35,11 @@ namespace OpenIddict.Core public class OpenIddictScopeManager : IOpenIddictScopeManager where TScope : class { public OpenIddictScopeManager( - [NotNull] IOpenIddictScopeCache cache, - [NotNull] IStringLocalizer localizer, - [NotNull] ILogger> logger, - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictScopeStoreResolver resolver) + IOpenIddictScopeCache cache, + IStringLocalizer localizer, + ILogger> logger, + IOptionsMonitor options, + IOpenIddictScopeStoreResolver resolver) { Cache = cache; Localizer = localizer; @@ -96,7 +95,7 @@ namespace OpenIddict.Core /// whose result returns the number of scopes that match the specified query. /// public virtual ValueTask CountAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -114,7 +113,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -166,7 +165,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, whose result returns the scope. /// public virtual async ValueTask CreateAsync( - [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -193,7 +192,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -217,7 +216,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the scope corresponding to the identifier. /// - public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -254,7 +253,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the scope corresponding to the specified name. /// - public virtual async ValueTask FindByNameAsync([NotNull] string name, CancellationToken cancellationToken = default) + public virtual async ValueTask FindByNameAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) { @@ -331,7 +330,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The scopes associated with the specified resource. public virtual IAsyncEnumerable FindByResourceAsync( - [NotNull] string resource, CancellationToken cancellationToken = default) + string resource, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(resource)) { @@ -377,7 +376,7 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -400,8 +399,8 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -420,7 +419,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the description associated with the specified scope. /// - public virtual ValueTask GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetDescriptionAsync(TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -440,7 +439,7 @@ namespace OpenIddict.Core /// whose result returns all the localized descriptions associated with the scope. /// public virtual async ValueTask> GetDescriptionsAsync( - [NotNull] TScope scope, CancellationToken cancellationToken = default) + TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -465,7 +464,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the display name associated with the scope. /// - public virtual ValueTask GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetDisplayNameAsync(TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -485,7 +484,7 @@ namespace OpenIddict.Core /// whose result returns all the localized display names associated with the scope. /// public virtual async ValueTask> GetDisplayNamesAsync( - [NotNull] TScope scope, CancellationToken cancellationToken = default) + TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -510,7 +509,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the scope. /// - public virtual ValueTask GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync(TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -531,7 +530,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the matching display name associated with the scope. /// - public virtual ValueTask GetLocalizedDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetLocalizedDisplayNameAsync(TScope scope, CancellationToken cancellationToken = default) => GetLocalizedDisplayNameAsync(scope, CultureInfo.CurrentUICulture, cancellationToken); /// @@ -546,8 +545,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the matching display name associated with the scope. /// - public virtual async ValueTask GetLocalizedDisplayNameAsync( - [NotNull] TScope scope, [NotNull] CultureInfo culture, CancellationToken cancellationToken = default) + public virtual async ValueTask GetLocalizedDisplayNameAsync( + TScope scope, CultureInfo culture, CancellationToken cancellationToken = default) { if (scope == null) { @@ -591,7 +590,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the matching localized description associated with the scope. /// - public virtual ValueTask GetLocalizedDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetLocalizedDescriptionAsync(TScope scope, CancellationToken cancellationToken = default) => GetLocalizedDescriptionAsync(scope, CultureInfo.CurrentUICulture, cancellationToken); /// @@ -606,8 +605,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the matching localized description associated with the scope. /// - public virtual async ValueTask GetLocalizedDescriptionAsync( - [NotNull] TScope scope, [NotNull] CultureInfo culture, CancellationToken cancellationToken = default) + public virtual async ValueTask GetLocalizedDescriptionAsync( + TScope scope, CultureInfo culture, CancellationToken cancellationToken = default) { if (scope == null) { @@ -649,7 +648,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the name associated with the specified scope. /// - public virtual ValueTask GetNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual ValueTask GetNameAsync(TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -669,7 +668,7 @@ namespace OpenIddict.Core /// whose result returns all the resources associated with the scope. /// public virtual ValueTask> GetResourcesAsync( - [NotNull] TScope scope, CancellationToken cancellationToken = default) + TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -687,7 +686,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default) + int? count = null, int? offset = null, CancellationToken cancellationToken = default) => Store.ListAsync(count, offset, cancellationToken); /// @@ -698,7 +697,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -718,8 +717,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -760,8 +759,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync([NotNull] TScope scope, - [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TScope scope, + OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) { if (scope == null) { @@ -791,8 +790,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - [NotNull] OpenIddictScopeDescriptor descriptor, - [NotNull] TScope scope, CancellationToken cancellationToken = default) + OpenIddictScopeDescriptor descriptor, + TScope scope, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -831,7 +830,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cancellationToken = default) { if (scope == null) { @@ -884,8 +883,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TScope scope, - [NotNull] OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TScope scope, + OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken = default) { if (scope == null) { @@ -908,7 +907,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The validation error encountered when validating the scope. public virtual async IAsyncEnumerable ValidateAsync( - [NotNull] TScope scope, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TScope scope, [EnumeratorCancellation] CancellationToken cancellationToken = default) { if (scope == null) { @@ -923,7 +922,7 @@ namespace OpenIddict.Core yield return new ValidationResult(Localizer[SR.ID3044]); } - else if (name.Contains(Separators.Space[0])) + else if (name!.Contains(Separators.Space[0])) { yield return new ValidationResult(Localizer[SR.ID3045]); } @@ -944,96 +943,127 @@ namespace OpenIddict.Core } } + /// ValueTask IOpenIddictScopeManager.CountAsync(CancellationToken cancellationToken) => CountAsync(cancellationToken); + /// ValueTask IOpenIddictScopeManager.CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) => CountAsync(query, cancellationToken); + /// async ValueTask IOpenIddictScopeManager.CreateAsync(OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken) => await CreateAsync(descriptor, cancellationToken); + /// ValueTask IOpenIddictScopeManager.CreateAsync(object scope, CancellationToken cancellationToken) => CreateAsync((TScope) scope, cancellationToken); + /// ValueTask IOpenIddictScopeManager.DeleteAsync(object scope, CancellationToken cancellationToken) => DeleteAsync((TScope) scope, cancellationToken); - async ValueTask IOpenIddictScopeManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) + /// + async ValueTask IOpenIddictScopeManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) => await FindByIdAsync(identifier, cancellationToken); - async ValueTask IOpenIddictScopeManager.FindByNameAsync(string name, CancellationToken cancellationToken) + /// + async ValueTask IOpenIddictScopeManager.FindByNameAsync(string name, CancellationToken cancellationToken) => await FindByNameAsync(name, cancellationToken); + /// IAsyncEnumerable IOpenIddictScopeManager.FindByNamesAsync(ImmutableArray names, CancellationToken cancellationToken) => FindByNamesAsync(names, cancellationToken); + /// IAsyncEnumerable IOpenIddictScopeManager.FindByResourceAsync(string resource, CancellationToken cancellationToken) => FindByResourceAsync(resource, cancellationToken); + /// ValueTask IOpenIddictScopeManager.GetAsync(Func, IQueryable> query, CancellationToken cancellationToken) => GetAsync(query, cancellationToken); + /// ValueTask IOpenIddictScopeManager.GetAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => GetAsync(query, state, cancellationToken); - ValueTask IOpenIddictScopeManager.GetDescriptionAsync(object scope, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetDescriptionAsync(object scope, CancellationToken cancellationToken) => GetDescriptionAsync((TScope) scope, cancellationToken); + /// ValueTask> IOpenIddictScopeManager.GetDescriptionsAsync(object scope, CancellationToken cancellationToken) => GetDescriptionsAsync((TScope) scope, cancellationToken); - ValueTask IOpenIddictScopeManager.GetDisplayNameAsync(object scope, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetDisplayNameAsync(object scope, CancellationToken cancellationToken) => GetDisplayNameAsync((TScope) scope, cancellationToken); + /// ValueTask> IOpenIddictScopeManager.GetDisplayNamesAsync(object scope, CancellationToken cancellationToken) => GetDisplayNamesAsync((TScope) scope, cancellationToken); - ValueTask IOpenIddictScopeManager.GetIdAsync(object scope, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetIdAsync(object scope, CancellationToken cancellationToken) => GetIdAsync((TScope) scope, cancellationToken); - ValueTask IOpenIddictScopeManager.GetLocalizedDescriptionAsync(object scope, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetLocalizedDescriptionAsync(object scope, CancellationToken cancellationToken) => GetLocalizedDescriptionAsync((TScope) scope, cancellationToken); - ValueTask IOpenIddictScopeManager.GetLocalizedDescriptionAsync(object scope, CultureInfo culture, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetLocalizedDescriptionAsync(object scope, CultureInfo culture, CancellationToken cancellationToken) => GetLocalizedDescriptionAsync((TScope) scope, culture, cancellationToken); - ValueTask IOpenIddictScopeManager.GetLocalizedDisplayNameAsync(object scope, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetLocalizedDisplayNameAsync(object scope, CancellationToken cancellationToken) => GetLocalizedDisplayNameAsync((TScope) scope, cancellationToken); - ValueTask IOpenIddictScopeManager.GetLocalizedDisplayNameAsync(object scope, CultureInfo culture, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetLocalizedDisplayNameAsync(object scope, CultureInfo culture, CancellationToken cancellationToken) => GetLocalizedDisplayNameAsync((TScope) scope, culture, cancellationToken); - ValueTask IOpenIddictScopeManager.GetNameAsync(object scope, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictScopeManager.GetNameAsync(object scope, CancellationToken cancellationToken) => GetNameAsync((TScope) scope, cancellationToken); + /// ValueTask> IOpenIddictScopeManager.GetResourcesAsync(object scope, CancellationToken cancellationToken) => GetResourcesAsync((TScope) scope, cancellationToken); + /// IAsyncEnumerable IOpenIddictScopeManager.ListAsync(int? count, int? offset, CancellationToken cancellationToken) => ListAsync(count, offset, cancellationToken); + /// IAsyncEnumerable IOpenIddictScopeManager.ListAsync(Func, IQueryable> query, CancellationToken cancellationToken) => ListAsync(query, cancellationToken); + /// IAsyncEnumerable IOpenIddictScopeManager.ListAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => ListAsync(query, state, cancellationToken); + /// IAsyncEnumerable IOpenIddictScopeManager.ListResourcesAsync(ImmutableArray scopes, CancellationToken cancellationToken) => ListResourcesAsync(scopes, cancellationToken); + /// ValueTask IOpenIddictScopeManager.PopulateAsync(OpenIddictScopeDescriptor descriptor, object scope, CancellationToken cancellationToken) => PopulateAsync(descriptor, (TScope) scope, cancellationToken); + /// ValueTask IOpenIddictScopeManager.PopulateAsync(object scope, OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken) => PopulateAsync((TScope) scope, descriptor, cancellationToken); + /// ValueTask IOpenIddictScopeManager.UpdateAsync(object scope, CancellationToken cancellationToken) => UpdateAsync((TScope) scope, cancellationToken); + /// ValueTask IOpenIddictScopeManager.UpdateAsync(object scope, OpenIddictScopeDescriptor descriptor, CancellationToken cancellationToken) => UpdateAsync((TScope) scope, descriptor, cancellationToken); + /// IAsyncEnumerable IOpenIddictScopeManager.ValidateAsync(object scope, CancellationToken cancellationToken) => ValidateAsync((TScope) scope, cancellationToken); } diff --git a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs index c66957e7..665d7797 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs @@ -14,7 +14,6 @@ using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; -using JetBrains.Annotations; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -37,11 +36,11 @@ namespace OpenIddict.Core public class OpenIddictTokenManager : IOpenIddictTokenManager where TToken : class { public OpenIddictTokenManager( - [NotNull] IOpenIddictTokenCache cache, - [NotNull] IStringLocalizer localizer, - [NotNull] ILogger> logger, - [NotNull] IOptionsMonitor options, - [NotNull] IOpenIddictTokenStoreResolver resolver) + IOpenIddictTokenCache cache, + IStringLocalizer localizer, + ILogger> logger, + IOptionsMonitor options, + IOpenIddictTokenStoreResolver resolver) { Cache = cache; Localizer = localizer; @@ -97,7 +96,7 @@ namespace OpenIddict.Core /// whose result returns the number of tokens that match the specified query. /// public virtual ValueTask CountAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -115,7 +114,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask CreateAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -181,7 +180,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, whose result returns the token. /// public virtual async ValueTask CreateAsync( - [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) + OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -208,7 +207,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask DeleteAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -231,8 +230,8 @@ namespace OpenIddict.Core /// The client associated with the token. /// The that can be used to abort the operation. /// The tokens corresponding to the subject/client. - public virtual IAsyncEnumerable FindAsync([NotNull] string subject, - [NotNull] string client, CancellationToken cancellationToken = default) + public virtual IAsyncEnumerable FindAsync(string subject, + string client, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -280,8 +279,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The tokens corresponding to the criteria. public virtual IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, CancellationToken cancellationToken = default) + string subject, string client, + string status, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -335,8 +334,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// Tokens corresponding to the criteria. public virtual IAsyncEnumerable FindAsync( - [NotNull] string subject, [NotNull] string client, - [NotNull] string status, [NotNull] string type, CancellationToken cancellationToken = default) + string subject, string client, + string status, string type, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -392,7 +391,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The tokens corresponding to the specified application. public virtual IAsyncEnumerable FindByApplicationIdAsync( - [NotNull] string identifier, CancellationToken cancellationToken = default) + string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -433,7 +432,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The tokens corresponding to the specified authorization. public virtual IAsyncEnumerable FindByAuthorizationIdAsync( - [NotNull] string identifier, CancellationToken cancellationToken = default) + string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -476,7 +475,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the token corresponding to the unique identifier. /// - public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask FindByIdAsync(string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -514,7 +513,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the tokens corresponding to the specified reference identifier. /// - public virtual async ValueTask FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -552,7 +551,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The tokens corresponding to the specified subject. public virtual IAsyncEnumerable FindBySubjectAsync( - [NotNull] string subject, CancellationToken cancellationToken = default) + string subject, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(subject)) { @@ -595,7 +594,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the application identifier associated with the token. /// - public virtual ValueTask GetApplicationIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetApplicationIdAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -616,7 +615,7 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -639,8 +638,8 @@ namespace OpenIddict.Core /// whose result returns the first element returned when executing the query. /// public virtual ValueTask GetAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -659,7 +658,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization identifier associated with the token. /// - public virtual ValueTask GetAuthorizationIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -678,7 +677,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the creation date associated with the specified token. /// - public virtual ValueTask GetCreationDateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetCreationDateAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -697,7 +696,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the expiration date associated with the specified token. /// - public virtual ValueTask GetExpirationDateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetExpirationDateAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -716,7 +715,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the unique identifier associated with the token. /// - public virtual ValueTask GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetIdAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -735,7 +734,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the payload associated with the specified token. /// - public virtual ValueTask GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetPayloadAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -756,7 +755,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the reference identifier associated with the specified token. /// - public virtual ValueTask GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetReferenceIdAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -775,7 +774,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the status associated with the specified token. /// - public virtual ValueTask GetStatusAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetStatusAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -794,7 +793,7 @@ namespace OpenIddict.Core /// 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) + public virtual ValueTask GetSubjectAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -813,7 +812,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the token type associated with the specified token. /// - public virtual ValueTask GetTypeAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual ValueTask GetTypeAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -830,7 +829,7 @@ namespace OpenIddict.Core /// The expected status. /// The that can be used to abort the operation. /// true if the token has the specified status, false otherwise. - public virtual async ValueTask HasStatusAsync([NotNull] TToken token, [NotNull] string status, CancellationToken cancellationToken = default) + public virtual async ValueTask HasStatusAsync(TToken token, string status, CancellationToken cancellationToken = default) { if (token == null) { @@ -852,7 +851,7 @@ namespace OpenIddict.Core /// The expected type. /// The that can be used to abort the operation. /// true if the token has the specified type, false otherwise. - public virtual async ValueTask HasTypeAsync([NotNull] TToken token, [NotNull] string type, CancellationToken cancellationToken = default) + public virtual async ValueTask HasTypeAsync(TToken token, string type, CancellationToken cancellationToken = default) { if (token == null) { @@ -875,7 +874,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default) + int? count = null, int? offset = null, CancellationToken cancellationToken = default) => Store.ListAsync(count, offset, cancellationToken); /// @@ -886,7 +885,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, IQueryable> query, CancellationToken cancellationToken = default) + Func, IQueryable> query, CancellationToken cancellationToken = default) { if (query == null) { @@ -906,8 +905,8 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// All the elements returned when executing the specified query. public virtual IAsyncEnumerable ListAsync( - [NotNull] Func, TState, IQueryable> query, - [CanBeNull] TState state, CancellationToken cancellationToken = default) + Func, TState, IQueryable> query, + TState state, CancellationToken cancellationToken = default) { if (query == null) { @@ -926,8 +925,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask PopulateAsync([NotNull] TToken token, - [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask PopulateAsync(TToken token, + OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) { if (token == null) { @@ -960,8 +959,8 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation. /// public virtual async ValueTask PopulateAsync( - [NotNull] OpenIddictTokenDescriptor descriptor, - [NotNull] TToken token, CancellationToken cancellationToken = default) + OpenIddictTokenDescriptor descriptor, + TToken token, CancellationToken cancellationToken = default) { if (descriptor == null) { @@ -1003,8 +1002,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask SetApplicationIdAsync([NotNull] TToken token, - [CanBeNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask SetApplicationIdAsync(TToken token, + string? identifier, CancellationToken cancellationToken = default) { if (token == null) { @@ -1024,8 +1023,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask SetAuthorizationIdAsync([NotNull] TToken token, - [CanBeNull] string identifier, CancellationToken cancellationToken = default) + public virtual async ValueTask SetAuthorizationIdAsync(TToken token, + string? identifier, CancellationToken cancellationToken = default) { if (token == null) { @@ -1043,8 +1042,8 @@ namespace OpenIddict.Core /// The date on which the token will no longer be considered valid. /// The that can be used to abort the operation. /// true if the token was successfully extended, false otherwise. - public virtual async ValueTask TryExtendAsync([NotNull] TToken token, - [CanBeNull] DateTimeOffset? date, CancellationToken cancellationToken = default) + public virtual async ValueTask TryExtendAsync(TToken token, + DateTimeOffset? date, CancellationToken cancellationToken = default) { if (token == null) { @@ -1096,7 +1095,7 @@ namespace OpenIddict.Core /// The token to redeem. /// The that can be used to abort the operation. /// true if the token was successfully redemeed, false otherwise. - public virtual async ValueTask TryRedeemAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRedeemAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -1141,7 +1140,7 @@ namespace OpenIddict.Core /// The token to reject. /// The that can be used to abort the operation. /// true if the token was successfully redemeed, false otherwise. - public virtual async ValueTask TryRejectAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRejectAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -1186,7 +1185,7 @@ namespace OpenIddict.Core /// The token to revoke. /// The that can be used to abort the operation. /// true if the token was successfully revoked, false otherwise. - public virtual async ValueTask TryRevokeAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask TryRevokeAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -1233,7 +1232,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TToken token, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken = default) { if (token == null) { @@ -1286,8 +1285,8 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - public virtual async ValueTask UpdateAsync([NotNull] TToken token, - [NotNull] OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) + public virtual async ValueTask UpdateAsync(TToken token, + OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default) { if (token == null) { @@ -1305,7 +1304,7 @@ namespace OpenIddict.Core // If the reference identifier was updated, re-obfuscate it before persisting the changes. var identifier = await Store.GetReferenceIdAsync(token, cancellationToken); - if (!string.Equals(identifier, comparand, StringComparison.Ordinal)) + if (!string.IsNullOrEmpty(identifier) && !string.Equals(identifier, comparand, StringComparison.Ordinal)) { identifier = await ObfuscateReferenceIdAsync(identifier, cancellationToken); await Store.SetReferenceIdAsync(token, identifier, cancellationToken); @@ -1321,7 +1320,7 @@ namespace OpenIddict.Core /// The that can be used to abort the operation. /// The validation error encountered when validating the token. public virtual async IAsyncEnumerable ValidateAsync( - [NotNull] TToken token, [EnumeratorCancellation] CancellationToken cancellationToken = default) + TToken token, [EnumeratorCancellation] CancellationToken cancellationToken = default) { if (token == null) { @@ -1367,7 +1366,7 @@ namespace OpenIddict.Core /// /// A that can be used to monitor the asynchronous operation. /// - protected virtual ValueTask ObfuscateReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default) + protected virtual ValueTask ObfuscateReferenceIdAsync(string identifier, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(identifier)) { @@ -1380,129 +1379,171 @@ namespace OpenIddict.Core return new ValueTask(Convert.ToBase64String(algorithm.ComputeHash(Encoding.UTF8.GetBytes(identifier)))); } + /// ValueTask IOpenIddictTokenManager.CountAsync(CancellationToken cancellationToken) => CountAsync(cancellationToken); + /// ValueTask IOpenIddictTokenManager.CountAsync(Func, IQueryable> query, CancellationToken cancellationToken) => CountAsync(query, cancellationToken); + /// async ValueTask IOpenIddictTokenManager.CreateAsync(OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken) => await CreateAsync(descriptor, cancellationToken); + /// ValueTask IOpenIddictTokenManager.CreateAsync(object token, CancellationToken cancellationToken) => CreateAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.DeleteAsync(object token, CancellationToken cancellationToken) => DeleteAsync((TToken) token, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.FindAsync(string subject, string client, CancellationToken cancellationToken) => FindAsync(subject, client, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.FindAsync(string subject, string client, string status, CancellationToken cancellationToken) => FindAsync(subject, client, status, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.FindAsync(string subject, string client, string status, string type, CancellationToken cancellationToken) => FindAsync(subject, client, status, type, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken) => FindByApplicationIdAsync(identifier, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken) => FindByAuthorizationIdAsync(identifier, cancellationToken); - async ValueTask IOpenIddictTokenManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) + /// + async ValueTask IOpenIddictTokenManager.FindByIdAsync(string identifier, CancellationToken cancellationToken) => await FindByIdAsync(identifier, cancellationToken); - async ValueTask IOpenIddictTokenManager.FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken) + /// + async ValueTask IOpenIddictTokenManager.FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken) => await FindByReferenceIdAsync(identifier, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.FindBySubjectAsync(string subject, CancellationToken cancellationToken) => FindBySubjectAsync(subject, cancellationToken); - ValueTask IOpenIddictTokenManager.GetApplicationIdAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetApplicationIdAsync(object token, CancellationToken cancellationToken) => GetApplicationIdAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.GetAsync(Func, IQueryable> query, CancellationToken cancellationToken) => GetAsync(query, cancellationToken); + /// ValueTask IOpenIddictTokenManager.GetAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => GetAsync(query, state, cancellationToken); - ValueTask IOpenIddictTokenManager.GetAuthorizationIdAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetAuthorizationIdAsync(object token, CancellationToken cancellationToken) => GetAuthorizationIdAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.GetCreationDateAsync(object token, CancellationToken cancellationToken) => GetCreationDateAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.GetExpirationDateAsync(object token, CancellationToken cancellationToken) => GetExpirationDateAsync((TToken) token, cancellationToken); - ValueTask IOpenIddictTokenManager.GetIdAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetIdAsync(object token, CancellationToken cancellationToken) => GetIdAsync((TToken) token, cancellationToken); - ValueTask IOpenIddictTokenManager.GetPayloadAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetPayloadAsync(object token, CancellationToken cancellationToken) => GetPayloadAsync((TToken) token, cancellationToken); - ValueTask IOpenIddictTokenManager.GetReferenceIdAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetReferenceIdAsync(object token, CancellationToken cancellationToken) => GetReferenceIdAsync((TToken) token, cancellationToken); - ValueTask IOpenIddictTokenManager.GetStatusAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetStatusAsync(object token, CancellationToken cancellationToken) => GetStatusAsync((TToken) token, cancellationToken); - ValueTask IOpenIddictTokenManager.GetSubjectAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetSubjectAsync(object token, CancellationToken cancellationToken) => GetSubjectAsync((TToken) token, cancellationToken); - ValueTask IOpenIddictTokenManager.GetTypeAsync(object token, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.GetTypeAsync(object token, CancellationToken cancellationToken) => GetTypeAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.HasStatusAsync(object token, string status, CancellationToken cancellationToken) => HasStatusAsync((TToken) token, status, cancellationToken); + /// ValueTask IOpenIddictTokenManager.HasTypeAsync(object token, string type, CancellationToken cancellationToken) => HasTypeAsync((TToken) token, type, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.ListAsync(int? count, int? offset, CancellationToken cancellationToken) => ListAsync(count, offset, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.ListAsync(Func, IQueryable> query, CancellationToken cancellationToken) => ListAsync(query, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.ListAsync(Func, TState, IQueryable> query, TState state, CancellationToken cancellationToken) => ListAsync(query, state, cancellationToken); + /// ValueTask IOpenIddictTokenManager.PopulateAsync(OpenIddictTokenDescriptor descriptor, object token, CancellationToken cancellationToken) => PopulateAsync(descriptor, (TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.PopulateAsync(object token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken) => PopulateAsync((TToken) token, descriptor, cancellationToken); + /// ValueTask IOpenIddictTokenManager.PruneAsync(CancellationToken cancellationToken) => PruneAsync(cancellationToken); - ValueTask IOpenIddictTokenManager.SetApplicationIdAsync(object token, string identifier, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.SetApplicationIdAsync(object token, string? identifier, CancellationToken cancellationToken) => SetApplicationIdAsync((TToken) token, identifier, cancellationToken); - ValueTask IOpenIddictTokenManager.SetAuthorizationIdAsync(object token, string identifier, CancellationToken cancellationToken) + /// + ValueTask IOpenIddictTokenManager.SetAuthorizationIdAsync(object token, string? identifier, CancellationToken cancellationToken) => SetAuthorizationIdAsync((TToken) token, identifier, cancellationToken); + /// ValueTask IOpenIddictTokenManager.TryExtendAsync(object token, DateTimeOffset? date, CancellationToken cancellationToken) => TryExtendAsync((TToken) token, date, cancellationToken); + /// ValueTask IOpenIddictTokenManager.TryRedeemAsync(object token, CancellationToken cancellationToken) => TryRedeemAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.TryRejectAsync(object token, CancellationToken cancellationToken) => TryRejectAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.TryRevokeAsync(object token, CancellationToken cancellationToken) => TryRevokeAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.UpdateAsync(object token, CancellationToken cancellationToken) => UpdateAsync((TToken) token, cancellationToken); + /// ValueTask IOpenIddictTokenManager.UpdateAsync(object token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken) => UpdateAsync((TToken) token, descriptor, cancellationToken); + /// IAsyncEnumerable IOpenIddictTokenManager.ValidateAsync(object token, CancellationToken cancellationToken) => ValidateAsync((TToken) token, cancellationToken); } diff --git a/src/OpenIddict.Core/OpenIddict.Core.csproj b/src/OpenIddict.Core/OpenIddict.Core.csproj index e651c40b..4039b6f4 100644 --- a/src/OpenIddict.Core/OpenIddict.Core.csproj +++ b/src/OpenIddict.Core/OpenIddict.Core.csproj @@ -2,6 +2,7 @@ net461;net472;netcoreapp2.1;netcoreapp3.1;netstandard2.0;netstandard2.1 + enable diff --git a/src/OpenIddict.Core/OpenIddictCoreBuilder.cs b/src/OpenIddict.Core/OpenIddictCoreBuilder.cs index 7864ff1d..ee83367e 100644 --- a/src/OpenIddict.Core/OpenIddictCoreBuilder.cs +++ b/src/OpenIddict.Core/OpenIddictCoreBuilder.cs @@ -6,7 +6,6 @@ using System; using System.ComponentModel; -using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection.Extensions; using OpenIddict.Abstractions; using OpenIddict.Core; @@ -24,7 +23,7 @@ namespace Microsoft.Extensions.DependencyInjection /// Initializes a new instance of . /// /// The services collection. - public OpenIddictCoreBuilder([NotNull] IServiceCollection services) + public OpenIddictCoreBuilder(IServiceCollection services) => Services = services ?? throw new ArgumentNullException(nameof(services)); /// @@ -39,7 +38,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The delegate used to configure the OpenIddict options. /// This extension can be safely called multiple times. /// The . - public OpenIddictCoreBuilder Configure([NotNull] Action configuration) + public OpenIddictCoreBuilder Configure(Action configuration) { if (configuration == null) { @@ -73,8 +72,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddApplicationStore( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddApplicationStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -130,8 +128,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddAuthorizationStore( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddAuthorizationStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -187,8 +184,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddScopeStore( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddScopeStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -244,8 +240,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The type of the custom store. /// The lifetime of the registered service. /// The . - public OpenIddictCoreBuilder AddTokenStore( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + public OpenIddictCoreBuilder AddTokenStore(Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -299,7 +294,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceApplicationManager([NotNull] Type type) + public OpenIddictCoreBuilder ReplaceApplicationManager(Type type) { if (type == null) { @@ -356,7 +351,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceApplicationStoreResolver( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -393,7 +388,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceAuthorizationManager([NotNull] Type type) + public OpenIddictCoreBuilder ReplaceAuthorizationManager(Type type) { if (type == null) { @@ -450,7 +445,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceAuthorizationStoreResolver( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -487,7 +482,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceScopeManager([NotNull] Type type) + public OpenIddictCoreBuilder ReplaceScopeManager(Type type) { if (type == null) { @@ -544,7 +539,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceScopeStoreResolver( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -581,7 +576,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The type of the custom manager. /// The . - public OpenIddictCoreBuilder ReplaceTokenManager([NotNull] Type type) + public OpenIddictCoreBuilder ReplaceTokenManager(Type type) { if (type == null) { @@ -638,7 +633,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The lifetime of the registered service. /// The . public OpenIddictCoreBuilder ReplaceTokenStoreResolver( - [NotNull] Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) + Type type, ServiceLifetime lifetime = ServiceLifetime.Scoped) { if (type == null) { @@ -687,7 +682,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The application entity type. /// The . - public OpenIddictCoreBuilder SetDefaultApplicationEntity([NotNull] Type type) + public OpenIddictCoreBuilder SetDefaultApplicationEntity(Type type) { if (type == null) { @@ -714,7 +709,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The authorization entity type. /// The . - public OpenIddictCoreBuilder SetDefaultAuthorizationEntity([NotNull] Type type) + public OpenIddictCoreBuilder SetDefaultAuthorizationEntity(Type type) { if (type == null) { @@ -741,7 +736,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The scope entity type. /// The . - public OpenIddictCoreBuilder SetDefaultScopeEntity([NotNull] Type type) + public OpenIddictCoreBuilder SetDefaultScopeEntity(Type type) { if (type == null) { @@ -768,7 +763,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The token entity type. /// The . - public OpenIddictCoreBuilder SetDefaultTokenEntity([NotNull] Type type) + public OpenIddictCoreBuilder SetDefaultTokenEntity(Type type) { if (type == null) { @@ -805,7 +800,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The object to compare with the current object. /// true if the specified object is equal to the current object; otherwise, false. [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals([CanBeNull] object obj) => base.Equals(obj); + public override bool Equals(object? obj) => base.Equals(obj); /// /// Serves as the default hash function. @@ -819,6 +814,6 @@ namespace Microsoft.Extensions.DependencyInjection /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => base.ToString(); + public override string? ToString() => base.ToString(); } } diff --git a/src/OpenIddict.Core/OpenIddictCoreExtensions.cs b/src/OpenIddict.Core/OpenIddictCoreExtensions.cs index 97ebe471..3c976165 100644 --- a/src/OpenIddict.Core/OpenIddictCoreExtensions.cs +++ b/src/OpenIddict.Core/OpenIddictCoreExtensions.cs @@ -5,7 +5,6 @@ */ using System; -using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging.Abstractions; @@ -28,7 +27,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictCoreBuilder AddCore([NotNull] this OpenIddictBuilder builder) + public static OpenIddictCoreBuilder AddCore(this OpenIddictBuilder builder) { if (builder == null) { @@ -125,9 +124,7 @@ namespace Microsoft.Extensions.DependencyInjection /// The configuration delegate used to configure the core services. /// This extension can be safely called multiple times. /// The . - public static OpenIddictBuilder AddCore( - [NotNull] this OpenIddictBuilder builder, - [NotNull] Action configuration) + public static OpenIddictBuilder AddCore(this OpenIddictBuilder builder, Action configuration) { if (builder == null) { diff --git a/src/OpenIddict.Core/OpenIddictCoreOptions.cs b/src/OpenIddict.Core/OpenIddictCoreOptions.cs index c5b19ff3..cd76b419 100644 --- a/src/OpenIddict.Core/OpenIddictCoreOptions.cs +++ b/src/OpenIddict.Core/OpenIddictCoreOptions.cs @@ -17,25 +17,25 @@ namespace OpenIddict.Core /// Gets or sets the type corresponding to the default Application entity, /// used by the non-generic application manager and the server/validation services. /// - public Type DefaultApplicationType { get; set; } + public Type? DefaultApplicationType { get; set; } /// /// Gets or sets the type corresponding to the default Authorization entity, /// used by the non-generic authorization manager and the server/validation services. /// - public Type DefaultAuthorizationType { get; set; } + public Type? DefaultAuthorizationType { get; set; } /// /// Gets or sets the type corresponding to the default Scope entity, /// used by the non-generic scope manager and the server/validation services. /// - public Type DefaultScopeType { get; set; } + public Type? DefaultScopeType { get; set; } /// /// Gets or sets the type corresponding to the default Token entity, /// used by the non-generic token manager and the server/validation services. /// - public Type DefaultTokenType { get; set; } + public Type? DefaultTokenType { get; set; } /// /// Gets or sets a boolean indicating whether additional filtering should be disabled, diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs index a113d3df..05cad2c5 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictApplicationStoreResolver.cs @@ -1,5 +1,4 @@ using System; -using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; using OpenIddict.Abstractions; using SR = OpenIddict.Abstractions.OpenIddictResources; @@ -13,7 +12,7 @@ namespace OpenIddict.Core { private readonly IServiceProvider _provider; - public OpenIddictApplicationStoreResolver([NotNull] IServiceProvider provider) + public OpenIddictApplicationStoreResolver(IServiceProvider provider) => _provider = provider; /// diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs index bfcb4137..7827d2a6 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictAuthorizationStoreResolver.cs @@ -1,5 +1,4 @@ using System; -using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; using OpenIddict.Abstractions; using SR = OpenIddict.Abstractions.OpenIddictResources; @@ -13,7 +12,7 @@ namespace OpenIddict.Core { private readonly IServiceProvider _provider; - public OpenIddictAuthorizationStoreResolver([NotNull] IServiceProvider provider) + public OpenIddictAuthorizationStoreResolver(IServiceProvider provider) => _provider = provider; /// diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs index b5e15103..5baf5658 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictScopeStoreResolver.cs @@ -1,5 +1,4 @@ using System; -using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; using OpenIddict.Abstractions; using SR = OpenIddict.Abstractions.OpenIddictResources; @@ -13,7 +12,7 @@ namespace OpenIddict.Core { private readonly IServiceProvider _provider; - public OpenIddictScopeStoreResolver([NotNull] IServiceProvider provider) + public OpenIddictScopeStoreResolver(IServiceProvider provider) => _provider = provider; /// diff --git a/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs b/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs index 49c3e40b..7e9c14bc 100644 --- a/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs +++ b/src/OpenIddict.Core/Resolvers/OpenIddictTokenStoreResolver.cs @@ -1,5 +1,4 @@ using System; -using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; using OpenIddict.Abstractions; using SR = OpenIddict.Abstractions.OpenIddictResources; @@ -13,7 +12,7 @@ namespace OpenIddict.Core { private readonly IServiceProvider _provider; - public OpenIddictTokenStoreResolver([NotNull] IServiceProvider provider) + public OpenIddictTokenStoreResolver(IServiceProvider provider) => _provider = provider; ///