From 09fe3f09551a2a4317920c93f553ca18c37eaea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Fri, 29 Nov 2019 16:04:14 +0100 Subject: [PATCH] Replace ImmutableDictionary by ImmutableDictionary --- .../Primitives/OpenIddictParameter.cs | 22 +++++++++++-------- .../Stores/IOpenIddictApplicationStore.cs | 4 ++-- .../Stores/IOpenIddictAuthorizationStore.cs | 4 ++-- .../Stores/IOpenIddictScopeStore.cs | 4 ++-- .../Stores/IOpenIddictTokenStore.cs | 4 ++-- .../Stores/OpenIddictApplicationStore.cs | 10 ++++----- .../Stores/OpenIddictAuthorizationStore.cs | 10 ++++----- .../Stores/OpenIddictScopeStore.cs | 10 ++++----- .../Stores/OpenIddictTokenStore.cs | 10 ++++----- .../Stores/OpenIddictApplicationStore.cs | 10 ++++----- .../Stores/OpenIddictAuthorizationStore.cs | 10 ++++----- .../Stores/OpenIddictScopeStore.cs | 10 ++++----- .../Stores/OpenIddictTokenStore.cs | 10 ++++----- .../Stores/OpenIddictApplicationStore.cs | 17 +++++++++----- .../Stores/OpenIddictAuthorizationStore.cs | 17 +++++++++----- .../Stores/OpenIddictScopeStore.cs | 15 ++++++++----- .../Stores/OpenIddictTokenStore.cs | 17 +++++++++----- .../Stores/OpenIddictApplicationStore.cs | 10 ++++----- .../Stores/OpenIddictAuthorizationStore.cs | 10 ++++----- .../Stores/OpenIddictScopeStore.cs | 10 ++++----- .../Stores/OpenIddictTokenStore.cs | 10 ++++----- 21 files changed, 127 insertions(+), 97 deletions(-) diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs index 9ad8661e..a2645edc 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs +++ b/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(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 diff --git a/src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs b/src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs index 1289e4e1..96264937 100644 --- a/src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs +++ b/src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs @@ -212,7 +212,7 @@ namespace OpenIddict.Abstractions /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the application. /// - ValueTask> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken); + ValueTask> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken); /// /// Retrieves the callback addresses associated with an application. @@ -342,7 +342,7 @@ namespace OpenIddict.Abstractions /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. ValueTask SetPropertiesAsync([NotNull] TApplication application, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); /// /// Sets the callback addresses associated with an application. diff --git a/src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs b/src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs index 93ddf219..f83d9373 100644 --- a/src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs @@ -183,7 +183,7 @@ namespace OpenIddict.Abstractions /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the authorization. /// - ValueTask> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); + ValueTask> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken); /// /// Retrieves the scopes associated with an authorization. @@ -286,7 +286,7 @@ namespace OpenIddict.Abstractions /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); /// /// Sets the scopes associated with an authorization. diff --git a/src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs b/src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs index 6876dd77..6ea1eb31 100644 --- a/src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs +++ b/src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs @@ -166,7 +166,7 @@ namespace OpenIddict.Abstractions /// A that can be used to monitor the asynchronous operation, whose /// result returns all the additional properties associated with the scope. /// - ValueTask> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken); + ValueTask> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken); /// /// Retrieves the resources associated with a scope. @@ -246,7 +246,7 @@ namespace OpenIddict.Abstractions /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. ValueTask SetPropertiesAsync([NotNull] TScope scope, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); /// /// Sets the resources associated with a scope. diff --git a/src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs b/src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs index 5c0c2f93..83b40b5c 100644 --- a/src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs +++ b/src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs @@ -232,7 +232,7 @@ namespace OpenIddict.Abstractions /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the token. /// - ValueTask> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken); + ValueTask> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken); /// /// Retrieves the reference identifier associated with a token. @@ -372,7 +372,7 @@ namespace OpenIddict.Abstractions /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. ValueTask SetPropertiesAsync([NotNull] TToken token, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken); /// /// Sets the reference identifier associated with a token. diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs index dfe26f3e..3ce51bed 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs @@ -537,7 +537,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the application. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(application.Properties); + return JsonSerializer.Deserialize>(application.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -876,7 +876,7 @@ namespace OpenIddict.EntityFramework /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (application == null) { diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs index 970642dd..c0908422 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs @@ -488,7 +488,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the authorization. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(authorization.Properties); + return JsonSerializer.Deserialize>(authorization.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -819,7 +819,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation. /// public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (authorization == null) { diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs index ae0cc855..cff96c40 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs @@ -357,7 +357,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the scope. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(scope.Properties); + return JsonSerializer.Deserialize>(scope.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -555,7 +555,7 @@ namespace OpenIddict.EntityFramework /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (scope == null) { diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs index 907d488b..69735ef9 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs @@ -575,7 +575,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the token. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(token.Properties); + return JsonSerializer.Deserialize>(token.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -988,7 +988,7 @@ namespace OpenIddict.EntityFramework /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TToken token, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (token == null) { diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs index 45ee2718..773dfe27 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs @@ -584,7 +584,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the application. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(application.Properties); + return JsonSerializer.Deserialize>(application.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -923,7 +923,7 @@ namespace OpenIddict.EntityFrameworkCore /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (application == null) { diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs index 0887f2e4..bf46a016 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs @@ -542,7 +542,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the authorization. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(authorization.Properties); + return JsonSerializer.Deserialize>(authorization.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -887,7 +887,7 @@ namespace OpenIddict.EntityFrameworkCore /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (authorization == null) { diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs index 00bf2e56..69699c2d 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs @@ -372,7 +372,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the scope. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(scope.Properties); + return JsonSerializer.Deserialize>(scope.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -570,7 +570,7 @@ namespace OpenIddict.EntityFrameworkCore /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (scope == null) { diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs index 6475338c..067101fa 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs @@ -622,7 +622,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the token. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(token.Properties); + return JsonSerializer.Deserialize>(token.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -1070,7 +1070,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation. /// public virtual ValueTask SetPropertiesAsync([NotNull] TToken token, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (token == null) { diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs index 0a7c8ddf..b01908e2 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs +++ b/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 that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the application. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -455,10 +457,11 @@ namespace OpenIddict.MongoDb if (application.Properties == null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } - return new ValueTask>(application.Properties.ToDictionary().ToImmutableDictionary()); + return new ValueTask>( + JsonSerializer.Deserialize>(application.Properties.ToJson())); } /// @@ -762,7 +765,7 @@ namespace OpenIddict.MongoDb /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary 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; } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs index 16e7a51f..df638351 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs +++ b/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 that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the authorization. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { @@ -489,10 +491,11 @@ namespace OpenIddict.MongoDb if (authorization.Properties == null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } - return new ValueTask>(authorization.Properties.ToDictionary().ToImmutableDictionary()); + return new ValueTask>( + JsonSerializer.Deserialize>(authorization.Properties.ToJson())); } /// @@ -765,7 +768,7 @@ namespace OpenIddict.MongoDb /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary 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; } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs index ced982bd..89963b85 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs @@ -349,7 +349,7 @@ namespace OpenIddict.MongoDb /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the scope. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { @@ -358,10 +358,11 @@ namespace OpenIddict.MongoDb if (scope.Properties == null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } - return new ValueTask>(scope.Properties.ToDictionary().ToImmutableDictionary()); + return new ValueTask>( + JsonSerializer.Deserialize>(scope.Properties.ToJson())); } /// @@ -542,7 +543,7 @@ namespace OpenIddict.MongoDb /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary 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; } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs index 2394b474..67c76922 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs +++ b/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 that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the token. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -554,10 +556,11 @@ namespace OpenIddict.MongoDb if (token.Properties == null) { - return new ValueTask>(ImmutableDictionary.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } - return new ValueTask>(token.Properties.ToDictionary().ToImmutableDictionary()); + return new ValueTask>( + JsonSerializer.Deserialize>(token.Properties.ToJson())); } /// @@ -864,7 +867,7 @@ namespace OpenIddict.MongoDb /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TToken token, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary 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; } diff --git a/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs index eb808ce2..f04e3734 100644 --- a/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs @@ -524,7 +524,7 @@ namespace OpenIddict.NHibernate /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the application. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(application.Properties); + return JsonSerializer.Deserialize>(application.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -879,7 +879,7 @@ namespace OpenIddict.NHibernate /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TApplication application, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (application == null) { diff --git a/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs index c25c0ac7..85467e82 100644 --- a/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs @@ -506,7 +506,7 @@ namespace OpenIddict.NHibernate /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the authorization. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(authorization.Properties); + return JsonSerializer.Deserialize>(authorization.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -773,7 +773,7 @@ namespace OpenIddict.NHibernate /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TAuthorization authorization, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (authorization == null) { diff --git a/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs index f325a07f..2b0b198c 100644 --- a/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs @@ -390,7 +390,7 @@ namespace OpenIddict.NHibernate /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the scope. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(scope.Properties); + return JsonSerializer.Deserialize>(scope.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -604,7 +604,7 @@ namespace OpenIddict.NHibernate /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TScope scope, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (scope == null) { diff --git a/src/OpenIddict.NHibernate/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.NHibernate/Stores/OpenIddictTokenStore.cs index a5c859c0..0e81a3b1 100644 --- a/src/OpenIddict.NHibernate/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.NHibernate/Stores/OpenIddictTokenStore.cs @@ -626,7 +626,7 @@ namespace OpenIddict.NHibernate /// A that can be used to monitor the asynchronous operation, /// whose result returns all the additional properties associated with the token. /// - public virtual ValueTask> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual ValueTask> 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.Create()); + return new ValueTask>(ImmutableDictionary.Create()); } // 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>(token.Properties); + return JsonSerializer.Deserialize>(token.Properties); }); - return new ValueTask>(properties); + return new ValueTask>(properties); } /// @@ -963,7 +963,7 @@ namespace OpenIddict.NHibernate /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. public virtual ValueTask SetPropertiesAsync([NotNull] TToken token, - [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) + [CanBeNull] ImmutableDictionary properties, CancellationToken cancellationToken) { if (token == null) {