Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,11 @@ IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
ValueTask PopulateAsync(object authorization, OpenIddictAuthorizationDescriptor descriptor, CancellationToken cancellationToken = default);

/// <summary>
/// Removes the authorizations that are marked as invalid and the ad-hoc ones that have no token attached.
/// Removes the authorizations that are marked as invalid and don't have any token attached.
/// Only authorizations created before the specified <paramref name="threshold"/> are removed.
/// </summary>
/// <remarks>
/// To ensure ad-hoc authorizations that no longer have any valid/non-expired token
/// attached are correctly removed, the tokens should always be pruned first.
/// Since authorizations with tokens still attached are not deleted, tokens should always be pruned first.
/// </remarks>
/// <param name="threshold">The date before which authorizations are not pruned.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,11 @@ IAsyncEnumerable<TResult> ListAsync<TState, TResult>(
TState state, CancellationToken cancellationToken);

/// <summary>
/// Removes the authorizations that are marked as invalid and the ad-hoc ones that have no token attached.
/// Removes the authorizations that are marked as invalid and don't have any token attached.
/// Only authorizations created before the specified <paramref name="threshold"/> are removed.
/// </summary>
/// <remarks>
/// To ensure ad-hoc authorizations that no longer have any valid/non-expired token
/// attached are correctly removed, the tokens should always be pruned first.
/// Since authorizations with tokens still attached are not deleted, tokens should always be pruned first.
/// </remarks>
/// <param name="threshold">The date before which authorizations are not pruned.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ public virtual async ValueTask<long> PruneAsync(DateTimeOffset threshold, Cancel
var authorizations =
await (from authorization in Authorizations.Include(authorization => authorization.Tokens)
where authorization.CreationDate < date
where authorization.Status != Statuses.Valid ||
(authorization.Type == AuthorizationTypes.AdHoc && !authorization.Tokens.Any())
where authorization.Status != Statuses.Valid || authorization.Type == AuthorizationTypes.AdHoc
where !authorization.Tokens.Any()
orderby authorization.Id
select authorization).Take(1_000).ToListAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ public virtual async ValueTask<long> PruneAsync(DateTimeOffset threshold, Cancel
var count = await
(from authorization in Authorizations
where authorization.CreationDate < date
where authorization.Status != Statuses.Valid ||
(authorization.Type == AuthorizationTypes.AdHoc && !authorization.Tokens.Any())
where authorization.Status != Statuses.Valid || authorization.Type == AuthorizationTypes.AdHoc
where !authorization.Tokens.Any()
orderby authorization.Id
select authorization).Take(1_000).ExecuteDeleteAsync(cancellationToken);

Expand Down Expand Up @@ -643,8 +643,8 @@ orderby authorization.Id
var authorizations = await
(from authorization in Authorizations.Include(authorization => authorization.Tokens).AsTracking()
where authorization.CreationDate < date
where authorization.Status != Statuses.Valid ||
(authorization.Type == AuthorizationTypes.AdHoc && !authorization.Tokens.Any())
where authorization.Status != Statuses.Valid || authorization.Type == AuthorizationTypes.AdHoc
where !authorization.Tokens.Any()
orderby authorization.Id
select authorization).Take(1_000).ToListAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ public virtual async ValueTask<long> PruneAsync(DateTimeOffset threshold, Cancel
join token in database.GetCollection<OpenIddictMongoDbToken>(Options.CurrentValue.TokensCollectionName).AsQueryable()
on authorization.Id equals token.AuthorizationId into tokens
where authorization.CreationDate < threshold.UtcDateTime
where authorization.Status != Statuses.Valid ||
(authorization.Type == AuthorizationTypes.AdHoc && !tokens.Any())
where authorization.Status != Statuses.Valid || authorization.Type == AuthorizationTypes.AdHoc
where !tokens.Any()
select authorization.Id).ToListAsync(cancellationToken);

// Note: to avoid generating delete requests with very large filters, a buffer is used here and the
Expand Down
6 changes: 2 additions & 4 deletions src/OpenIddict.Quartz/OpenIddictQuartzJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ public async Task Execute(IJobExecutionContext context)

try
{
// Note: this background task is responsible for automatically removing orphaned tokens/authorizations
// (i.e tokens that are no longer valid and ad-hoc authorizations that have no valid tokens associated).
// Import: since tokens associated to ad-hoc authorizations are not removed as part of the same operation,
// the tokens MUST be deleted before removing the ad-hoc authorizations that no longer have any token.
// Important: since authorizations that still have tokens attached are never
// pruned, the tokens MUST be deleted before deleting the authorizations.

if (!_options.CurrentValue.DisableTokenPruning)
{
Expand Down