Browse Source

Backport the managers/stores/models changes to OpenIddict 1.x

pull/670/head
Kévin Chalet 8 years ago
parent
commit
24961dd0f9
  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. 101
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  14. 115
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
  15. 2
      src/OpenIddict.MongoDb.Models/OpenIddictApplication.cs
  16. 2
      src/OpenIddict.MongoDb.Models/OpenIddictAuthorization.cs
  17. 2
      src/OpenIddict.MongoDb.Models/OpenIddictScope.cs
  18. 2
      src/OpenIddict.MongoDb.Models/OpenIddictToken.cs
  19. 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>

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

@ -277,16 +277,14 @@ namespace OpenIddict.EntityFrameworkCore
// this method is overriden to use an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
IQueryable<TAuthorization> Query(IQueryable<TAuthorization> authorizations,
IQueryable<TApplication> applications, TKey key, string principal)
=> from authorization in authorizations.Include(authorization => authorization.Application).AsTracking()
where authorization.Subject == principal
join application in applications.AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(key)
select authorization;
return ImmutableArray.CreateRange(await Query(
Authorizations, Applications, ConvertIdentifierFromString(client), subject).ToListAsync(cancellationToken));
var key = ConvertIdentifierFromString(client);
return ImmutableArray.CreateRange(
await (from authorization in Authorizations.Include(authorization => authorization.Application).AsTracking()
where authorization.Subject == subject
join application in Applications.AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(key)
select authorization).ToListAsync(cancellationToken));
}
/// <summary>
@ -324,16 +322,14 @@ namespace OpenIddict.EntityFrameworkCore
// this method is overriden to use an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
IQueryable<TAuthorization> Query(IQueryable<TAuthorization> authorizations,
IQueryable<TApplication> applications, TKey key, string principal, string state)
=> from authorization in authorizations.Include(authorization => authorization.Application).AsTracking()
where authorization.Subject == principal && authorization.Status == state
join application in applications.AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(key)
select authorization;
var key = ConvertIdentifierFromString(client);
return ImmutableArray.CreateRange(await Query(
Authorizations, Applications, ConvertIdentifierFromString(client), subject, status).ToListAsync(cancellationToken));
return ImmutableArray.CreateRange(
await (from authorization in Authorizations.Include(authorization => authorization.Application).AsTracking()
where authorization.Subject == subject && authorization.Status == status
join application in Applications.AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(key)
select authorization).ToListAsync(cancellationToken));
}
/// <summary>
@ -377,18 +373,16 @@ namespace OpenIddict.EntityFrameworkCore
// this method is overriden to use an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
IQueryable<TAuthorization> Query(IQueryable<TAuthorization> authorizations,
IQueryable<TApplication> applications, TKey key, string principal, string state, string kind)
=> from authorization in authorizations.Include(authorization => authorization.Application).AsTracking()
where authorization.Subject == principal &&
authorization.Status == state &&
authorization.Type == kind
join application in applications.AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(key)
select authorization;
return ImmutableArray.CreateRange(await Query(
Authorizations, Applications, ConvertIdentifierFromString(client), subject, status, type).ToListAsync(cancellationToken));
var key = ConvertIdentifierFromString(client);
return ImmutableArray.CreateRange(
await (from authorization in Authorizations.Include(authorization => authorization.Application).AsTracking()
where authorization.Subject == subject &&
authorization.Status == status &&
authorization.Type == type
join application in Applications.AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(key)
select authorization).ToListAsync(cancellationToken));
}
/// <summary>
@ -435,6 +429,37 @@ namespace OpenIddict.EntityFrameworkCore
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));
}
// 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 method is overriden to use an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
var key = ConvertIdentifierFromString(identifier);
return ImmutableArray.CreateRange(
await (from authorization in Authorizations.Include(authorization => authorization.Application).AsTracking()
join application in Applications.AsTracking() on authorization.Application.Id equals application.Id
where application.Id.Equals(identifier)
select authorization).ToListAsync(cancellationToken));
}
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>
@ -504,14 +529,12 @@ namespace OpenIddict.EntityFrameworkCore
async Task<string> RetrieveApplicationIdAsync()
{
IQueryable<TKey> Query(IQueryable<TAuthorization> authorizations, TKey key)
=> from element in authorizations.AsTracking()
where element.Id.Equals(key) &&
element.Application != null
select element.Application.Id;
return ConvertIdentifierToString(await GetAsync(
(authorizations, key) => Query(authorizations, key), authorization.Id, cancellationToken));
var key = await (from element in Authorizations.AsTracking()
where element.Id.Equals(authorization.Id) &&
element.Application != null
select element.Application.Id).FirstOrDefaultAsync(cancellationToken);
return ConvertIdentifierToString(key);
}
return new ValueTask<string>(RetrieveApplicationIdAsync());

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

