Browse Source

Introduce OpenIddictAuthorizationManager.FindByApplicationIdAsync() and decorate the built-in models with [DebuggerDisplay]

pull/670/merge
Kévin Chalet 8 years ago
parent
commit
a60014dda5
  1. 11
      src/OpenIddict.Abstractions/Managers/IOpenIddictAuthorizationManager.cs
  2. 11
      src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs
  3. 23
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  4. 2
      src/OpenIddict.EntityFramework.Models/OpenIddictApplication.cs
  5. 2
      src/OpenIddict.EntityFramework.Models/OpenIddictAuthorization.cs
  6. 2
      src/OpenIddict.EntityFramework.Models/OpenIddictScope.cs
  7. 2
      src/OpenIddict.EntityFramework.Models/OpenIddictToken.cs
  8. 25
      src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
  9. 2
      src/OpenIddict.EntityFrameworkCore.Models/OpenIddictApplication.cs
  10. 2
      src/OpenIddict.EntityFrameworkCore.Models/OpenIddictAuthorization.cs
  11. 2
      src/OpenIddict.EntityFrameworkCore.Models/OpenIddictScope.cs
  12. 2
      src/OpenIddict.EntityFrameworkCore.Models/OpenIddictToken.cs
  13. 38
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  14. 2
      src/OpenIddict.MongoDb.Models/OpenIddictApplication.cs
  15. 2
      src/OpenIddict.MongoDb.Models/OpenIddictAuthorization.cs
  16. 2
      src/OpenIddict.MongoDb.Models/OpenIddictScope.cs
  17. 2
      src/OpenIddict.MongoDb.Models/OpenIddictToken.cs
  18. 24
      src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs

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

@ -141,6 +141,17 @@ namespace OpenIddict.Abstractions
/// </returns>
Task<ImmutableArray<object>> FindAsync([NotNull] string subject, [NotNull] string client, [NotNull] string status, [NotNull] string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the authorizations.</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 authorizations corresponding to the specified application.
/// </returns>
Task<ImmutableArray<object>> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>

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

@ -125,6 +125,17 @@ namespace OpenIddict.Abstractions
[NotNull] string status, [NotNull] string type,
ImmutableArray<string> scopes, CancellationToken cancellationToken);
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the authorizations.</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 authorizations corresponding to the specified application.
/// </returns>
Task<ImmutableArray<TAuthorization>> FindByApplicationIdAsync([NotNull] string identifier, CancellationToken cancellationToken);
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>

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

@ -446,6 +446,26 @@ namespace OpenIddict.Core
builder.ToImmutable();
}
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the authorizations.</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 authorizations corresponding to the specified application.
/// </returns>
public virtual Task<ImmutableArray<TAuthorization>> FindByApplicationIdAsync(
[NotNull] string identifier, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Store.FindByApplicationIdAsync(identifier, cancellationToken);
}
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>
@ -1082,6 +1102,9 @@ namespace OpenIddict.Core
async Task<ImmutableArray<object>> IOpenIddictAuthorizationManager.FindAsync(string subject, string client, string status, string type, ImmutableArray<string> scopes, CancellationToken cancellationToken)
=> (await FindAsync(subject, client, status, type, scopes, cancellationToken)).CastArray<object>();
async Task<ImmutableArray<object>> IOpenIddictAuthorizationManager.FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
=> (await FindByApplicationIdAsync(identifier, cancellationToken)).CastArray<object>();
async Task<object> IOpenIddictAuthorizationManager.FindByIdAsync(string identifier, CancellationToken cancellationToken)
=> await FindByIdAsync(identifier, cancellationToken);

2
src/OpenIddict.EntityFramework.Models/OpenIddictApplication.cs

