Browse Source

Replace ImmutableDictionary<string, object> by ImmutableDictionary<string, JsonElement>

pull/850/head
Kévin Chalet 7 years ago
parent
commit
09fe3f0955
  1. 22
      src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
  2. 4
      src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs
  3. 4
      src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs
  4. 4
      src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs
  5. 4
      src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs
  6. 10
      src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
  7. 10
      src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
  8. 10
      src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
  9. 10
      src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
  10. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  11. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  12. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
  13. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
  14. 17
      src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs
  15. 17
      src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs
  16. 15
      src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs
  17. 17
      src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs
  18. 10
      src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs
  19. 10
      src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs
  20. 10
      src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs
  21. 10
      src/OpenIddict.NHibernate/Stores/OpenIddictTokenStore.cs

22
src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs

@ -522,7 +522,7 @@ namespace OpenIddict.Abstractions
return parameter?.Value switch
{
// When the parameter is a null value, return null.
null => default(JsonElement?),
null => null,
// When the parameter is a JsonElement representing null, return null.
JsonElement value when value.ValueKind == JsonValueKind.Undefined => null,
@ -548,8 +548,16 @@ namespace OpenIddict.Abstractions
static JsonElement? DeserializeElement(string value)
{
try { return JsonSerializer.Deserialize<JsonElement>(value); }
catch (JsonException) { return null; }
try
{
using var document = JsonDocument.Parse(value);
return document.RootElement.Clone();
}
catch (JsonException)
{
return null;
}
}
}
@ -620,12 +628,8 @@ namespace OpenIddict.Abstractions
// When the parameter is a JsonElement representing a string, return it as-is.
JsonElement value when value.ValueKind == JsonValueKind.String => value.GetString(),
// When the parameter is a JsonElement that doesn't represent a string, serialize it.
JsonElement value => JsonSerializer.Serialize(value, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = false
}),
// When the parameter is a JsonElement that doesn't represent a string, return its raw representation.
JsonElement value => value.GetRawText(),
// If the parameter is of a different type, return null to indicate the conversion failed.
_ => null

4
src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs

@ -212,7 +212,7 @@ namespace OpenIddict.Abstractions
/// 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, object>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the callback addresses associated with an application.
@ -342,7 +342,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TApplication application,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken);
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the callback addresses associated with an application.

4
src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs

@ -183,7 +183,7 @@ namespace OpenIddict.Abstractions
/// 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, object>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the scopes associated with an authorization.
@ -286,7 +286,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken);
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the scopes associated with an authorization.

4
src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs

@ -166,7 +166,7 @@ namespace OpenIddict.Abstractions
/// 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, object>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the resources associated with a scope.
@ -246,7 +246,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken);
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the resources associated with a scope.

4
src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs

@ -232,7 +232,7 @@ namespace OpenIddict.Abstractions
/// 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, object>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken);
ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the reference identifier associated with a token.
@ -372,7 +372,7 @@ namespace OpenIddict.Abstractions
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
ValueTask SetPropertiesAsync([NotNull] TToken token,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken);
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the reference identifier associated with a token.

10
src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs

