Browse Source

Introduce new APIs in the core managers to allow retrieving and adding additional properties

pull/1171/head 3.0.0-rc1
Kévin Chalet 5 years ago
parent
commit
d58cac661a
  1. 17
      src/OpenIddict.Abstractions/Descriptors/OpenIddictApplicationDescriptor.cs
  2. 8
      src/OpenIddict.Abstractions/Descriptors/OpenIddictAuthorizationDescriptor.cs
  3. 12
      src/OpenIddict.Abstractions/Descriptors/OpenIddictScopeDescriptor.cs
  4. 7
      src/OpenIddict.Abstractions/Descriptors/OpenIddictTokenDescriptor.cs
  5. 12
      src/OpenIddict.Abstractions/Managers/IOpenIddictApplicationManager.cs
  6. 12
      src/OpenIddict.Abstractions/Managers/IOpenIddictAuthorizationManager.cs
  7. 12
      src/OpenIddict.Abstractions/Managers/IOpenIddictScopeManager.cs
  8. 13
      src/OpenIddict.Abstractions/Managers/IOpenIddictTokenManager.cs
  9. 32
      src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
  10. 32
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  11. 32
      src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
  12. 32
      src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs

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

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json;
namespace OpenIddict.Abstractions
{
@ -34,28 +35,32 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets the localized display names associated with the application.
/// </summary>
public Dictionary<CultureInfo, string> DisplayNames { get; }
= new Dictionary<CultureInfo, string>();
public Dictionary<CultureInfo, string> DisplayNames { get; } = new();
/// <summary>
/// Gets the permissions associated with the application.
/// </summary>
public HashSet<string> Permissions { get; } = new HashSet<string>(StringComparer.Ordinal);
public HashSet<string> Permissions { get; } = new(StringComparer.Ordinal);
/// <summary>
/// Gets the logout callback URLs associated with the application.
/// </summary>
public HashSet<Uri> PostLogoutRedirectUris { get; } = new HashSet<Uri>();
public HashSet<Uri> PostLogoutRedirectUris { get; } = new();
/// <summary>
/// Gets the additional properties associated with the application.
/// </summary>
public Dictionary<string, JsonElement> Properties { get; } = new(StringComparer.Ordinal);
/// <summary>
/// Gets the callback URLs associated with the application.
/// </summary>
public HashSet<Uri> RedirectUris { get; } = new HashSet<Uri>();
public HashSet<Uri> RedirectUris { get; } = new();
/// <summary>
/// Gets the requirements associated with the application.
/// </summary>
public HashSet<string> Requirements { get; } = new HashSet<string>(StringComparer.Ordinal);
public HashSet<string> Requirements { get; } = new(StringComparer.Ordinal);
/// <summary>
/// Gets or sets the application type associated with the application.

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

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Text.Json;
namespace OpenIddict.Abstractions
{
@ -25,10 +26,15 @@ namespace OpenIddict.Abstractions
/// </summary>
public ClaimsPrincipal? Principal { get; set; }
/// <summary>
/// Gets the additional properties associated with the authorization.
/// </summary>
public Dictionary<string, JsonElement> Properties { get; } = new(StringComparer.Ordinal);
/// <summary>
/// Gets the scopes associated with the authorization.
/// </summary>
public HashSet<string> Scopes { get; } = new HashSet<string>(StringComparer.Ordinal);
public HashSet<string> Scopes { get; } = new(StringComparer.Ordinal);
/// <summary>
/// Gets or sets the status associated with the authorization.

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

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json;
namespace OpenIddict.Abstractions
{
@ -17,7 +18,7 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets the localized descriptions associated with the scope.
/// </summary>
public Dictionary<CultureInfo, string> Descriptions { get; } = new Dictionary<CultureInfo, string>();
public Dictionary<CultureInfo, string> Descriptions { get; } = new();
/// <summary>
/// Gets or sets the display name associated with the scope.
@ -27,16 +28,21 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Gets the localized display names associated with the scope.
/// </summary>
public Dictionary<CultureInfo, string> DisplayNames { get; } = new Dictionary<CultureInfo, string>();
public Dictionary<CultureInfo, string> DisplayNames { get; } = new();
/// <summary>
/// Gets or sets the unique name associated with the scope.
/// </summary>
public string? Name { get; set; }
/// <summary>
/// Gets the additional properties associated with the scope.
/// </summary>
public Dictionary<string, JsonElement> Properties { get; } = new(StringComparer.Ordinal);
/// <summary>
/// Gets the resources associated with the scope.
/// </summary>
public HashSet<string> Resources { get; } = new HashSet<string>(StringComparer.Ordinal);
public HashSet<string> Resources { get; } = new(StringComparer.Ordinal);
}
}

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

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Text.Json;
namespace OpenIddict.Abstractions
{
@ -39,6 +41,11 @@ namespace OpenIddict.Abstractions
/// </summary>
public ClaimsPrincipal? Principal { get; set; }
/// <summary>
/// Gets the additional properties associated with the token.
/// </summary>
public Dictionary<string, JsonElement> Properties { get; } = new(StringComparer.Ordinal);
/// <summary>
/// Gets or sets the redemption date associated with the token.
/// </summary>

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

@ -10,6 +10,7 @@ using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -275,6 +276,17 @@ namespace OpenIddict.Abstractions
/// </returns>
ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the additional properties associated with an application.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the application.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(object application, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the callback addresses associated with an application.
/// </summary>

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

@ -10,6 +10,7 @@ using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -232,6 +233,17 @@ namespace OpenIddict.Abstractions
/// </returns>
ValueTask<string?> GetIdAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the additional properties associated with an authorization.
/// </summary>
/// <param name="authorization">The authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the authorization.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(object authorization, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the scopes associated with an authorization.
/// </summary>

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

@ -10,6 +10,7 @@ using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -264,6 +265,17 @@ namespace OpenIddict.Abstractions
/// </returns>
ValueTask<string?> GetNameAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the additional properties associated with a scope.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the scope.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(object scope, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the resources associated with a scope.
/// </summary>

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

@ -6,8 +6,10 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -253,6 +255,17 @@ namespace OpenIddict.Abstractions
/// </returns>
ValueTask<string?> GetPayloadAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the additional properties associated with a token.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the token.
/// </returns>
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(object token, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the redemption date associated with a token.
/// </summary>

32
src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs

@ -15,6 +15,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -696,6 +697,26 @@ namespace OpenIddict.Core
return Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken);
}
/// <summary>
/// Retrieves the additional properties associated with an application.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the application.
/// </returns>
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TApplication application, CancellationToken cancellationToken = default)
{
if (application is null)
{
throw new ArgumentNullException(nameof(application));
}
return Store.GetPropertiesAsync(application, cancellationToken);
}
/// <summary>
/// Retrieves the callback addresses associated with an application.
/// </summary>
@ -909,6 +930,7 @@ namespace OpenIddict.Core
await Store.SetPermissionsAsync(application, descriptor.Permissions.ToImmutableArray(), cancellationToken);
await Store.SetPostLogoutRedirectUrisAsync(application, ImmutableArray.CreateRange(
descriptor.PostLogoutRedirectUris.Select(address => address.OriginalString)), cancellationToken);
await Store.SetPropertiesAsync(application, descriptor.Properties.ToImmutableDictionary(), cancellationToken);
await Store.SetRedirectUrisAsync(application, ImmutableArray.CreateRange(
descriptor.RedirectUris.Select(address => address.OriginalString)), cancellationToken);
await Store.SetRequirementsAsync(application, descriptor.Requirements.ToImmutableArray(), cancellationToken);
@ -971,6 +993,12 @@ namespace OpenIddict.Core
descriptor.PostLogoutRedirectUris.Add(uri);
}
descriptor.Properties.Clear();
foreach (var pair in await Store.GetPropertiesAsync(application, cancellationToken))
{
descriptor.Properties.Add(pair.Key, pair.Value);
}
descriptor.RedirectUris.Clear();
foreach (var address in await Store.GetRedirectUrisAsync(application, cancellationToken))
{
@ -1581,6 +1609,10 @@ namespace OpenIddict.Core
ValueTask<ImmutableArray<string>> IOpenIddictApplicationManager.GetPostLogoutRedirectUrisAsync(object application, CancellationToken cancellationToken)
=> GetPostLogoutRedirectUrisAsync((TApplication) application, cancellationToken);
/// <inheritdoc/>
ValueTask<ImmutableDictionary<string, JsonElement>> IOpenIddictApplicationManager.GetPropertiesAsync(object application, CancellationToken cancellationToken)
=> GetPropertiesAsync((TApplication) application, cancellationToken);
/// <inheritdoc/>
ValueTask<ImmutableArray<string>> IOpenIddictApplicationManager.GetRedirectUrisAsync(object application, CancellationToken cancellationToken)
=> GetRedirectUrisAsync((TApplication) application, cancellationToken);

32
src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs

@ -12,6 +12,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Claims;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -714,6 +715,26 @@ namespace OpenIddict.Core
return Store.GetIdAsync(authorization, cancellationToken);
}
/// <summary>
/// Retrieves the additional properties associated with an authorization.
/// </summary>
/// <param name="authorization">The authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the authorization.
/// </returns>
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TAuthorization authorization, CancellationToken cancellationToken = default)
{
if (authorization is null)
{
throw new ArgumentNullException(nameof(authorization));
}
return Store.GetPropertiesAsync(authorization, cancellationToken);
}
/// <summary>
/// Retrieves the scopes associated with an authorization.
/// </summary>
@ -933,6 +954,7 @@ namespace OpenIddict.Core
await Store.SetApplicationIdAsync(authorization, descriptor.ApplicationId, cancellationToken);
await Store.SetCreationDateAsync(authorization, descriptor.CreationDate, cancellationToken);
await Store.SetPropertiesAsync(authorization, descriptor.Properties.ToImmutableDictionary(), cancellationToken);
await Store.SetScopesAsync(authorization, descriptor.Scopes.ToImmutableArray(), cancellationToken);
await Store.SetStatusAsync(authorization, descriptor.Status, cancellationToken);
await Store.SetSubjectAsync(authorization, descriptor.Subject, cancellationToken);
@ -969,6 +991,12 @@ namespace OpenIddict.Core
descriptor.Status = await Store.GetStatusAsync(authorization, cancellationToken);
descriptor.Subject = await Store.GetSubjectAsync(authorization, cancellationToken);
descriptor.Type = await Store.GetTypeAsync(authorization, cancellationToken);
descriptor.Properties.Clear();
foreach (var pair in await Store.GetPropertiesAsync(authorization, cancellationToken))
{
descriptor.Properties.Add(pair.Key, pair.Value);
}
}
/// <summary>
@ -1231,6 +1259,10 @@ namespace OpenIddict.Core
ValueTask<string?> IOpenIddictAuthorizationManager.GetIdAsync(object authorization, CancellationToken cancellationToken)
=> GetIdAsync((TAuthorization) authorization, cancellationToken);
/// <inheritdoc/>
ValueTask<ImmutableDictionary<string, JsonElement>> IOpenIddictAuthorizationManager.GetPropertiesAsync(object authorization, CancellationToken cancellationToken)
=> GetPropertiesAsync((TAuthorization) authorization, cancellationToken);
/// <inheritdoc/>
ValueTask<ImmutableArray<string>> IOpenIddictAuthorizationManager.GetScopesAsync(object authorization, CancellationToken cancellationToken)
=> GetScopesAsync((TAuthorization) authorization, cancellationToken);