@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace OpenIddict.EntityFramework.Models
{
@ -24,6 +25,7 @@ namespace OpenIddict.EntityFramework.Models
/// <summary>
/// Represents an OpenIddict application.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; ClientId = {ClientId,nq} ; Type = {Type,nq}")]
public class OpenIddictApplication<TKey, TAuthorization, TToken> where TKey : IEquatable<TKey>
{
/// <summary>

2
src/OpenIddict.EntityFramework.Models/OpenIddictAuthorization.cs

@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace OpenIddict.EntityFramework.Models
{
@ -24,6 +25,7 @@ namespace OpenIddict.EntityFramework.Models
/// <summary>
/// Represents an OpenIddict authorization.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictAuthorization<TKey, TApplication, TToken> where TKey : IEquatable<TKey>
{
/// <summary>

2
src/OpenIddict.EntityFramework.Models/OpenIddictScope.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
namespace OpenIddict.EntityFramework.Models
{
@ -23,6 +24,7 @@ namespace OpenIddict.EntityFramework.Models
/// <summary>
/// Represents an OpenIddict scope.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Name = {Name,nq}")]
public class OpenIddictScope<TKey> where TKey : IEquatable<TKey>
{
/// <summary>

2
src/OpenIddict.EntityFramework.Models/OpenIddictToken.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
namespace OpenIddict.EntityFramework.Models
{
@ -23,6 +24,7 @@ namespace OpenIddict.EntityFramework.Models
/// <summary>
/// Represents an OpenIddict token.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictToken<TKey, TApplication, TAuthorization> where TKey : IEquatable<TKey>
{
/// <summary>

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

@ -378,6 +378,31 @@ namespace OpenIddict.EntityFramework
builder.ToImmutable();
}
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the authorizations.</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 authorizations corresponding to the specified application.
/// </returns>
public virtual async Task<ImmutableArray<TAuthorization>> FindByApplicationIdAsync(
[NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
var key = ConvertIdentifierFromString(identifier);
return ImmutableArray.CreateRange(
await (from authorization in Authorizations.Include(authorization => authorization.Application)
where authorization.Application.Id.Equals(key)
select authorization).ToListAsync(cancellationToken));
}
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>

2
src/OpenIddict.EntityFrameworkCore.Models/OpenIddictApplication.cs

@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace OpenIddict.EntityFrameworkCore.Models
{
@ -31,6 +32,7 @@ namespace OpenIddict.EntityFrameworkCore.Models
/// <summary>
/// Represents an OpenIddict application.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; ClientId = {ClientId,nq} ; Type = {Type,nq}")]
public class OpenIddictApplication<TKey, TAuthorization, TToken> where TKey : IEquatable<TKey>
{
/// <summary>

2
src/OpenIddict.EntityFrameworkCore.Models/OpenIddictAuthorization.cs

@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace OpenIddict.EntityFrameworkCore.Models
{
@ -31,6 +32,7 @@ namespace OpenIddict.EntityFrameworkCore.Models
/// <summary>
/// Represents an OpenIddict authorization.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictAuthorization<TKey, TApplication, TToken> where TKey : IEquatable<TKey>
{
/// <summary>

2
src/OpenIddict.EntityFrameworkCore.Models/OpenIddictScope.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
namespace OpenIddict.EntityFrameworkCore.Models
{
@ -23,6 +24,7 @@ namespace OpenIddict.EntityFrameworkCore.Models
/// <summary>
/// Represents an OpenIddict scope.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Name = {Name,nq}")]
public class OpenIddictScope<TKey> where TKey : IEquatable<TKey>
{
/// <summary>

2
src/OpenIddict.EntityFrameworkCore.Models/OpenIddictToken.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
namespace OpenIddict.EntityFrameworkCore.Models
{
@ -31,6 +32,7 @@ namespace OpenIddict.EntityFrameworkCore.Models
/// <summary>
/// Represents an OpenIddict token.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictToken<TKey, TApplication, TAuthorization> where TKey : IEquatable<TKey>
{
/// <summary>

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

@ -449,6 +449,44 @@ namespace OpenIddict.EntityFrameworkCore
builder.ToImmutable();
}
/// <summary>
/// Exposes a compiled query allowing to retrieve the list of
/// authorizations corresponding to the specified application identifier.
/// </summary>
private static readonly Func<TContext, TKey, AsyncEnumerable<TAuthorization>> FindByApplicationId =
// Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be
// filtered using authorization.Application.Id.Equals(key). To work around this issue,
// this compiled query uses an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
EF.CompileAsyncQuery((TContext context, TKey identifier) =>
from authorization in context.Set<TAuthorization>()
.Include(authorization => authorization.Application)
.AsTracking()
join application in context.Set<TApplication>().AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(identifier)
select authorization);
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the authorizations.</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 authorizations corresponding to the specified application.
/// </returns>
public virtual async Task<ImmutableArray<TAuthorization>> FindByApplicationIdAsync(
[NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return ImmutableArray.CreateRange(await FindByApplicationId(Context,
ConvertIdentifierFromString(identifier)).ToListAsync(cancellationToken));
}
/// <summary>
/// Exposes a compiled query allowing to retrieve an authorization using its unique identifier.
/// </summary>

2
src/OpenIddict.MongoDb.Models/OpenIddictApplication.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
@ -13,6 +14,7 @@ namespace OpenIddict.MongoDb.Models
/// <summary>
/// Represents an OpenIddict application.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; ClientId = {ClientId,nq} ; Type = {Type,nq}")]
public class OpenIddictApplication
{
/// <summary>

2
src/OpenIddict.MongoDb.Models/OpenIddictAuthorization.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
@ -13,6 +14,7 @@ namespace OpenIddict.MongoDb.Models
/// <summary>
/// Represents an OpenIddict authorization.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictAuthorization
{
/// <summary>

2
src/OpenIddict.MongoDb.Models/OpenIddictScope.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
@ -13,6 +14,7 @@ namespace OpenIddict.MongoDb.Models
/// <summary>
/// Represents an OpenIddict scope.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Name = {Name,nq}")]
public class OpenIddictScope
{
/// <summary>

2
src/OpenIddict.MongoDb.Models/OpenIddictToken.cs

@ -5,6 +5,7 @@
*/
using System;
using System.Diagnostics;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
@ -13,6 +14,7 @@ namespace OpenIddict.MongoDb.Models
/// <summary>
/// Represents an OpenIddict token.
/// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictToken
{
/// <summary>

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

@ -314,6 +314,30 @@ namespace OpenIddict.MongoDb
Enumerable.All(scopes, scope => authorization.Scopes.Contains(scope))).ToListAsync(cancellationToken));
}
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
/// </summary>
/// <param name="identifier">The application identifier associated with the authorizations.</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 authorizations corresponding to the specified application.
/// </returns>
public virtual async Task<ImmutableArray<TAuthorization>> FindByApplicationIdAsync(
[NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TAuthorization>(Options.CurrentValue.AuthorizationsCollectionName);
return ImmutableArray.CreateRange(await collection.Find(authorization =>
authorization.ApplicationId == ObjectId.Parse(identifier)).ToListAsync(cancellationToken));
}
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>

Loading…
Cancel
Save