Browse Source

Introduce OpenIddictApplication/Authorization/Scope/Token.Properties as a way to store untyped properties in the database

pull/545/head
Kévin Chalet 8 years ago
parent
commit
fb5d8c9351
  1. 1
      build/dependencies.props
  2. 28
      src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
  3. 1
      src/OpenIddict.Core/OpenIddict.Core.csproj
  4. 23
      src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs
  5. 23
      src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs
  6. 23
      src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs
  7. 23
      src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs
  8. 54
      src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs
  9. 54
      src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs
  10. 54
      src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs
  11. 54
      src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs
  12. 6
      src/OpenIddict.Models/OpenIddictApplication.cs
  13. 6
      src/OpenIddict.Models/OpenIddictAuthorization.cs
  14. 6
      src/OpenIddict.Models/OpenIddictScope.cs
  15. 6
      src/OpenIddict.Models/OpenIddictToken.cs

1
build/dependencies.props

@ -8,6 +8,7 @@
<CryptoHelperVersion>3.0.0</CryptoHelperVersion>
<EntityFrameworkVersion>6.1.3</EntityFrameworkVersion>
<JetBrainsVersion>10.3.0</JetBrainsVersion>
<JsonNetVersion>10.0.2</JsonNetVersion>
<JsonNetBsonVersion>1.0.1</JsonNetBsonVersion>
<ImmutableCollectionsVersion>1.4.0</ImmutableCollectionsVersion>
<MoqVersion>4.7.63</MoqVersion>

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

@ -389,62 +389,62 @@ namespace OpenIddict.Core
}
/// <summary>
/// Retrieves the reference identifier associated with a token.
/// Note: depending on the manager used to create the token,
/// the reference identifier may be hashed for security reasons.
/// Retrieves the unique identifier 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="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the reference identifier associated with the specified token.
/// whose result returns the unique identifier associated with the token.
/// </returns>
public virtual Task<string> GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual Task<string> GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetReferenceIdAsync(token, cancellationToken);
return Store.GetIdAsync(token, cancellationToken);
}
/// <summary>
/// Retrieves the unique identifier associated with a token.
/// Retrieves the payload 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="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the unique identifier associated with the token.
/// whose result returns the payload associated with the specified token.
/// </returns>
public virtual Task<string> GetIdAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual Task<string> GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetIdAsync(token, cancellationToken);
return Store.GetPayloadAsync(token, cancellationToken);
}
/// <summary>
/// Retrieves the payload associated with a token.
/// Retrieves the reference identifier associated with a token.
/// Note: depending on the manager used to create the token,
/// the reference identifier may be hashed for security reasons.
/// </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="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the payload associated with the specified token.
/// whose result returns the reference identifier associated with the specified token.
/// </returns>
public virtual Task<string> GetPayloadAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual Task<string> GetReferenceIdAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
}
return Store.GetPayloadAsync(token, cancellationToken);
return Store.GetReferenceIdAsync(token, cancellationToken);
}
/// <summary>

1
src/OpenIddict.Core/OpenIddict.Core.csproj