32
src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs

@ -12,6 +12,7 @@ using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -650,6 +651,26 @@ namespace OpenIddict.Core
return Store.GetNameAsync(scope, cancellationToken);
}
/// <summary>
/// Retrieves the additional properties associated with a scope.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the scope.
/// </returns>
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TScope scope, CancellationToken cancellationToken = default)
{
if (scope is null)
{
throw new ArgumentNullException(nameof(scope));
}
return Store.GetPropertiesAsync(scope, cancellationToken);
}
/// <summary>
/// Retrieves the resources associated with a scope.
/// </summary>
@ -769,6 +790,7 @@ namespace OpenIddict.Core
await Store.SetDisplayNameAsync(scope, descriptor.DisplayName, cancellationToken);
await Store.SetDisplayNamesAsync(scope, descriptor.DisplayNames.ToImmutableDictionary(), cancellationToken);
await Store.SetNameAsync(scope, descriptor.Name, cancellationToken);
await Store.SetPropertiesAsync(scope, descriptor.Properties.ToImmutableDictionary(), cancellationToken);
await Store.SetResourcesAsync(scope, descriptor.Resources.ToImmutableArray(), cancellationToken);
}
@ -812,6 +834,12 @@ namespace OpenIddict.Core
{
descriptor.Descriptions.Add(pair.Key, pair.Value);
}
descriptor.Properties.Clear();
foreach (var pair in await Store.GetPropertiesAsync(scope, cancellationToken))
{
descriptor.Properties.Add(pair.Key, pair.Value);
}
}
/// <summary>
@ -1019,6 +1047,10 @@ namespace OpenIddict.Core
ValueTask<string?> IOpenIddictScopeManager.GetNameAsync(object scope, CancellationToken cancellationToken)
=> GetNameAsync((TScope) scope, cancellationToken);
/// <inheritdoc/>
ValueTask<ImmutableDictionary<string, JsonElement>> IOpenIddictScopeManager.GetPropertiesAsync(object scope, CancellationToken cancellationToken)
=> GetPropertiesAsync((TScope) scope, cancellationToken);
/// <inheritdoc/>
ValueTask<ImmutableArray<string>> IOpenIddictScopeManager.GetResourcesAsync(object scope, CancellationToken cancellationToken)
=> GetResourcesAsync((TScope) scope, cancellationToken);