@ -537,7 +537,7 @@ namespace OpenIddict.EntityFramework
/// 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, object>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
@ -546,7 +546,7 @@ namespace OpenIddict.EntityFramework
if (string.IsNullOrEmpty(application.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -557,10 +557,10 @@ namespace OpenIddict.EntityFramework
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(application.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(application.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -876,7 +876,7 @@ namespace OpenIddict.EntityFramework
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (application == null)
{

10
src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs

@ -488,7 +488,7 @@ namespace OpenIddict.EntityFramework
/// 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, object>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization == null)
{
@ -497,7 +497,7 @@ namespace OpenIddict.EntityFramework
if (string.IsNullOrEmpty(authorization.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -508,10 +508,10 @@ namespace OpenIddict.EntityFramework
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(authorization.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(authorization.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -819,7 +819,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (authorization == null)
{

10
src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs

@ -357,7 +357,7 @@ namespace OpenIddict.EntityFramework
/// 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, object>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
{
if (scope == null)
{
@ -366,7 +366,7 @@ namespace OpenIddict.EntityFramework
if (string.IsNullOrEmpty(scope.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -377,10 +377,10 @@ namespace OpenIddict.EntityFramework
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(scope.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(scope.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -555,7 +555,7 @@ namespace OpenIddict.EntityFramework
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (scope == null)
{

10
src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs

@ -575,7 +575,7 @@ namespace OpenIddict.EntityFramework
/// 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, object>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
@ -584,7 +584,7 @@ namespace OpenIddict.EntityFramework
if (string.IsNullOrEmpty(token.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -595,10 +595,10 @@ namespace OpenIddict.EntityFramework
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(token.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(token.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -988,7 +988,7 @@ namespace OpenIddict.EntityFramework
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TToken token,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (token == null)
{

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs

@ -584,7 +584,7 @@ namespace OpenIddict.EntityFrameworkCore
/// 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, object>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
@ -593,7 +593,7 @@ namespace OpenIddict.EntityFrameworkCore
if (string.IsNullOrEmpty(application.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -604,10 +604,10 @@ namespace OpenIddict.EntityFrameworkCore
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(application.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(application.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -923,7 +923,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (application == null)
{

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

@ -542,7 +542,7 @@ namespace OpenIddict.EntityFrameworkCore
/// 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, object>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization == null)
{
@ -551,7 +551,7 @@ namespace OpenIddict.EntityFrameworkCore
if (string.IsNullOrEmpty(authorization.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -562,10 +562,10 @@ namespace OpenIddict.EntityFrameworkCore
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(authorization.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(authorization.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -887,7 +887,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (authorization == null)
{

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs

@ -372,7 +372,7 @@ namespace OpenIddict.EntityFrameworkCore
/// 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, object>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
{
if (scope == null)
{
@ -381,7 +381,7 @@ namespace OpenIddict.EntityFrameworkCore
if (string.IsNullOrEmpty(scope.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -392,10 +392,10 @@ namespace OpenIddict.EntityFrameworkCore
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(scope.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(scope.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -570,7 +570,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (scope == null)
{

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

@ -622,7 +622,7 @@ namespace OpenIddict.EntityFrameworkCore
/// 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, object>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
@ -631,7 +631,7 @@ namespace OpenIddict.EntityFrameworkCore
if (string.IsNullOrEmpty(token.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -642,10 +642,10 @@ namespace OpenIddict.EntityFrameworkCore
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(token.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(token.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -1070,7 +1070,7 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TToken token,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (token == null)
{

17
src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs

@ -10,6 +10,8 @@ using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
@ -446,7 +448,7 @@ namespace OpenIddict.MongoDb
/// 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, object>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
@ -455,10 +457,11 @@ namespace OpenIddict.MongoDb
if (application.Properties == null)
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
return new ValueTask<ImmutableDictionary<string, object>>(application.Properties.ToDictionary().ToImmutableDictionary());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(
JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(application.Properties.ToJson()));
}
/// <summary>
@ -762,7 +765,7 @@ namespace OpenIddict.MongoDb
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (application == null)
{
@ -776,7 +779,11 @@ namespace OpenIddict.MongoDb
return default;
}
application.Properties = new BsonDocument(properties.ToDictionary(property => property.Key, property => property.Value));
application.Properties = BsonDocument.Parse(JsonSerializer.Serialize(properties, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = false
}));
return default;
}

17
src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs

@ -10,6 +10,8 @@ using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
@ -480,7 +482,7 @@ namespace OpenIddict.MongoDb
/// 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, object>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization == null)
{
@ -489,10 +491,11 @@ namespace OpenIddict.MongoDb
if (authorization.Properties == null)
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
return new ValueTask<ImmutableDictionary<string, object>>(authorization.Properties.ToDictionary().ToImmutableDictionary());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(
JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(authorization.Properties.ToJson()));
}
/// <summary>
@ -765,7 +768,7 @@ namespace OpenIddict.MongoDb
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (authorization == null)
{
@ -779,7 +782,11 @@ namespace OpenIddict.MongoDb
return default;
}
authorization.Properties = new BsonDocument(properties.ToDictionary(property => property.Key, property => property.Value));
authorization.Properties = BsonDocument.Parse(JsonSerializer.Serialize(properties, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = false
}));
return default;
}

15
src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs

@ -349,7 +349,7 @@ namespace OpenIddict.MongoDb
/// 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, object>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
{
if (scope == null)
{
@ -358,10 +358,11 @@ namespace OpenIddict.MongoDb
if (scope.Properties == null)
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
return new ValueTask<ImmutableDictionary<string, object>>(scope.Properties.ToDictionary().ToImmutableDictionary());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(
JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(scope.Properties.ToJson()));
}
/// <summary>
@ -542,7 +543,7 @@ namespace OpenIddict.MongoDb
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (scope == null)
{
@ -556,7 +557,11 @@ namespace OpenIddict.MongoDb
return default;
}
scope.Properties = new BsonDocument(properties.ToDictionary(property => property.Key, property => property.Value));
scope.Properties = BsonDocument.Parse(JsonSerializer.Serialize(properties, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = false
}));
return default;
}

17
src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs

@ -10,6 +10,8 @@ using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
@ -545,7 +547,7 @@ namespace OpenIddict.MongoDb
/// 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, object>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
@ -554,10 +556,11 @@ namespace OpenIddict.MongoDb
if (token.Properties == null)
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
return new ValueTask<ImmutableDictionary<string, object>>(token.Properties.ToDictionary().ToImmutableDictionary());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(
JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(token.Properties.ToJson()));
}
/// <summary>
@ -864,7 +867,7 @@ namespace OpenIddict.MongoDb
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TToken token,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (token == null)
{
@ -878,7 +881,11 @@ namespace OpenIddict.MongoDb
return default;
}
token.Properties = new BsonDocument(properties.ToDictionary(property => property.Key, property => property.Value));
token.Properties = BsonDocument.Parse(JsonSerializer.Serialize(properties, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = false
}));
return default;
}

10
src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs

@ -524,7 +524,7 @@ namespace OpenIddict.NHibernate
/// 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, object>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
@ -533,7 +533,7 @@ namespace OpenIddict.NHibernate
if (string.IsNullOrEmpty(application.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -544,10 +544,10 @@ namespace OpenIddict.NHibernate
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(application.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(application.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -879,7 +879,7 @@ namespace OpenIddict.NHibernate
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (application == null)
{

10
src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs

@ -506,7 +506,7 @@ namespace OpenIddict.NHibernate
/// 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, object>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization == null)
{
@ -515,7 +515,7 @@ namespace OpenIddict.NHibernate
if (string.IsNullOrEmpty(authorization.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -526,10 +526,10 @@ namespace OpenIddict.NHibernate
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(authorization.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(authorization.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -773,7 +773,7 @@ namespace OpenIddict.NHibernate
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (authorization == null)
{

10
src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs

@ -390,7 +390,7 @@ namespace OpenIddict.NHibernate
/// 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, object>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
{
if (scope == null)
{
@ -399,7 +399,7 @@ namespace OpenIddict.NHibernate
if (string.IsNullOrEmpty(scope.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -410,10 +410,10 @@ namespace OpenIddict.NHibernate
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(scope.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(scope.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -604,7 +604,7 @@ namespace OpenIddict.NHibernate
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (scope == null)
{

10
src/OpenIddict.NHibernate/Stores/OpenIddictTokenStore.cs

@ -626,7 +626,7 @@ namespace OpenIddict.NHibernate
/// 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, object>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
@ -635,7 +635,7 @@ namespace OpenIddict.NHibernate
if (string.IsNullOrEmpty(token.Properties))
{
return new ValueTask<ImmutableDictionary<string, object>>(ImmutableDictionary.Create<string, object>());
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
@ -646,10 +646,10 @@ namespace OpenIddict.NHibernate
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JsonSerializer.Deserialize<ImmutableDictionary<string, object>>(token.Properties);
return JsonSerializer.Deserialize<ImmutableDictionary<string, JsonElement>>(token.Properties);
});
return new ValueTask<ImmutableDictionary<string, object>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
}
/// <summary>
@ -963,7 +963,7 @@ namespace OpenIddict.NHibernate
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask SetPropertiesAsync([NotNull] TToken token,
[CanBeNull] ImmutableDictionary<string, object> properties, CancellationToken cancellationToken)
[CanBeNull] ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (token == null)
{

Loading…
Cancel
Save