@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(JsonNetVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="$(ImmutableCollectionsVersion)" />
</ItemGroup>

23
src/OpenIddict.Core/Stores/IOpenIddictApplicationStore.cs

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
namespace OpenIddict.Core
{
@ -189,6 +190,17 @@ namespace OpenIddict.Core
/// </returns>
Task<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync([NotNull] TApplication application, CancellationToken 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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the application.
/// </returns>
Task<JObject> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the callback addresses associated with an application.
/// </summary>
@ -296,6 +308,17 @@ namespace OpenIddict.Core
Task SetPostLogoutRedirectUrisAsync([NotNull] TApplication application,
ImmutableArray<string> addresses, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with an application.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="properties">The additional properties associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
Task SetPropertiesAsync([NotNull] TApplication application, [CanBeNull] JObject properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the callback addresses associated with an application.
/// </summary>

23
src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
namespace OpenIddict.Core
{
@ -123,6 +124,17 @@ namespace OpenIddict.Core
/// </returns>
Task<string> GetIdAsync([NotNull] TAuthorization authorization, CancellationToken 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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the authorization.
/// </returns>
Task<JObject> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the scopes associated with an authorization.
/// </summary>
@ -230,6 +242,17 @@ namespace OpenIddict.Core
Task SetApplicationIdAsync([NotNull] TAuthorization authorization,
[CanBeNull] string identifier, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with an authorization.
/// </summary>
/// <param name="authorization">The authorization.</param>
/// <param name="properties">The additional properties associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
Task SetPropertiesAsync([NotNull] TAuthorization authorization, [CanBeNull] JObject properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the scopes associated with an authorization.
/// </summary>

23
src/OpenIddict.Core/Stores/IOpenIddictScopeStore.cs

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
namespace OpenIddict.Core
{
@ -121,6 +122,17 @@ namespace OpenIddict.Core
/// </returns>
Task<string> GetNameAsync([NotNull] TScope scope, CancellationToken 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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the scope.
/// </returns>
Task<JObject> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken);
/// <summary>
/// Instantiates a new scope.
/// </summary>
@ -181,6 +193,17 @@ namespace OpenIddict.Core
/// </returns>
Task SetNameAsync([NotNull] TScope scope, [CanBeNull] string name, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with a scope.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="properties">The additional properties associated with the scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
Task SetPropertiesAsync([NotNull] TScope scope, [CanBeNull] JObject properties, CancellationToken cancellationToken);
/// <summary>
/// Updates an existing scope.
/// </summary>

23
src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
namespace OpenIddict.Core
{
@ -197,6 +198,17 @@ namespace OpenIddict.Core
/// </returns>
Task<string> GetPayloadAsync([NotNull] TToken token, CancellationToken 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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the token.
/// </returns>
Task<JObject> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the reference identifier associated with a token.
/// Note: depending on the manager used to create the token,
@ -349,6 +361,17 @@ namespace OpenIddict.Core
/// </returns>
Task SetPayloadAsync([NotNull] TToken token, [CanBeNull] string payload, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with a token.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="properties">The additional properties associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
Task SetPropertiesAsync([NotNull] TToken token, [CanBeNull] JObject properties, CancellationToken cancellationToken);
/// <summary>
/// Sets the reference identifier associated with a token.
/// Note: depending on the manager used to create the token,

54
src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs

@ -11,6 +11,8 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenIddict.Models;
namespace OpenIddict.Core
@ -381,6 +383,30 @@ namespace OpenIddict.Core
return Task.FromResult(ImmutableArray.Create(uris));
}
/// <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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the application.
/// </returns>
public virtual Task<JObject> GetPropertiesAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
if (string.IsNullOrEmpty(application.Properties))
{
return Task.FromResult(new JObject());
}
return Task.FromResult(JObject.Parse(application.Properties));
}
/// <summary>
/// Retrieves the callback addresses associated with an application.
/// </summary>
@ -596,6 +622,34 @@ namespace OpenIddict.Core
return Task.CompletedTask;
}
/// <summary>
/// Sets the additional properties associated with an application.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="properties">The additional properties associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
public virtual Task SetPropertiesAsync([NotNull] TApplication application, [CanBeNull] JObject properties, CancellationToken cancellationToken)
{
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
if (properties == null)
{
application.Properties = null;
return Task.CompletedTask;
}
application.Properties = properties.ToString(Formatting.None);
return Task.CompletedTask;
}
/// <summary>
/// Sets the callback addresses associated with an application.
/// </summary>

54
src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs

@ -11,6 +11,8 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenIddict.Models;
namespace OpenIddict.Core
@ -199,6 +201,30 @@ namespace OpenIddict.Core
return Task.FromResult(ConvertIdentifierToString(authorization.Id));
}
/// <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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the authorization.
/// </returns>
public virtual Task<JObject> GetPropertiesAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization == null)
{
throw new ArgumentNullException(nameof(authorization));
}
if (string.IsNullOrEmpty(authorization.Properties))
{
return Task.FromResult(new JObject());
}
return Task.FromResult(JObject.Parse(authorization.Properties));
}
/// <summary>
/// Retrieves the scopes associated with an authorization.
/// </summary>
@ -387,6 +413,34 @@ namespace OpenIddict.Core
public abstract Task SetApplicationIdAsync([NotNull] TAuthorization authorization,
[CanBeNull] string identifier, CancellationToken cancellationToken);
/// <summary>
/// Sets the additional properties associated with an authorization.
/// </summary>
/// <param name="authorization">The authorization.</param>
/// <param name="properties">The additional properties associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
public virtual Task SetPropertiesAsync([NotNull] TAuthorization authorization, [CanBeNull] JObject properties, CancellationToken cancellationToken)
{
if (authorization == null)
{
throw new ArgumentNullException(nameof(authorization));
}
if (properties == null)
{
authorization.Properties = null;
return Task.CompletedTask;
}
authorization.Properties = properties.ToString(Formatting.None);
return Task.CompletedTask;
}
/// <summary>
/// Sets the scopes associated with an authorization.
/// </summary>

54
src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs

@ -11,6 +11,8 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenIddict.Models;
namespace OpenIddict.Core
@ -167,6 +169,30 @@ namespace OpenIddict.Core
return Task.FromResult(scope.Name);
}
/// <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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the scope.
/// </returns>
public virtual Task<JObject> GetPropertiesAsync([NotNull] TScope scope, CancellationToken cancellationToken)
{
if (scope == null)
{
throw new ArgumentNullException(nameof(scope));
}
if (string.IsNullOrEmpty(scope.Properties))
{
return Task.FromResult(new JObject());
}
return Task.FromResult(JObject.Parse(scope.Properties));
}
/// <summary>
/// Instantiates a new scope.
/// </summary>
@ -267,6 +293,34 @@ namespace OpenIddict.Core
return Task.CompletedTask;
}
/// <summary>
/// Sets the additional properties associated with a scope.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="properties">The additional properties associated with the scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
public virtual Task SetPropertiesAsync([NotNull] TScope scope, [CanBeNull] JObject properties, CancellationToken cancellationToken)
{
if (scope == null)
{
throw new ArgumentNullException(nameof(scope));
}
if (properties == null)
{
scope.Properties = null;
return Task.CompletedTask;
}
scope.Properties = properties.ToString(Formatting.None);
return Task.CompletedTask;
}
/// <summary>
/// Updates an existing scope.
/// </summary>

54
src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs

@ -11,6 +11,8 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenIddict.Models;
namespace OpenIddict.Core
@ -347,6 +349,30 @@ namespace OpenIddict.Core
return Task.FromResult(token.Payload);
}
/// <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="Task"/> that can be used to monitor the asynchronous operation, whose
/// result returns all the additional properties associated with the token.
/// </returns>
public virtual Task<JObject> GetPropertiesAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
}
if (string.IsNullOrEmpty(token.Properties))
{
return Task.FromResult(new JObject());
}
return Task.FromResult(JObject.Parse(token.Properties));
}
/// <summary>
/// Retrieves the reference identifier associated with a token.
/// Note: depending on the manager used to create the token,
@ -607,6 +633,34 @@ namespace OpenIddict.Core
return Task.CompletedTask;
}
/// <summary>
/// Sets the additional properties associated with a token.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="properties">The additional properties associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
/// </returns>
public virtual Task SetPropertiesAsync([NotNull] TToken token, [CanBeNull] JObject properties, CancellationToken cancellationToken)
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
}
if (properties == null)
{
token.Properties = null;
return Task.CompletedTask;
}
token.Properties = properties.ToString(Formatting.None);
return Task.CompletedTask;
}
/// <summary>
/// Sets the reference identifier associated with a token.
/// Note: depending on the manager used to create the token,

