|
|
|
@ -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; |
|
|
|
} |
|
|
|
|