@ -225,15 +225,19 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentException("The client cannot be null or empty.", nameof(client));
}
IQueryable<TToken> Query(IQueryable<TApplication> applications, IQueryable<TToken> tokens, TKey key, string principal)
=> from token in tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
where token.Subject == subject
join application in applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token;
return ImmutableArray.CreateRange(await Query(Applications, Tokens,
ConvertIdentifierFromString(client), subject).ToListAsync(cancellationToken));
// Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be
// filtered using token.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.
var key = ConvertIdentifierFromString(client);
return ImmutableArray.CreateRange(
await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
where token.Subject == subject
join application in Applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token).ToListAsync(cancellationToken));
}
/// <summary>
@ -266,17 +270,20 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentException("The status cannot be null or empty.", nameof(status));
}
IQueryable<TToken> Query(IQueryable<TApplication> applications,
IQueryable<TToken> tokens, TKey key, string principal, string state)
=> from token in tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
where token.Subject == subject &&
token.Status == status
join application in applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token;
// Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be
// filtered using token.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.
var key = ConvertIdentifierFromString(client);
return ImmutableArray.CreateRange(await Query(Applications, Tokens,
ConvertIdentifierFromString(client), subject, status).ToListAsync(cancellationToken));
return ImmutableArray.CreateRange(
await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
where token.Subject == subject &&
token.Status == status
join application in Applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token).ToListAsync(cancellationToken));
}
/// <summary>
@ -320,18 +327,16 @@ namespace OpenIddict.EntityFrameworkCore
// this compiled query uses an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
IQueryable<TToken> Query(IQueryable<TApplication> applications,
IQueryable<TToken> tokens, TKey key, string principal, string state, string kind)
=> from token in tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
where token.Subject == subject &&
token.Status == status &&
token.Type == type
join application in applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token;
return ImmutableArray.CreateRange(await Query(Applications, Tokens,
ConvertIdentifierFromString(client), subject, status, type).ToListAsync(cancellationToken));
var key = ConvertIdentifierFromString(client);
return ImmutableArray.CreateRange(
await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
where token.Subject == subject &&
token.Status == status &&
token.Type == type
join application in Applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token).ToListAsync(cancellationToken));
}
/// <summary>
@ -355,14 +360,13 @@ namespace OpenIddict.EntityFrameworkCore
// this method is overriden to use an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
IQueryable<TToken> Query(IQueryable<TApplication> applications, IQueryable<TToken> tokens, TKey key)
=> from token in tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
join application in applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token;
var key = ConvertIdentifierFromString(identifier);
return ImmutableArray.CreateRange(await Query(
Applications, Tokens, ConvertIdentifierFromString(identifier)).ToListAsync(cancellationToken));
return ImmutableArray.CreateRange(
await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
join application in Applications.AsTracking() on token.Application.Id equals application.Id
where application.Id.Equals(key)
select token).ToListAsync(cancellationToken));
}
/// <summary>
@ -386,14 +390,13 @@ namespace OpenIddict.EntityFrameworkCore
// this method is overriden to use an explicit join before applying the equality check.
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
IQueryable<TToken> Query(IQueryable<TAuthorization> authorizations, IQueryable<TToken> tokens, TKey key)
=> from token in tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
join authorization in authorizations.AsTracking() on token.Authorization.Id equals authorization.Id
where authorization.Id.Equals(key)
select token;
var key = ConvertIdentifierFromString(identifier);
return ImmutableArray.CreateRange(await Query(
Authorizations, Tokens, ConvertIdentifierFromString(identifier)).ToListAsync(cancellationToken));
return ImmutableArray.CreateRange(
await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking()
join authorization in Authorizations.AsTracking() on token.Authorization.Id equals authorization.Id
where authorization.Id.Equals(key)
select token).ToListAsync(cancellationToken));
}
/// <summary>
@ -486,13 +489,12 @@ namespace OpenIddict.EntityFrameworkCore
async Task<string> RetrieveApplicationIdAsync()
{
IQueryable<TKey> Query(IQueryable<TToken> tokens, TKey key)
=> from element in tokens.AsTracking()
where element.Id.Equals(key) &&
element.Application != null
select element.Application.Id;
var key = await (from element in Tokens.AsTracking()
where element.Id.Equals(token.Id) &&
element.Application != null
select element.Application.Id).FirstOrDefaultAsync(cancellationToken);
return ConvertIdentifierToString(await GetAsync((tokens, key) => Query(tokens, key), token.Id, cancellationToken));
return ConvertIdentifierToString(key);
}
return new ValueTask<string>(RetrieveApplicationIdAsync());
@ -548,13 +550,12 @@ namespace OpenIddict.EntityFrameworkCore
async Task<string> RetrieveAuthorizationIdAsync()
{
IQueryable<TKey> Query(IQueryable<TToken> tokens, TKey key)
=> from element in tokens.AsTracking()
where element.Id.Equals(key) &&
element.Authorization != null
select element.Authorization.Id;
var key = await (from element in Tokens.AsTracking()
where element.Id.Equals(token.Id) &&
element.Authorization != null
select element.Authorization.Id).FirstOrDefaultAsync(cancellationToken);
return ConvertIdentifierToString(await GetAsync((tokens, key) => Query(tokens, key), token.Id, cancellationToken));
return ConvertIdentifierToString(key);
}
return new ValueTask<string>(RetrieveAuthorizationIdAsync());

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.Value.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