6
src/OpenIddict.Models/OpenIddictApplication.cs

@ -75,6 +75,12 @@ namespace OpenIddict.Models
/// </summary>
public virtual string PostLogoutRedirectUris { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current application.
/// </summary>
public virtual string Properties { get; set; }
/// <summary>
/// Gets or sets the callback URLs
/// associated with the current application,

6
src/OpenIddict.Models/OpenIddictAuthorization.cs

@ -49,6 +49,12 @@ namespace OpenIddict.Models
/// </summary>
public virtual TKey Id { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current authorization.
/// </summary>
public virtual string Properties { get; set; }
/// <summary>
/// Gets or sets the space-delimited scopes
/// associated with the current authorization.

6
src/OpenIddict.Models/OpenIddictScope.cs

@ -47,5 +47,11 @@ namespace OpenIddict.Models
/// associated with the current scope.
/// </summary>
public virtual string Name { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current scope.
/// </summary>
public virtual string Properties { get; set; }
}
}

6
src/OpenIddict.Models/OpenIddictToken.cs

@ -73,6 +73,12 @@ namespace OpenIddict.Models
/// </summary>
public virtual string Payload { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current token.
/// </summary>
public virtual string Properties { get; set; }
/// <summary>
/// Gets or sets the reference identifier associated
/// with the current token, if applicable.

Loading…
Cancel
Save