Browse Source

Introduce new managers/stores methods allowing to list invalid authorizations/tokens

pull/490/head
Kévin Chalet 9 years ago
parent
commit
356508005a
  1. 16
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  2. 16
      src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
  3. 13
      src/OpenIddict.Core/Stores/IOpenIddictAuthorizationStore.cs
  4. 13
      src/OpenIddict.Core/Stores/IOpenIddictTokenStore.cs
  5. 38
      src/OpenIddict.Core/Stores/OpenIddictAuthorizationStore.cs
  6. 37
      src/OpenIddict.Core/Stores/OpenIddictTokenStore.cs

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

@ -338,6 +338,22 @@ namespace OpenIddict.Core
return Store.ListAsync(query, cancellationToken);
}
/// <summary>
/// Lists the ad-hoc authorizations that are marked as invalid or have no
/// valid token attached and that can be safely removed from the database.
/// </summary>
/// <param name="count">The number of results to return.</param>
/// <param name="offset">The number of results to skip.</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 elements returned when executing the specified query.
/// </returns>
public virtual Task<ImmutableArray<TAuthorization>> ListInvalidAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken)
{
return Store.ListInvalidAsync(count, offset, cancellationToken);
}
/// <summary>
/// Revokes an authorization.
/// </summary>

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

@ -490,6 +490,22 @@ namespace OpenIddict.Core
return Store.ListAsync(query, cancellationToken);
}
/// <summary>
/// Lists the tokens that are marked as expired or invalid
/// and that can be safely removed from the database.
/// </summary>
/// <param name="count">The number of results to return.</param>
/// <param name="offset">The number of results to skip.</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 elements returned when executing the specified query.
/// </returns>
public virtual Task<ImmutableArray<TToken>> ListInvalidAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken)
{
return Store.ListInvalidAsync(count, offset, cancellationToken);
}
/// <summary>
/// Redeems a token.
/// </summary>

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

@ -174,6 +174,19 @@ namespace OpenIddict.Core
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Lists the ad-hoc authorizations that are marked as invalid or have no
/// valid token attached and that can be safely removed from the database.
/// </summary>
/// <param name="count">The number of results to return.</param>
/// <param name="offset">The number of results to skip.</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 elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TAuthorization>> ListInvalidAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken);
/// <summary>
/// Sets the status associated with an authorization.
/// </summary>

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

@ -248,6 +248,19 @@ namespace OpenIddict.Core
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Lists the tokens that are marked as expired or invalid
/// and that can be safely removed from the database.
/// </summary>
/// <param name="count">The number of results to return.</param>
/// <param name="offset">The number of results to skip.</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 elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TToken>> ListInvalidAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken);
/// <summary>
/// Sets the authorization associated with a token.
/// </summary>

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

@ -263,6 +263,44 @@ namespace OpenIddict.Core
/// </returns>
public abstract Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Lists the ad-hoc authorizations that are marked as invalid or have no
/// valid token attached and that can be safely removed from the database.
/// </summary>
/// <param name="count">The number of results to return.</param>
/// <param name="offset">The number of results to skip.</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 elements returned when executing the specified query.
/// </returns>
public virtual Task<ImmutableArray<TAuthorization>> ListInvalidAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken)
{
IQueryable<TAuthorization> Query(IQueryable<TAuthorization> authorizations)
{
var query = (from authorization in authorizations
where authorization.Status != OpenIddictConstants.Statuses.Valid ||
(authorization.Type == OpenIddictConstants.AuthorizationTypes.AdHoc &&
!authorization.Tokens.Any(token => token.Status == OpenIddictConstants.Statuses.Valid))
orderby authorization.Id
select authorization).AsQueryable();
if (offset.HasValue)
{
query = query.Skip(offset.Value);
}
if (count.HasValue)
{
query = query.Take(count.Value);
}
return query;
}
return ListAsync(Query, cancellationToken);
}
/// <summary>
/// Sets the status associated with an authorization.
/// </summary>

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

@ -399,6 +399,43 @@ namespace OpenIddict.Core
/// </returns>
public abstract Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken);
/// <summary>
/// Lists the tokens that are marked as expired or invalid
/// and that can be safely removed from the database.
/// </summary>
/// <param name="count">The number of results to return.</param>
/// <param name="offset">The number of results to skip.</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 elements returned when executing the specified query.
/// </returns>
public virtual Task<ImmutableArray<TToken>> ListInvalidAsync([CanBeNull] int? count, [CanBeNull] int? offset, CancellationToken cancellationToken)
{
IQueryable<TToken> Query(IQueryable<TToken> tokens)
{
var query = (from token in tokens
where token.ExpirationDate < DateTimeOffset.UtcNow ||
token.Status != OpenIddictConstants.Statuses.Valid
orderby token.Id
select token).AsQueryable();
if (offset.HasValue)
{
query = query.Skip(offset.Value);
}
if (count.HasValue)
{
query = query.Take(count.Value);
}
return query;
}
return ListAsync(Query, cancellationToken);
}
/// <summary>
/// Sets the authorization associated with a token.
/// </summary>

Loading…
Cancel
Save