|
|
|
@ -748,6 +748,66 @@ public class OpenIddictEntityFrameworkCoreTokenStore<TToken, TApplication, TAuth |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public virtual async ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(identifier)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(identifier)); |
|
|
|
} |
|
|
|
|
|
|
|
var key = ConvertIdentifierFromString(identifier); |
|
|
|
|
|
|
|
#if SUPPORTS_BULK_DBSET_OPERATIONS
|
|
|
|
if (!Options.CurrentValue.DisableBulkOperations) |
|
|
|
{ |
|
|
|
return await ( |
|
|
|
from token in Tokens |
|
|
|
where token.Application!.Id!.Equals(key) |
|
|
|
select token).ExecuteUpdateAsync(entity => entity.SetProperty( |
|
|
|
token => token.Status, Statuses.Revoked), cancellationToken); |
|
|
|
|
|
|
|
// Note: calling DbContext.SaveChangesAsync() is not necessary
|
|
|
|
// with bulk update operations as they are executed immediately.
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
List<Exception>? exceptions = null; |
|
|
|
|
|
|
|
var result = 0L; |
|
|
|
|
|
|
|
foreach (var token in await (from token in Tokens |
|
|
|
where token.Application!.Id!.Equals(key) |
|
|
|
select token).ToListAsync(cancellationToken)) |
|
|
|
{ |
|
|
|
token.Status = Statuses.Revoked; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
await Context.SaveChangesAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception exception) when (!OpenIddictHelpers.IsFatal(exception)) |
|
|
|
{ |
|
|
|
// Reset the state of the entity to prevents future calls to SaveChangesAsync() from failing.
|
|
|
|
Context.Entry(token).State = EntityState.Unchanged; |
|
|
|
|
|
|
|
exceptions ??= []; |
|
|
|
exceptions.Add(exception); |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
result++; |
|
|
|
} |
|
|
|
|
|
|
|
if (exceptions is not null) |
|
|
|
{ |
|
|
|
throw new AggregateException(SR.GetResourceString(SR.ID0249), exceptions); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public virtual async ValueTask<long> RevokeByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
@ -808,6 +868,64 @@ public class OpenIddictEntityFrameworkCoreTokenStore<TToken, TApplication, TAuth |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public virtual async ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0195), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
#if SUPPORTS_BULK_DBSET_OPERATIONS
|
|
|
|
if (!Options.CurrentValue.DisableBulkOperations) |
|
|
|
{ |
|
|
|
return await ( |
|
|
|
from token in Tokens |
|
|
|
where token.Subject == subject |
|
|
|
select token).ExecuteUpdateAsync(entity => entity.SetProperty( |
|
|
|
token => token.Status, Statuses.Revoked), cancellationToken); |
|
|
|
|
|
|
|
// Note: calling DbContext.SaveChangesAsync() is not necessary
|
|
|
|
// with bulk update operations as they are executed immediately.
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
List<Exception>? exceptions = null; |
|
|
|
|
|
|
|
var result = 0L; |
|
|
|
|
|
|
|
foreach (var token in await (from token in Tokens |
|
|
|
where token.Subject == subject |
|
|
|
select token).ToListAsync(cancellationToken)) |
|
|
|
{ |
|
|
|
token.Status = Statuses.Revoked; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
await Context.SaveChangesAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception exception) when (!OpenIddictHelpers.IsFatal(exception)) |
|
|
|
{ |
|
|
|
// Reset the state of the entity to prevents future calls to SaveChangesAsync() from failing.
|
|
|
|
Context.Entry(token).State = EntityState.Unchanged; |
|
|
|
|
|
|
|
exceptions ??= []; |
|
|
|
exceptions.Add(exception); |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
result++; |
|
|
|
} |
|
|
|
|
|
|
|
if (exceptions is not null) |
|
|
|
{ |
|
|
|
throw new AggregateException(SR.GetResourceString(SR.ID0249), exceptions); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public virtual async ValueTask SetApplicationIdAsync(TToken token, string? identifier, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
|