From 41a19beb412bb9b43dfcf5193988dcc00c1d7549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Fri, 29 Dec 2017 22:32:36 +0100 Subject: [PATCH] Introduce IOpenIddictScopeStore/OpenIddictScopeManager.FindByIdAsync()/GetIdAsync() --- .../Managers/OpenIddictScopeManager.cs | 38 ++++++++++++++++ .../Stores/IOpenIddictScopeStore.cs | 22 ++++++++++ .../Stores/OpenIddictScopeStore.cs | 43 +++++++++++++++++++ .../Stores/OpenIddictScopeStore.cs | 19 ++++++++ .../Stores/OpenIddictScopeStore.cs | 19 ++++++++ 5 files changed, 141 insertions(+) diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index 48cd9add..644e7b23 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -152,6 +152,25 @@ 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 virtual Task FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(identifier)) + { + throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); + } + + return Store.FindByIdAsync(identifier, cancellationToken); + } + /// /// Executes the specified query and returns the first element. /// @@ -191,6 +210,25 @@ namespace OpenIddict.Core return Store.GetAsync(query, state, cancellationToken); } + /// + /// Retrieves the unique identifier associated with a scope. + /// + /// 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 unique identifier associated with the scope. + /// + public virtual Task GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken) + { + if (scope == null) + { + throw new ArgumentNullException(nameof(scope)); + } + + return Store.GetIdAsync(scope, cancellationToken); + } + /// /// Executes the specified query and returns all the corresponding elements. /// diff --git a/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs index 4460c2d5..4d3c7329 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs @@ -61,6 +61,17 @@ namespace OpenIddict.Core /// Task DeleteAsync([NotNull] TScope scope, CancellationToken cancellationToken); + /// + /// 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. + /// + Task FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken); + /// /// Executes the specified query and returns the first element. /// @@ -88,6 +99,17 @@ namespace OpenIddict.Core /// Task GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken); + /// + /// Retrieves the unique identifier associated with a scope. + /// + /// 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 unique identifier associated with the scope. + /// + Task GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken); + /// /// Retrieves the name associated with a scope. /// diff --git a/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs index d828c2bc..1591f97e 100644 --- a/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs @@ -70,6 +70,30 @@ namespace OpenIddict.Core /// public abstract Task DeleteAsync([NotNull] TScope scope, CancellationToken cancellationToken); + /// + /// 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 virtual Task FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(identifier)) + { + throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); + } + + IQueryable Query(IQueryable scopes, TKey key) + => from scope in scopes + where scope.Id.Equals(key) + select scope; + + return GetAsync((scopes, key) => Query(scopes, key), ConvertIdentifierFromString(identifier), cancellationToken); + } + /// /// Executes the specified query and returns the first element. /// @@ -105,6 +129,25 @@ namespace OpenIddict.Core return Task.FromResult(scope.Description); } + /// + /// Retrieves the unique identifier associated with a scope. + /// + /// 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 unique identifier associated with the scope. + /// + public virtual Task GetIdAsync([NotNull] TScope scope, CancellationToken cancellationToken) + { + if (scope == null) + { + throw new ArgumentNullException(nameof(scope)); + } + + return Task.FromResult(ConvertIdentifierToString(scope.Id)); + } + /// /// Retrieves the name associated with a scope. /// diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs index adad729a..4cad07cd 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs @@ -134,6 +134,25 @@ namespace OpenIddict.EntityFramework return Context.SaveChangesAsync(cancellationToken); } + /// + /// 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 override Task FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(identifier)) + { + throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); + } + + return Scopes.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier)); + } + /// /// Executes the specified query and returns the first element. /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs index b46276e8..536f7af3 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs @@ -134,6 +134,25 @@ namespace OpenIddict.EntityFrameworkCore return Context.SaveChangesAsync(cancellationToken); } + /// + /// 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 override Task FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(identifier)) + { + throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); + } + + return Scopes.FindAsync(new object[] { ConvertIdentifierFromString(identifier) }, cancellationToken); + } + /// /// Executes the specified query and returns the first element. ///