|
|
|
@ -16,7 +16,6 @@ using System.Threading.Tasks; |
|
|
|
using JetBrains.Annotations; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
|
|
|
using Microsoft.EntityFrameworkCore.Query; |
|
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
@ -202,25 +201,6 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exposes a compiled query allowing to retrieve the tokens corresponding
|
|
|
|
/// to the specified subject and associated with the application identifier.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, TKey, string, AsyncEnumerable<TToken>> FindBySubjectAndClient = |
|
|
|
// 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.
|
|
|
|
EF.CompileAsyncQuery((TContext context, TKey identifier, string subject) => |
|
|
|
from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
where token.Subject == subject |
|
|
|
join application in context.Set<TApplication>().AsTracking() on token.Application.Id equals application.Id |
|
|
|
where application.Id.Equals(identifier) |
|
|
|
select token); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the tokens corresponding to the specified
|
|
|
|
/// subject and associated with the application identifier.
|
|
|
|
@ -245,27 +225,20 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
throw new ArgumentException("The client cannot be null or empty.", nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
return ImmutableArray.CreateRange(await FindBySubjectAndClient(Context, |
|
|
|
ConvertIdentifierFromString(client), subject).ToListAsync(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exposes a compiled query allowing to retrieve the tokens matching the specified parameters.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, TKey, string, string, AsyncEnumerable<TToken>> FindBySubjectClientAndStatus = |
|
|
|
// 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.
|
|
|
|
EF.CompileAsyncQuery((TContext context, TKey identifier, string subject, string status) => |
|
|
|
from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
where token.Subject == subject && token.Status == status |
|
|
|
join application in context.Set<TApplication>().AsTracking() on token.Application.Id equals application.Id |
|
|
|
where application.Id.Equals(identifier) |
|
|
|
select token); |
|
|
|
|
|
|
|
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>
|
|
|
|
/// Retrieves the tokens matching the specified parameters.
|
|
|
|
@ -297,29 +270,21 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
throw new ArgumentException("The status cannot be null or empty.", nameof(status)); |
|
|
|
} |
|
|
|
|
|
|
|
return ImmutableArray.CreateRange(await FindBySubjectClientAndStatus(Context, |
|
|
|
ConvertIdentifierFromString(client), subject, status).ToListAsync(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exposes a compiled query allowing to retrieve the tokens matching the specified parameters.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, TKey, string, string, string, AsyncEnumerable<TToken>> FindBySubjectClientStatusAndType = |
|
|
|
// 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.
|
|
|
|
EF.CompileAsyncQuery((TContext context, TKey identifier, string subject, string status, string type) => |
|
|
|
from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
where token.Subject == subject && |
|
|
|
token.Status == status && |
|
|
|
token.Type == type |
|
|
|
join application in context.Set<TApplication>().AsTracking() on token.Application.Id equals application.Id |
|
|
|
where application.Id.Equals(identifier) |
|
|
|
select token); |
|
|
|
|
|
|
|
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 |
|
|
|
join application in Applications.AsTracking() on token.Application.Id equals application.Id |
|
|
|
where application.Id.Equals(key) |
|
|
|
select token).ToListAsync(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the tokens matching the specified parameters.
|
|
|
|
@ -357,27 +322,22 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
throw new ArgumentException("The type cannot be null or empty.", nameof(type)); |
|
|
|
} |
|
|
|
|
|
|
|
return ImmutableArray.CreateRange(await FindBySubjectClientStatusAndType(Context, |
|
|
|
ConvertIdentifierFromString(client), subject, status, type).ToListAsync(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exposes a compiled query allowing to retrieve the list of
|
|
|
|
/// tokens corresponding to the specified application identifier.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, TKey, AsyncEnumerable<TToken>> FindByApplicationId = |
|
|
|
// Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be
|
|
|
|
// 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.
|
|
|
|
EF.CompileAsyncQuery((TContext context, TKey identifier) => |
|
|
|
from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
join application in context.Set<TApplication>().AsTracking() on token.Application.Id equals application.Id |
|
|
|
where application.Id.Equals(identifier) |
|
|
|
select token); |
|
|
|
|
|
|
|
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>
|
|
|
|
/// Retrieves the list of tokens corresponding to the specified application identifier.
|
|
|
|
@ -395,27 +355,19 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
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 the list of
|
|
|
|
/// tokens corresponding to the specified authorization identifier.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, TKey, AsyncEnumerable<TToken>> FindByAuthorizationId = |
|
|
|
// Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be
|
|
|
|
// filtered using token.Authorization.Id.Equals(key). To work around this issue,
|
|
|
|
// this compiled query uses an explicit join before applying the equality check.
|
|
|
|
// filtered using token.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.
|
|
|
|
EF.CompileAsyncQuery((TContext context, TKey identifier) => |
|
|
|
from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
join authorization in context.Set<TAuthorization>().AsTracking() on token.Authorization.Id equals authorization.Id |
|
|
|
where authorization.Id.Equals(identifier) |
|
|
|
select token); |
|
|
|
|
|
|
|
var key = ConvertIdentifierFromString(identifier); |
|
|
|
|
|
|
|
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>
|
|
|
|
/// Retrieves the list of tokens corresponding to the specified authorization identifier.
|
|
|
|
@ -433,21 +385,19 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); |
|
|
|
} |
|
|
|
|
|
|
|
return ImmutableArray.CreateRange(await FindByAuthorizationId(Context, |
|
|
|
ConvertIdentifierFromString(identifier)).ToListAsync(cancellationToken)); |
|
|
|
} |
|
|
|
// Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be
|
|
|
|
// filtered using token.Authorization.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.
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exposes a compiled query allowing to retrieve a token using its unique identifier.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, TKey, Task<TToken>> FindById = |
|
|
|
EF.CompileAsyncQuery((TContext context, TKey identifier) => |
|
|
|
(from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
where token.Id.Equals(identifier) |
|
|
|
select token).FirstOrDefault()); |
|
|
|
var key = ConvertIdentifierFromString(identifier); |
|
|
|
|
|
|
|
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>
|
|
|
|
/// Retrieves a token using its unique identifier.
|
|
|
|
@ -465,21 +415,12 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); |
|
|
|
} |
|
|
|
|
|
|
|
return FindById(Context, ConvertIdentifierFromString(identifier)); |
|
|
|
} |
|
|
|
var key = ConvertIdentifierFromString(identifier); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exposes a compiled query allowing to retrieve the list of
|
|
|
|
/// tokens corresponding to the specified reference identifier.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, string, Task<TToken>> FindByReferenceId = |
|
|
|
EF.CompileAsyncQuery((TContext context, string identifier) => |
|
|
|
(from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
where token.ReferenceId == identifier |
|
|
|
select token).FirstOrDefault()); |
|
|
|
return (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking() |
|
|
|
where token.Id.Equals(key) |
|
|
|
select token).FirstOrDefaultAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the list of tokens corresponding to the specified reference identifier.
|
|
|
|
@ -498,22 +439,11 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); |
|
|
|
} |
|
|
|
|
|
|
|
return FindByReferenceId(Context, identifier); |
|
|
|
return (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking() |
|
|
|
where token.ReferenceId == identifier |
|
|
|
select token).FirstOrDefaultAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exposes a compiled query allowing to retrieve the
|
|
|
|
/// list of tokens corresponding to the specified subject.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly Func<TContext, string, AsyncEnumerable<TToken>> FindBySubject = |
|
|
|
EF.CompileAsyncQuery((TContext context, string subject) => |
|
|
|
from token in context.Set<TToken>() |
|
|
|
.Include(token => token.Application) |
|
|
|
.Include(token => token.Authorization) |
|
|
|
.AsTracking() |
|
|
|
where token.Subject == subject |
|
|
|
select token); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the list of tokens corresponding to the specified subject.
|
|
|
|
/// </summary>
|
|
|
|
@ -530,7 +460,10 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
|
throw new ArgumentException("The subject cannot be null or empty.", nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
return ImmutableArray.CreateRange(await FindBySubject(Context, subject).ToListAsync(cancellationToken)); |
|
|
|
return ImmutableArray.CreateRange( |
|
|
|
await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization).AsTracking() |
|
|
|
where token.Subject == subject |
|
|
|
select token).ToListAsync(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|