|
|
|
@ -271,207 +271,21 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori |
|
|
|
await Store.DeleteAsync(authorization, cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the authorizations corresponding to the specified
|
|
|
|
/// subject and associated with the application identifier.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="subject">The subject associated with the authorization.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization.</param>
|
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
|
|
|
|
/// <returns>The authorizations corresponding to the subject/client.</returns>
|
|
|
|
public virtual IAsyncEnumerable<TAuthorization> FindAsync( |
|
|
|
string subject, string client, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(client)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
var authorizations = Options.CurrentValue.DisableEntityCaching ? |
|
|
|
Store.FindAsync(subject, client, cancellationToken) : |
|
|
|
Cache.FindAsync(subject, client, cancellationToken); |
|
|
|
|
|
|
|
// SQL engines like Microsoft SQL Server or MySQL are known to use case-insensitive lookups by default.
|
|
|
|
// To ensure a case-sensitive comparison is enforced independently of the database/table/query collation
|
|
|
|
// used by the store, a second pass using string.Equals(StringComparison.Ordinal) is manually made here.
|
|
|
|
|
|
|
|
if (Options.CurrentValue.DisableAdditionalFiltering) |
|
|
|
{ |
|
|
|
return authorizations; |
|
|
|
} |
|
|
|
|
|
|
|
// SQL engines like Microsoft SQL Server or MySQL are known to use case-insensitive lookups by default.
|
|
|
|
// To ensure a case-sensitive comparison is enforced independently of the database/table/query collation
|
|
|
|
// used by the store, a second pass using string.Equals(StringComparison.Ordinal) is manually made here.
|
|
|
|
|
|
|
|
return ExecuteAsync(cancellationToken); |
|
|
|
|
|
|
|
async IAsyncEnumerable<TAuthorization> ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
await foreach (var authorization in authorizations) |
|
|
|
{ |
|
|
|
if (string.Equals(await Store.GetSubjectAsync(authorization, cancellationToken), subject, StringComparison.Ordinal)) |
|
|
|
{ |
|
|
|
yield return authorization; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the authorizations matching the specified parameters.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="subject">The subject associated with the authorization.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization.</param>
|
|
|
|
/// <param name="status">The authorization status.</param>
|
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
|
|
|
|
/// <returns>The authorizations corresponding to the criteria.</returns>
|
|
|
|
public virtual IAsyncEnumerable<TAuthorization> FindAsync( |
|
|
|
string subject, string client, |
|
|
|
string status, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(client)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(status)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status)); |
|
|
|
} |
|
|
|
|
|
|
|
var authorizations = Options.CurrentValue.DisableEntityCaching ? |
|
|
|
Store.FindAsync(subject, client, status, cancellationToken) : |
|
|
|
Cache.FindAsync(subject, client, status, cancellationToken); |
|
|
|
|
|
|
|
if (Options.CurrentValue.DisableAdditionalFiltering) |
|
|
|
{ |
|
|
|
return authorizations; |
|
|
|
} |
|
|
|
|
|
|
|
// SQL engines like Microsoft SQL Server or MySQL are known to use case-insensitive lookups by default.
|
|
|
|
// To ensure a case-sensitive comparison is enforced independently of the database/table/query collation
|
|
|
|
// used by the store, a second pass using string.Equals(StringComparison.Ordinal) is manually made here.
|
|
|
|
|
|
|
|
return ExecuteAsync(cancellationToken); |
|
|
|
|
|
|
|
async IAsyncEnumerable<TAuthorization> ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
await foreach (var authorization in authorizations) |
|
|
|
{ |
|
|
|
if (string.Equals(await Store.GetSubjectAsync(authorization, cancellationToken), subject, StringComparison.Ordinal)) |
|
|
|
{ |
|
|
|
yield return authorization; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the authorizations matching the specified parameters.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="subject">The subject associated with the authorization.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization.</param>
|
|
|
|
/// <param name="status">The authorization status.</param>
|
|
|
|
/// <param name="type">The authorization type.</param>
|
|
|
|
/// <param name="subject">The subject associated with the authorization, or <see langword="null"/> not to filter out specific subjects.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization, or <see langword="null"/> not to filter out specific clients.</param>
|
|
|
|
/// <param name="status">The authorization status, or <see langword="null"/> not to filter out specific authorization statuses.</param>
|
|
|
|
/// <param name="type">The authorization type, or <see langword="null"/> not to filter out specific authorization types.</param>
|
|
|
|
/// <param name="scopes">The minimal scopes associated with the authorization, or <see langword="null"/> not to filter out scopes.</param>
|
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
|
|
|
|
/// <returns>The authorizations corresponding to the criteria.</returns>
|
|
|
|
public virtual IAsyncEnumerable<TAuthorization> FindAsync( |
|
|
|
string subject, string client, |
|
|
|
string status, string type, CancellationToken cancellationToken = default) |
|
|
|
string? subject, string? client, |
|
|
|
string? status, string? type, |
|
|
|
ImmutableArray<string>? scopes, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(client)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(status)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(type)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type)); |
|
|
|
} |
|
|
|
|
|
|
|
var authorizations = Options.CurrentValue.DisableEntityCaching ? |
|
|
|
Store.FindAsync(subject, client, status, type, cancellationToken) : |
|
|
|
Cache.FindAsync(subject, client, status, type, cancellationToken); |
|
|
|
|
|
|
|
if (Options.CurrentValue.DisableAdditionalFiltering) |
|
|
|
{ |
|
|
|
return authorizations; |
|
|
|
} |
|
|
|
|
|
|
|
// SQL engines like Microsoft SQL Server or MySQL are known to use case-insensitive lookups by default.
|
|
|
|
// To ensure a case-sensitive comparison is enforced independently of the database/table/query collation
|
|
|
|
// used by the store, a second pass using string.Equals(StringComparison.Ordinal) is manually made here.
|
|
|
|
|
|
|
|
return ExecuteAsync(cancellationToken); |
|
|
|
|
|
|
|
async IAsyncEnumerable<TAuthorization> ExecuteAsync([EnumeratorCancellation] CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
await foreach (var authorization in authorizations) |
|
|
|
{ |
|
|
|
if (string.Equals(await Store.GetSubjectAsync(authorization, cancellationToken), subject, StringComparison.Ordinal)) |
|
|
|
{ |
|
|
|
yield return authorization; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the authorizations matching the specified parameters.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="subject">The subject associated with the authorization.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization.</param>
|
|
|
|
/// <param name="status">The authorization status.</param>
|
|
|
|
/// <param name="type">The authorization type.</param>
|
|
|
|
/// <param name="scopes">The minimal scopes associated with the authorization.</param>
|
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
|
|
|
|
/// <returns>The authorizations corresponding to the criteria.</returns>
|
|
|
|
public virtual IAsyncEnumerable<TAuthorization> FindAsync( |
|
|
|
string subject, string client, |
|
|
|
string status, string type, |
|
|
|
ImmutableArray<string> scopes, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(client)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(status)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(type)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type)); |
|
|
|
} |
|
|
|
|
|
|
|
var authorizations = Options.CurrentValue.DisableEntityCaching ? |
|
|
|
Store.FindAsync(subject, client, status, type, scopes, cancellationToken) : |
|
|
|
Cache.FindAsync(subject, client, status, type, scopes, cancellationToken); |
|
|
|
@ -491,12 +305,13 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori |
|
|
|
{ |
|
|
|
await foreach (var authorization in authorizations) |
|
|
|
{ |
|
|
|
if (!string.Equals(await Store.GetSubjectAsync(authorization, cancellationToken), subject, StringComparison.Ordinal)) |
|
|
|
if (!string.IsNullOrEmpty(subject) && |
|
|
|
!string.Equals(await Store.GetSubjectAsync(authorization, cancellationToken), subject, StringComparison.Ordinal)) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!await HasScopesAsync(authorization, scopes, cancellationToken)) |
|
|
|
if (scopes is not null && !await HasScopesAsync(authorization, scopes.Value, cancellationToken)) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
@ -1028,90 +843,17 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori |
|
|
|
public virtual ValueTask<long> PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken = default) |
|
|
|
=> Store.PruneAsync(threshold, cancellationToken); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Revokes all the authorizations corresponding to the specified
|
|
|
|
/// subject and associated with the application identifier.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="subject">The subject associated with the authorization.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization.</param>
|
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
|
|
|
|
/// <returns>The number of authorizations corresponding to the criteria that were marked as revoked.</returns>
|
|
|
|
public virtual ValueTask<long> RevokeAsync(string subject, string client, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(client)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
return Store.RevokeAsync(subject, client, cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Revokes all the authorizations matching the specified parameters.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="subject">The subject associated with the authorization.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization.</param>
|
|
|
|
/// <param name="status">The authorization status.</param>
|
|
|
|
/// <param name="subject">The subject associated with the authorization, or <see langword="null"/> not to filter out specific subjects.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization, or <see langword="null"/> not to filter out specific clients.</param>
|
|
|
|
/// <param name="status">The authorization status, or <see langword="null"/> not to filter out specific authorization statuses.</param>
|
|
|
|
/// <param name="type">The authorization type, or <see langword="null"/> not to filter out specific authorization types.</param>
|
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
|
|
|
|
/// <returns>The number of authorizations corresponding to the criteria that were marked as revoked.</returns>
|
|
|
|
public virtual ValueTask<long> RevokeAsync(string subject, string client, string status, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(client)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(status)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status)); |
|
|
|
} |
|
|
|
|
|
|
|
return Store.RevokeAsync(subject, client, status, cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Revokes all the authorizations matching the specified parameters.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="subject">The subject associated with the authorization.</param>
|
|
|
|
/// <param name="client">The client associated with the authorization.</param>
|
|
|
|
/// <param name="status">The authorization status.</param>
|
|
|
|
/// <param name="type">The authorization type.</param>
|
|
|
|
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
|
|
|
|
/// <returns>The number of authorizations corresponding to the criteria that were marked as revoked.</returns>
|
|
|
|
public virtual ValueTask<long> RevokeAsync(string subject, string client, string status, string type, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(subject)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0198), nameof(subject)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(client)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0124), nameof(client)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(status)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0199), nameof(status)); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(type)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(SR.GetResourceString(SR.ID0200), nameof(type)); |
|
|
|
} |
|
|
|
|
|
|
|
return Store.RevokeAsync(subject, client, status, type, cancellationToken); |
|
|
|
} |
|
|
|
public virtual ValueTask<long> RevokeAsync(string? subject, string? client, string? status, string? type, CancellationToken cancellationToken = default) |
|
|
|
=> Store.RevokeAsync(subject, client, status, type, cancellationToken); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Revokes all the authorizations associated with the specified application identifier.
|
|
|
|
@ -1352,19 +1094,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori |
|
|
|
=> DeleteAsync((TAuthorization) authorization, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
IAsyncEnumerable<object> IOpenIddictAuthorizationManager.FindAsync(string subject, string client, CancellationToken cancellationToken) |
|
|
|
=> FindAsync(subject, client, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
IAsyncEnumerable<object> IOpenIddictAuthorizationManager.FindAsync(string subject, string client, string status, CancellationToken cancellationToken) |
|
|
|
=> FindAsync(subject, client, status, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
IAsyncEnumerable<object> IOpenIddictAuthorizationManager.FindAsync(string subject, string client, string status, string type, CancellationToken cancellationToken) |
|
|
|
=> FindAsync(subject, client, status, type, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
IAsyncEnumerable<object> IOpenIddictAuthorizationManager.FindAsync(string subject, string client, string status, string type, ImmutableArray<string> scopes, CancellationToken cancellationToken) |
|
|
|
IAsyncEnumerable<object> IOpenIddictAuthorizationManager.FindAsync(string? subject, string? client, string? status, string? type, ImmutableArray<string>? scopes, CancellationToken cancellationToken) |
|
|
|
=> FindAsync(subject, client, status, type, scopes, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
@ -1455,15 +1185,7 @@ public class OpenIddictAuthorizationManager<TAuthorization> : IOpenIddictAuthori |
|
|
|
=> PruneAsync(threshold, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
ValueTask<long> IOpenIddictAuthorizationManager.RevokeAsync(string subject, string client, CancellationToken cancellationToken) |
|
|
|
=> RevokeAsync(subject, client, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
ValueTask<long> IOpenIddictAuthorizationManager.RevokeAsync(string subject, string client, string status, CancellationToken cancellationToken) |
|
|
|
=> RevokeAsync(subject, client, status, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
ValueTask<long> IOpenIddictAuthorizationManager.RevokeAsync(string subject, string client, string status, string type, CancellationToken cancellationToken) |
|
|
|
ValueTask<long> IOpenIddictAuthorizationManager.RevokeAsync(string? subject, string? client, string? status, string? type, CancellationToken cancellationToken) |
|
|
|
=> RevokeAsync(subject, client, status, type, cancellationToken); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|