32
src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs

@ -12,6 +12,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -736,6 +737,26 @@ namespace OpenIddict.Core
return Store.GetPayloadAsync(token, cancellationToken);
}
/// <summary>
/// Retrieves the additional properties associated with a token.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the additional properties associated with the token.
/// </returns>
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(
TToken token, CancellationToken cancellationToken = default)
{
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetPropertiesAsync(token, cancellationToken);
}
/// <summary>
/// Retrieves the redemption date associated with a token.
/// </summary>
@ -954,6 +975,7 @@ namespace OpenIddict.Core
await Store.SetCreationDateAsync(token, descriptor.CreationDate, cancellationToken);
await Store.SetExpirationDateAsync(token, descriptor.ExpirationDate, cancellationToken);
await Store.SetPayloadAsync(token, descriptor.Payload, cancellationToken);
await Store.SetPropertiesAsync(token, descriptor.Properties.ToImmutableDictionary(), cancellationToken);
await Store.SetRedemptionDateAsync(token, descriptor.RedemptionDate, cancellationToken);
await Store.SetReferenceIdAsync(token, descriptor.ReferenceId, cancellationToken);
await Store.SetStatusAsync(token, descriptor.Status, cancellationToken);
@ -994,6 +1016,12 @@ namespace OpenIddict.Core
descriptor.Status = await Store.GetStatusAsync(token, cancellationToken);
descriptor.Subject = await Store.GetSubjectAsync(token, cancellationToken);
descriptor.Type = await Store.GetTypeAsync(token, cancellationToken);
descriptor.Properties.Clear();
foreach (var pair in await Store.GetPropertiesAsync(token, cancellationToken))
{
descriptor.Properties.Add(pair.Key, pair.Value);
}
}
/// <summary>
@ -1370,6 +1398,10 @@ namespace OpenIddict.Core
ValueTask<string?> IOpenIddictTokenManager.GetPayloadAsync(object token, CancellationToken cancellationToken)
=> GetPayloadAsync((TToken) token, cancellationToken);
/// <inheritdoc/>
ValueTask<ImmutableDictionary<string, JsonElement>> IOpenIddictTokenManager.GetPropertiesAsync(object token, CancellationToken cancellationToken)
=> GetPropertiesAsync((TToken) token, cancellationToken);
/// <inheritdoc/>
ValueTask<DateTimeOffset?> IOpenIddictTokenManager.GetRedemptionDateAsync(object token, CancellationToken cancellationToken)
=> GetRedemptionDateAsync((TToken) token, cancellationToken);

Loading…
Cancel
Save