From 595012507e0b274d056dcc9a3e85d00efc41ff7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Tue, 13 Feb 2018 18:34:31 +0100 Subject: [PATCH] Add a new DisplayName property to OpenIddictScope/OpenIddictScopeDescriptor --- .../Descriptors/OpenIddictScopeDescriptor.cs | 6 +++ .../Managers/OpenIddictScopeManager.cs | 21 ++++++++++ .../Stores/IOpenIddictScopeStore.cs | 22 ++++++++++ .../Stores/OpenIddictScopeStore.cs | 40 +++++++++++++++++++ src/OpenIddict.Models/OpenIddictScope.cs | 6 +++ 5 files changed, 95 insertions(+) diff --git a/src/OpenIddict.Core/Descriptors/OpenIddictScopeDescriptor.cs b/src/OpenIddict.Core/Descriptors/OpenIddictScopeDescriptor.cs index 82f4418d..01b41d12 100644 --- a/src/OpenIddict.Core/Descriptors/OpenIddictScopeDescriptor.cs +++ b/src/OpenIddict.Core/Descriptors/OpenIddictScopeDescriptor.cs @@ -14,6 +14,12 @@ namespace OpenIddict.Core /// public virtual string Description { get; set; } + /// + /// Gets or sets the display name + /// associated with the scope. + /// + public virtual string DisplayName { get; set; } + /// /// Gets or sets the unique name /// associated with the scope. diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index ca3b536d..bd3659e2 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -261,6 +261,25 @@ namespace OpenIddict.Core return Store.GetDescriptionAsync(scope, cancellationToken); } + /// + /// Retrieves the display name 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 display name associated with the scope. + /// + public virtual Task GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken = default) + { + if (scope == null) + { + throw new ArgumentNullException(nameof(scope)); + } + + return Store.GetDisplayNameAsync(scope, cancellationToken); + } + /// /// Retrieves the unique identifier associated with a scope. /// @@ -452,6 +471,7 @@ namespace OpenIddict.Core var descriptor = new OpenIddictScopeDescriptor { Description = await Store.GetDescriptionAsync(scope, cancellationToken), + DisplayName = await Store.GetDisplayNameAsync(scope, cancellationToken), Name = await Store.GetNameAsync(scope, cancellationToken) }; @@ -512,6 +532,7 @@ namespace OpenIddict.Core } await Store.SetDescriptionAsync(scope, descriptor.Description, cancellationToken); + await Store.SetDisplayNameAsync(scope, descriptor.DisplayName, cancellationToken); await Store.SetNameAsync(scope, descriptor.Name, cancellationToken); await Store.SetResourcesAsync(scope, descriptor.Resources.ToImmutableArray(), cancellationToken); } diff --git a/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs b/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs index 69b662ab..f0f2ade9 100644 --- a/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs +++ b/src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs @@ -122,6 +122,17 @@ namespace OpenIddict.Core /// Task GetDescriptionAsync([NotNull] TScope scope, CancellationToken cancellationToken); + /// + /// Retrieves the display name 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 display name associated with the scope. + /// + Task GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken); + /// /// Retrieves the unique identifier associated with a scope. /// @@ -215,6 +226,17 @@ namespace OpenIddict.Core /// Task SetDescriptionAsync([NotNull] TScope scope, [CanBeNull] string description, CancellationToken cancellationToken); + /// + /// Sets the display name associated with a scope. + /// + /// The scope. + /// The display name associated with the scope. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + Task SetDisplayNameAsync([NotNull] TScope scope, [CanBeNull] string name, CancellationToken cancellationToken); + /// /// Sets the name associated with a scope. /// diff --git a/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs index 0ed07b04..5bd08b87 100644 --- a/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs @@ -196,6 +196,25 @@ namespace OpenIddict.Core return Task.FromResult(scope.Description); } + /// + /// Retrieves the display name 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 display name associated with the scope. + /// + public virtual Task GetDisplayNameAsync([NotNull] TScope scope, CancellationToken cancellationToken) + { + if (scope == null) + { + throw new ArgumentNullException(nameof(scope)); + } + + return Task.FromResult(scope.DisplayName); + } + /// /// Retrieves the unique identifier associated with a scope. /// @@ -373,6 +392,27 @@ namespace OpenIddict.Core return Task.CompletedTask; } + /// + /// Sets the display name associated with a scope. + /// + /// The scope. + /// The display name associated with the scope. + /// The that can be used to abort the operation. + /// + /// A that can be used to monitor the asynchronous operation. + /// + public virtual Task SetDisplayNameAsync([NotNull] TScope scope, [CanBeNull] string name, CancellationToken cancellationToken) + { + if (scope == null) + { + throw new ArgumentNullException(nameof(scope)); + } + + scope.DisplayName = name; + + return Task.CompletedTask; + } + /// /// Sets the name associated with a scope. /// diff --git a/src/OpenIddict.Models/OpenIddictScope.cs b/src/OpenIddict.Models/OpenIddictScope.cs index 3d07847a..c02b52ae 100644 --- a/src/OpenIddict.Models/OpenIddictScope.cs +++ b/src/OpenIddict.Models/OpenIddictScope.cs @@ -36,6 +36,12 @@ namespace OpenIddict.Models /// public virtual string Description { get; set; } + /// + /// Gets or sets the display name + /// associated with the current scope. + /// + public virtual string DisplayName { get; set; } + /// /// Gets or sets the unique identifier /// associated with the current scope.