Browse Source

Upgrade to `OpenIddict 6.0.0-preview3`.

pull/20979/head
maliming 1 year ago
parent
commit
5b9296c1d6
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 10
      Directory.Packages.props
  2. 12
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs
  3. 78
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationCache.cs
  4. 62
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs
  5. 8
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/IOpenIddictAuthorizationRepository.cs
  6. 52
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenCache.cs
  7. 45
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs
  8. 8
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/IOpenIddictTokenRepository.cs
  9. 33
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs
  10. 31
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs
  11. 54
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs
  12. 19
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs
  13. 65
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs
  14. 37
      modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictAuthorizationRepository_Tests.cs
  15. 8
      modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictTokenRepository_Tests.cs

10
Directory.Packages.props

@ -120,11 +120,11 @@
<PackageVersion Include="NUglify" Version="1.21.9" /> <PackageVersion Include="NUglify" Version="1.21.9" />
<PackageVersion Include="Nullable" Version="1.3.1" /> <PackageVersion Include="Nullable" Version="1.3.1" />
<PackageVersion Include="Octokit" Version="13.0.1" /> <PackageVersion Include="Octokit" Version="13.0.1" />
<PackageVersion Include="OpenIddict.Abstractions" Version="6.0.0-preview2.24522.58" /> <PackageVersion Include="OpenIddict.Abstractions" Version="6.0.0-preview3.24551.41" />
<PackageVersion Include="OpenIddict.Core" Version="6.0.0-preview2.24522.58" /> <PackageVersion Include="OpenIddict.Core" Version="6.0.0-preview3.24551.41" />
<PackageVersion Include="OpenIddict.Server.AspNetCore" Version="6.0.0-preview2.24522.58" /> <PackageVersion Include="OpenIddict.Server.AspNetCore" Version="6.0.0-preview3.24551.41" />
<PackageVersion Include="OpenIddict.Validation.AspNetCore" Version="6.0.0-preview2.24522.58" /> <PackageVersion Include="OpenIddict.Validation.AspNetCore" Version="6.0.0-preview3.24551.41" />
<PackageVersion Include="OpenIddict.Validation.ServerIntegration" Version="6.0.0-preview2.24522.58" /> <PackageVersion Include="OpenIddict.Validation.ServerIntegration" Version="6.0.0-preview3.24551.41" />
<PackageVersion Include="Oracle.EntityFrameworkCore" Version="8.23.60" /> <PackageVersion Include="Oracle.EntityFrameworkCore" Version="8.23.60" />
<PackageVersion Include="Polly" Version="8.4.2" /> <PackageVersion Include="Polly" Version="8.4.2" />
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" /> <PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />

12
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs

@ -30,11 +30,11 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
// If prompt=login was specified by the client application, // If prompt=login was specified by the client application,
// immediately return the user agent to the login page. // immediately return the user agent to the login page.
if (request.HasPrompt(OpenIddictConstants.PromptValues.Login)) if (request.HasPromptValue(OpenIddictConstants.PromptValues.Login))
{ {
// To avoid endless login -> authorization redirects, the prompt=login flag // To avoid endless login -> authorization redirects, the prompt=login flag
// is removed from the authorization request payload before redirecting the user. // is removed from the authorization request payload before redirecting the user.
var prompt = string.Join(" ", request.GetPrompts().Remove(OpenIddictConstants.PromptValues.Login)); var prompt = string.Join(" ", request.GetPromptValues().Remove(OpenIddictConstants.PromptValues.Login));
var parameters = Request.HasFormContentType ? var parameters = Request.HasFormContentType ?
Request.Form.Where(parameter => parameter.Key != OpenIddictConstants.Parameters.Prompt).ToList() : Request.Form.Where(parameter => parameter.Key != OpenIddictConstants.Parameters.Prompt).ToList() :
@ -59,7 +59,7 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
{ {
// If the client application requested promptless authentication, // If the client application requested promptless authentication,
// return an error indicating that the user is not logged in. // return an error indicating that the user is not logged in.
if (request.HasPrompt(OpenIddictConstants.PromptValues.None)) if (request.HasPromptValue(OpenIddictConstants.PromptValues.None))
{ {
return Forbid( return Forbid(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
@ -137,7 +137,7 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
// return an authorization response without displaying the consent form. // return an authorization response without displaying the consent form.
case OpenIddictConstants.ConsentTypes.Implicit: case OpenIddictConstants.ConsentTypes.Implicit:
case OpenIddictConstants.ConsentTypes.External when authorizations.Any(): case OpenIddictConstants.ConsentTypes.External when authorizations.Any():
case OpenIddictConstants.ConsentTypes.Explicit when authorizations.Any() && !request.HasPrompt(OpenIddictConstants.PromptValues.Consent): case OpenIddictConstants.ConsentTypes.Explicit when authorizations.Any() && !request.HasPromptValue(OpenIddictConstants.PromptValues.Consent):
var principal = await SignInManager.CreateUserPrincipalAsync(user); var principal = await SignInManager.CreateUserPrincipalAsync(user);
if (result.Properties != null && result.Properties.IsPersistent) if (result.Properties != null && result.Properties.IsPersistent)
@ -173,8 +173,8 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
// At this point, no authorization was found in the database and an error must be returned // At this point, no authorization was found in the database and an error must be returned
// if the client application specified prompt=none in the authorization request. // if the client application specified prompt=none in the authorization request.
case OpenIddictConstants.ConsentTypes.Explicit when request.HasPrompt(OpenIddictConstants.PromptValues.None): case OpenIddictConstants.ConsentTypes.Explicit when request.HasPromptValue(OpenIddictConstants.PromptValues.None):
case OpenIddictConstants.ConsentTypes.Systematic when request.HasPrompt(OpenIddictConstants.PromptValues.None): case OpenIddictConstants.ConsentTypes.Systematic when request.HasPromptValue(OpenIddictConstants.PromptValues.None):
return Forbid( return Forbid(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
properties: new AuthenticationProperties(new Dictionary<string, string> properties: new AuthenticationProperties(new Dictionary<string, string>

78
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationCache.cs

@ -30,82 +30,8 @@ public class AbpOpenIddictAuthorizationCache : AbpOpenIddictCacheBase<OpenIddict
await Cache.SetAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(authorization, cancellationToken)}", authorization, token: cancellationToken); await Cache.SetAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(authorization, cancellationToken)}", authorization, token: cancellationToken);
} }
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken) public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, string type, ImmutableArray<string>? scopes, [EnumeratorCancellation] CancellationToken cancellationToken)
{ {
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
var authorizations = await ArrayCache.GetOrAddAsync($"{nameof(FindAsync)}_{subject}_{client}", async () =>
{
var applications = new List<OpenIddictAuthorizationModel>();
await foreach (var authorization in Store.FindAsync(subject, client, cancellationToken))
{
applications.Add(authorization);
await AddAsync(authorization, cancellationToken);
}
return applications.ToArray();
}, token: cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
var authorizations = await ArrayCache.GetOrAddAsync($"{nameof(FindAsync)}_{subject}_{client}_{status}", async () =>
{
var applications = new List<OpenIddictAuthorizationModel>();
await foreach (var authorization in Store.FindAsync(subject, client, status, cancellationToken))
{
applications.Add(authorization);
await AddAsync(authorization, cancellationToken);
}
return applications.ToArray();
}, token: cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, string type, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var authorizations = await ArrayCache.GetOrAddAsync($"{nameof(FindAsync)}_{subject}_{client}_{status}_{type}", async () =>
{
var applications = new List<OpenIddictAuthorizationModel>();
await foreach (var authorization in Store.FindAsync(subject, client, status, type, cancellationToken))
{
applications.Add(authorization);
await AddAsync(authorization, cancellationToken);
}
return applications.ToArray();
}, token: cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, string type, ImmutableArray<string> scopes, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
// Note: this method is only partially cached. // Note: this method is only partially cached.
await foreach (var authorization in Store.FindAsync(subject, client, status, type, scopes, cancellationToken)) await foreach (var authorization in Store.FindAsync(subject, client, status, type, scopes, cancellationToken))
{ {
@ -170,8 +96,6 @@ public class AbpOpenIddictAuthorizationCache : AbpOpenIddictCacheBase<OpenIddict
await ArrayCache.RemoveManyAsync(new[] await ArrayCache.RemoveManyAsync(new[]
{ {
$"{nameof(FindAsync)}_{await Store.GetSubjectAsync(authorization, cancellationToken)}_{await Store.GetApplicationIdAsync(authorization, cancellationToken)}",
$"{nameof(FindAsync)}_{await Store.GetSubjectAsync(authorization, cancellationToken)}_{await Store.GetApplicationIdAsync(authorization, cancellationToken)}_{await Store.GetStatusAsync(authorization, cancellationToken)}",
$"{nameof(FindAsync)}_{await Store.GetSubjectAsync(authorization, cancellationToken)}_{await Store.GetApplicationIdAsync(authorization, cancellationToken)}_{await Store.GetStatusAsync(authorization, cancellationToken)}_{await Store.GetTypeAsync(authorization, cancellationToken)}", $"{nameof(FindAsync)}_{await Store.GetSubjectAsync(authorization, cancellationToken)}_{await Store.GetApplicationIdAsync(authorization, cancellationToken)}_{await Store.GetStatusAsync(authorization, cancellationToken)}_{await Store.GetTypeAsync(authorization, cancellationToken)}",
$"{nameof(FindByApplicationIdAsync)}_{await Store.GetApplicationIdAsync(authorization, cancellationToken)}", $"{nameof(FindByApplicationIdAsync)}_{await Store.GetApplicationIdAsync(authorization, cancellationToken)}",
$"{nameof(FindBySubjectAsync)}_{await Store.GetSubjectAsync(authorization, cancellationToken)}" $"{nameof(FindBySubjectAsync)}_{await Store.GetSubjectAsync(authorization, cancellationToken)}"

62
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs

@ -80,57 +80,19 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
} }
} }
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken) public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, string type, ImmutableArray<string>? scopes, [EnumeratorCancellation] CancellationToken cancellationToken)
{ {
Check.NotNullOrEmpty(subject, nameof(subject)); Guid? identifier = null;
Check.NotNullOrEmpty(client, nameof(client)); if (!string.IsNullOrEmpty(client))
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, string type, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken);
foreach (var authorization in authorizations)
{ {
yield return authorization.ToModel(); identifier = ConvertIdentifierFromString(client);
} }
}
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, string status, string type, ImmutableArray<string> scopes, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken); var authorizations = await Repository.FindAsync(subject, identifier, status, type, cancellationToken);
foreach (var authorization in authorizations) foreach (var authorization in authorizations)
{ {
if (new HashSet<string>(await GetScopesAsync(authorization.ToModel(), cancellationToken), StringComparer.Ordinal).IsSupersetOf(scopes)) if (new HashSet<string>(await GetScopesAsync(authorization.ToModel(), cancellationToken), StringComparer.Ordinal).IsSupersetOf(scopes!))
{ {
yield return authorization.ToModel(); yield return authorization.ToModel();
} }
@ -300,6 +262,17 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
} }
} }
public virtual async ValueTask<long> RevokeAsync(string subject, string client, string status, string type, CancellationToken cancellationToken)
{
Guid? identifier = null;
if (!string.IsNullOrEmpty(client))
{
identifier = ConvertIdentifierFromString(client);
}
return await Repository.RevokeAsync(subject, identifier, status, type, cancellationToken);
}
public virtual async ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken) public virtual async ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{ {
Check.NotNullOrEmpty(identifier, nameof(identifier)); Check.NotNullOrEmpty(identifier, nameof(identifier));
@ -309,7 +282,6 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return await Repository.RevokeByApplicationIdAsync(key, cancellationToken: cancellationToken); return await Repository.RevokeByApplicationIdAsync(key, cancellationToken: cancellationToken);
} }
/// <inheritdoc/>
public virtual async ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken) public virtual async ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken)
{ {
Check.NotNullOrEmpty(subject, nameof(subject)); Check.NotNullOrEmpty(subject, nameof(subject));

8
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/IOpenIddictAuthorizationRepository.cs

@ -8,11 +8,7 @@ namespace Volo.Abp.OpenIddict.Authorizations;
public interface IOpenIddictAuthorizationRepository : IBasicRepository<OpenIddictAuthorization, Guid> public interface IOpenIddictAuthorizationRepository : IBasicRepository<OpenIddictAuthorization, Guid>
{ {
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default); Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default); Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default);
@ -24,6 +20,8 @@ public interface IOpenIddictAuthorizationRepository : IBasicRepository<OpenIddic
Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default); Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default);
ValueTask<long> RevokeAsync(string subject, Guid? applicationId, string status, string type, CancellationToken cancellationToken = default);
ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default); ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default);
ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default); ValueTask<long> RevokeBySubjectAsync(string subject, CancellationToken cancellationToken = default);

52
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenCache.cs

@ -30,58 +30,8 @@ public class AbpOpenIddictTokenCache : AbpOpenIddictCacheBase<OpenIddictToken, O
await Cache.SetAsync($"{nameof(FindByReferenceIdAsync)}_{await Store.GetReferenceIdAsync(token, cancellationToken)}", token, token: cancellationToken); await Cache.SetAsync($"{nameof(FindByReferenceIdAsync)}_{await Store.GetReferenceIdAsync(token, cancellationToken)}", token, token: cancellationToken);
} }
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
var tokens = await ArrayCache.GetOrAddAsync($"{nameof(FindAsync)}_{subject}_{client}", async () =>
{
var tokens = new List<OpenIddictTokenModel>();
await foreach (var token in Store.FindAsync(subject, client, cancellationToken))
{
tokens.Add(token);
await AddAsync(token, cancellationToken);
}
return tokens.ToArray();
}, token: cancellationToken);
foreach (var token in tokens)
{
yield return token;
}
}
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, string status, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
var tokens = await ArrayCache.GetOrAddAsync($"{nameof(FindAsync)}_{subject}_{client}_{status}", async () =>
{
var tokens = new List<OpenIddictTokenModel>();
await foreach (var token in Store.FindAsync(subject, client, status, cancellationToken))
{
tokens.Add(token);
await AddAsync(token, cancellationToken);
}
return tokens.ToArray();
}, token: cancellationToken);
foreach (var token in tokens)
{
yield return token;
}
}
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, string status, string type, [EnumeratorCancellation] CancellationToken cancellationToken) public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, string status, string type, [EnumeratorCancellation] CancellationToken cancellationToken)
{ {
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var tokens = await ArrayCache.GetOrAddAsync($"{nameof(FindAsync)}_{subject}_{client}_{status}_{type}", async () => var tokens = await ArrayCache.GetOrAddAsync($"{nameof(FindAsync)}_{subject}_{client}_{status}_{type}", async () =>
{ {
var tokens = new List<OpenIddictTokenModel>(); var tokens = new List<OpenIddictTokenModel>();
@ -196,8 +146,6 @@ public class AbpOpenIddictTokenCache : AbpOpenIddictCacheBase<OpenIddictToken, O
{ {
await ArrayCache.RemoveManyAsync(new[] await ArrayCache.RemoveManyAsync(new[]
{ {
$"{nameof(FindAsync)}_{await Store.GetSubjectAsync(token, cancellationToken)}_{await Store.GetApplicationIdAsync(token, cancellationToken)}",
$"{nameof(FindAsync)}_{await Store.GetSubjectAsync(token, cancellationToken)}_{await Store.GetApplicationIdAsync(token, cancellationToken)}_{Store.GetStatusAsync(token, cancellationToken)}",
$"{nameof(FindAsync)}_{await Store.GetSubjectAsync(token, cancellationToken)}_{await Store.GetApplicationIdAsync(token, cancellationToken)}_{Store.GetStatusAsync(token, cancellationToken)}_{Store.GetTypeAsync(token, cancellationToken)}", $"{nameof(FindAsync)}_{await Store.GetSubjectAsync(token, cancellationToken)}_{await Store.GetApplicationIdAsync(token, cancellationToken)}_{Store.GetStatusAsync(token, cancellationToken)}_{Store.GetTypeAsync(token, cancellationToken)}",
$"{nameof(FindByApplicationIdAsync)}_{await Store.GetApplicationIdAsync(token, cancellationToken)}", $"{nameof(FindByApplicationIdAsync)}_{await Store.GetApplicationIdAsync(token, cancellationToken)}",
$"{nameof(FindByAuthorizationIdAsync)}_{await Store.GetAuthorizationIdAsync(token, cancellationToken)}", $"{nameof(FindByAuthorizationIdAsync)}_{await Store.GetAuthorizationIdAsync(token, cancellationToken)}",

45
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs

@ -73,39 +73,15 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
} }
} }
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken) public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, string status, string type, [EnumeratorCancellation] CancellationToken cancellationToken)
{ {
Check.NotNullOrEmpty(subject, nameof(subject)); Guid? identifier = null;
Check.NotNullOrEmpty(client, nameof(client)); if (!string.IsNullOrEmpty(client))
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), cancellationToken);
foreach (var token in tokens)
{ {
yield return token.ToModel(); identifier = ConvertIdentifierFromString(client);
} }
}
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, string status, [EnumeratorCancellation] CancellationToken cancellationToken) var tokens = await Repository.FindAsync(subject, identifier, status, type, cancellationToken);
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, cancellationToken);
foreach (var token in tokens)
{
yield return token.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, string status, string type, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken);
foreach (var token in tokens) foreach (var token in tokens)
{ {
yield return token.ToModel(); yield return token.ToModel();
@ -320,6 +296,17 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
} }
} }
public virtual async ValueTask<long> RevokeAsync(string subject, string client, string status, string type, CancellationToken cancellationToken)
{
Guid? identifier = null;
if (!string.IsNullOrEmpty(client))
{
identifier = ConvertIdentifierFromString(client);
}
return await Repository.RevokeAsync(subject, identifier, status, type, cancellationToken);
}
public virtual async ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken) public virtual async ValueTask<long> RevokeByApplicationIdAsync(string identifier, CancellationToken cancellationToken)
{ {
Check.NotNullOrEmpty(identifier, nameof(identifier)); Check.NotNullOrEmpty(identifier, nameof(identifier));

8
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/IOpenIddictTokenRepository.cs

@ -14,11 +14,7 @@ public interface IOpenIddictTokenRepository : IBasicRepository<OpenIddictToken,
Task DeleteManyByAuthorizationIdsAsync(Guid[] authorizationIds, bool autoSave = false, CancellationToken cancellationToken = default); Task DeleteManyByAuthorizationIdsAsync(Guid[] authorizationIds, bool autoSave = false, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default); Task<List<OpenIddictToken>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default); Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default);
@ -34,6 +30,8 @@ public interface IOpenIddictTokenRepository : IBasicRepository<OpenIddictToken,
Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default); Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default);
ValueTask<long> RevokeAsync(string subject, Guid? applicationId, string status, string type, CancellationToken cancellationToken = default);
ValueTask<long> RevokeByAuthorizationIdAsync(Guid id, CancellationToken cancellationToken = default); ValueTask<long> RevokeByAuthorizationIdAsync(Guid id, CancellationToken cancellationToken = default);
ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default); ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default);

33
modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs

@ -20,24 +20,13 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository<IOpenIdd
} }
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where(x => x.Subject == subject && x.ApplicationId == client) .WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.ToListAsync(GetCancellationToken(cancellationToken)); .WhereIf(client.HasValue, x => x.ApplicationId == client)
} .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
.WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.Subject == subject && x.Status == status && x.ApplicationId == client)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.Subject == subject && x.Status == status && x.Type == type && x.ApplicationId == client)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -99,6 +88,18 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository<IOpenIdd
return count + await (await GetDbSetAsync()).Where(x => authorizations.Contains(x.Id)).ExecuteDeleteAsync(cancellationToken); return count + await (await GetDbSetAsync()).Where(x => authorizations.Contains(x.Id)).ExecuteDeleteAsync(cancellationToken);
} }
public virtual async ValueTask<long> RevokeAsync(string subject, Guid? applicationId, string status, string type, CancellationToken cancellationToken = default)
{
var query = (await GetQueryableAsync())
.WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.WhereIf(applicationId.HasValue, x => x.ApplicationId == applicationId)
.WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
.WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type);
return await query.ExecuteUpdateAsync(entity => entity.SetProperty(
authorization => authorization.Status, OpenIddictConstants.Statuses.Revoked), cancellationToken);
}
public virtual async ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) public virtual async ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{ {
return await (from authorization in await GetQueryableAsync() return await (from authorization in await GetQueryableAsync()

31
modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs

@ -47,19 +47,14 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbCon
await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken)); await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default)
{ {
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client).ToListAsync(GetCancellationToken(cancellationToken)); return await (await GetQueryableAsync())
} .WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.WhereIf(client.HasValue, x => x.ApplicationId == client)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default) .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
{ .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type)
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client && x.Status == status).ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client && x.Status == status && x.Type == type).ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
@ -110,6 +105,18 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbCon
.ExecuteDeleteAsync(GetCancellationToken(cancellationToken)); .ExecuteDeleteAsync(GetCancellationToken(cancellationToken));
} }
public virtual async ValueTask<long> RevokeAsync(string subject, Guid? applicationId, string status, string type, CancellationToken cancellationToken = default)
{
var query = (await GetQueryableAsync())
.WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.WhereIf(applicationId.HasValue, x => x.ApplicationId == applicationId)
.WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
.WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type);
return await query.ExecuteUpdateAsync(entity => entity.SetProperty(
authorization => authorization.Status, OpenIddictConstants.Statuses.Revoked), cancellationToken);
}
public virtual async ValueTask<long> RevokeByAuthorizationIdAsync(Guid id, CancellationToken cancellationToken) public virtual async ValueTask<long> RevokeByAuthorizationIdAsync(Guid id, CancellationToken cancellationToken)
{ {
return await (from token in await GetQueryableAsync() where token.AuthorizationId == id select token) return await (from token in await GetQueryableAsync() where token.AuthorizationId == id select token)

54
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using OpenIddict.Abstractions; using OpenIddict.Abstractions;
@ -26,24 +27,14 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
TokenDbRepositoryFilterer = tokenDbRepositoryFilterer; TokenDbRepositoryFilterer = tokenDbRepositoryFilterer;
} }
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.Subject == subject && x.ApplicationId == client) .WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.ToListAsync(GetCancellationToken(cancellationToken)); .WhereIf(client.HasValue, x => x.ApplicationId == client)
} .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
.WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default) .As<IMongoQueryable<OpenIddictAuthorization>>()
{
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.Subject == subject && x.Status == status && x.ApplicationId == client)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.Subject == subject && x.Status == status && x.Type == type && x.ApplicationId == client)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -110,6 +101,37 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
return authorizations.Count; return authorizations.Count;
} }
public async ValueTask<long> RevokeAsync(string subject, Guid? applicationId, string status, string type, CancellationToken cancellationToken = default)
{
var filter = Builders<OpenIddictAuthorization>.Filter.Empty;
if (!string.IsNullOrEmpty(subject))
{
filter &= Builders<OpenIddictAuthorization>.Filter.Where(authorization => authorization.Subject == subject);
}
if (applicationId.HasValue)
{
filter &= Builders<OpenIddictAuthorization>.Filter.Where(authorization => authorization.ApplicationId == applicationId);
}
if (!string.IsNullOrEmpty(status))
{
filter &= Builders<OpenIddictAuthorization>.Filter.Where(authorization => authorization.Status == status);
}
if (!string.IsNullOrEmpty(type))
{
filter &= Builders<OpenIddictAuthorization>.Filter.Where(authorization => authorization.Type == type);
}
return (await (await GetCollectionAsync(cancellationToken)).UpdateManyAsync(
filter : filter,
update : Builders<OpenIddictAuthorization>.Update.Set(authorization => authorization.Status, OpenIddictConstants.Statuses.Revoked),
options : null,
cancellationToken: cancellationToken)).MatchedCount;
}
public virtual async ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) public virtual async ValueTask<long> RevokeByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{ {
return (await (await GetCollectionAsync(cancellationToken)).UpdateManyAsync( return (await (await GetCollectionAsync(cancellationToken)).UpdateManyAsync(

19
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs

@ -17,12 +17,12 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
public MongoOpenIddictScopeRepository(IMongoDbContextProvider<OpenIddictMongoDbContext> dbContextProvider) : base(dbContextProvider) public MongoOpenIddictScopeRepository(IMongoDbContextProvider<OpenIddictMongoDbContext> dbContextProvider) : base(dbContextProvider)
{ {
} }
public virtual async Task<List<OpenIddictScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, public virtual async Task<List<OpenIddictScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetMongoQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => .WhereIf(!filter.IsNullOrWhiteSpace(), x =>
x.Name.Contains(filter) || x.Name.Contains(filter) ||
x.DisplayName.Contains(filter) || x.DisplayName.Contains(filter) ||
x.Description.Contains(filter)) x.Description.Contains(filter))
@ -35,7 +35,7 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetMongoQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => .WhereIf(!filter.IsNullOrWhiteSpace(), x =>
x.Name.Contains(filter) || x.Name.Contains(filter) ||
x.DisplayName.Contains(filter) || x.DisplayName.Contains(filter) ||
x.Description.Contains(filter)) x.Description.Contains(filter))
@ -55,21 +55,24 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default)
{ {
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => names.Contains(x.Name)) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => names.Contains(x.Name))
.As<IMongoQueryable<OpenIddictScope>>() .As<IMongoQueryable<OpenIddictScope>>()
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default)
{ {
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Resources.Contains(resource)) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.Resources.Contains(resource))
.As<IMongoQueryable<OpenIddictScope>>() .As<IMongoQueryable<OpenIddictScope>>()
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{ {
return await Queryable.OrderBy((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.Id) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.OrderBy(x => x.Id)
.SkipIf<OpenIddictScope, IQueryable<OpenIddictScope>>(offset.HasValue, offset) .SkipIf<OpenIddictScope, IQueryable<OpenIddictScope>>(offset.HasValue, offset)
.TakeIf<OpenIddictScope, IQueryable<OpenIddictScope>>(count.HasValue, count) .TakeIf<OpenIddictScope, IQueryable<OpenIddictScope>>(count.HasValue, count)
.As<IMongoQueryable<OpenIddictScope>>() .As<IMongoQueryable<OpenIddictScope>>()

65
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs

@ -47,37 +47,29 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken)); await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid? client, string status, string type, CancellationToken cancellationToken = default)
{ {
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject && x.ApplicationId == client) return await (await GetMongoQueryableAsync(cancellationToken))
.As<IMongoQueryable<OpenIddictToken>>() .WhereIf(!subject.IsNullOrWhiteSpace(), x => x.Subject == subject)
.ToListAsync(GetCancellationToken(cancellationToken)); .WhereIf(client.HasValue, x => x.ApplicationId == client)
} .WhereIf(!status.IsNullOrWhiteSpace(), x => x.Status == status)
.WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.Subject == subject && x.ApplicationId == client && x.Status == status)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.Subject == subject && x.ApplicationId == client && x.Status == status && x.Type == type)
.As<IMongoQueryable<OpenIddictToken>>() .As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{ {
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.ApplicationId == applicationId) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.ApplicationId == applicationId)
.As<IMongoQueryable<OpenIddictToken>>() .As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default)
{ {
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.AuthorizationId == authorizationId) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.AuthorizationId == authorizationId)
.As<IMongoQueryable<OpenIddictToken>>() .As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -94,14 +86,16 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{ {
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.Subject == subject) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.Subject == subject)
.As<IMongoQueryable<OpenIddictToken>>() .As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default) public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{ {
return await Queryable.OrderBy((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.Id) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.OrderBy(x => x.Id)
.SkipIf<OpenIddictToken, IQueryable<OpenIddictToken>>(offset.HasValue, offset) .SkipIf<OpenIddictToken, IQueryable<OpenIddictToken>>(offset.HasValue, offset)
.TakeIf<OpenIddictToken, IQueryable<OpenIddictToken>>(count.HasValue, count) .TakeIf<OpenIddictToken, IQueryable<OpenIddictToken>>(count.HasValue, count)
.As<IMongoQueryable<OpenIddictToken>>() .As<IMongoQueryable<OpenIddictToken>>()
@ -129,6 +123,37 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
return tokens.Count; return tokens.Count;
} }
public virtual async ValueTask<long> RevokeAsync(string subject, Guid? applicationId, string status, string type, CancellationToken cancellationToken = default)
{
var filter = Builders<OpenIddictToken>.Filter.Empty;
if (!string.IsNullOrEmpty(subject))
{
filter &= Builders<OpenIddictToken>.Filter.Where(authorization => authorization.Subject == subject);
}
if (applicationId.HasValue)
{
filter &= Builders<OpenIddictToken>.Filter.Where(authorization => authorization.ApplicationId == applicationId);
}
if (!string.IsNullOrEmpty(status))
{
filter &= Builders<OpenIddictToken>.Filter.Where(authorization => authorization.Status == status);
}
if (!string.IsNullOrEmpty(type))
{
filter &= Builders<OpenIddictToken>.Filter.Where(authorization => authorization.Type == type);
}
return (await (await GetCollectionAsync(cancellationToken)).UpdateManyAsync(
filter : filter,
update : Builders<OpenIddictToken>.Update.Set(authorization => authorization.Status, OpenIddictConstants.Statuses.Revoked),
options : null,
cancellationToken: cancellationToken)).MatchedCount;
}
public virtual async ValueTask<long> RevokeByAuthorizationIdAsync(Guid id, CancellationToken cancellationToken) public virtual async ValueTask<long> RevokeByAuthorizationIdAsync(Guid id, CancellationToken cancellationToken)
{ {
return (await (await GetCollectionAsync(GetCancellationToken(cancellationToken))).UpdateManyAsync( return (await (await GetCollectionAsync(GetCancellationToken(cancellationToken))).UpdateManyAsync(

37
modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictAuthorizationRepository_Tests.cs

@ -24,10 +24,10 @@ public abstract class OpenIddictAuthorizationRepository_Tests<TStartupModule> :
[Fact] [Fact]
public async Task FindAsync() public async Task FindAsync()
{ {
(await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: new Guid())).Count.ShouldBe(0); (await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: new Guid(), status: null, type: null)).Count.ShouldBe(0);
(await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id)).Count.ShouldBe(1); (await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: null, type: null)).Count.ShouldBe(1);
(await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: "NonExistsStatus")).Count.ShouldBe(0); (await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: "NonExistsStatus", type: null)).Count.ShouldBe(0);
(await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid)).Count.ShouldBe(1); (await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid, type: null)).Count.ShouldBe(1);
(await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid ,type: "NonExistsType")).Count.ShouldBe(0); (await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid ,type: "NonExistsType")).Count.ShouldBe(0);
(await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid ,type: OpenIddictConstants.AuthorizationTypes.Permanent)).Count.ShouldBe(1); (await _authorizationRepository.FindAsync(subject: _testData.Subject1, client: _testData.App1Id, status: OpenIddictConstants.Statuses.Valid ,type: OpenIddictConstants.AuthorizationTypes.Permanent)).Count.ShouldBe(1);
} }
@ -71,6 +71,35 @@ public abstract class OpenIddictAuthorizationRepository_Tests<TStartupModule> :
(await _authorizationRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(1); (await _authorizationRepository.ListAsync(int.MaxValue, 0)).Count.ShouldBe(1);
} }
[Fact]
public async Task RevokeAsync()
{
var authorizations = await _authorizationRepository.FindByApplicationIdAsync(_testData.App1Id);
authorizations.Count.ShouldBe(1);
authorizations.First().ApplicationId.ShouldBe(_testData.App1Id);
authorizations.First().Status.ShouldBe(OpenIddictConstants.Statuses.Valid);
(await _authorizationRepository.RevokeAsync(null, _testData.App1Id, null, null)).ShouldBe(1);
authorizations = await _authorizationRepository.FindByApplicationIdAsync(_testData.App1Id);
authorizations.Count.ShouldBe(1);
authorizations.First().ApplicationId.ShouldBe(_testData.App1Id);
authorizations.First().Status.ShouldBe(OpenIddictConstants.Statuses.Revoked);
authorizations = await _authorizationRepository.FindBySubjectAsync(_testData.Subject2);
authorizations.Count.ShouldBe(1);
authorizations.First().Subject.ShouldBe(_testData.Subject2);
authorizations.First().Status.ShouldBe(OpenIddictConstants.Statuses.Inactive);
(await _authorizationRepository.RevokeAsync(_testData.Subject2, null, null, null)).ShouldBe(1);
authorizations = await _authorizationRepository.FindBySubjectAsync(_testData.Subject2);
authorizations.Count.ShouldBe(1);
authorizations.First().Subject.ShouldBe(_testData.Subject2);
authorizations.First().Status.ShouldBe(OpenIddictConstants.Statuses.Revoked);
}
[Fact] [Fact]
public async Task RevokeByApplicationIdAsync() public async Task RevokeByApplicationIdAsync()
{ {

8
modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/Volo/Abp/OpenIddict/OpenIddictTokenRepository_Tests.cs

@ -62,10 +62,10 @@ public abstract class OpenIddictTokenRepository_Tests<TStartupModule> : OpenIddi
[Fact] [Fact]
public async Task FindAsync() public async Task FindAsync()
{ {
(await _tokenRepository.FindAsync( _testData.Subject1, new Guid())).Count.ShouldBe(0); (await _tokenRepository.FindAsync( _testData.Subject1, new Guid(), null, null)).Count.ShouldBe(0);
(await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id)).Count.ShouldBe(1); (await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, null, null)).Count.ShouldBe(1);
(await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, "NonExistsStatus")).Count.ShouldBe(0); (await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, "NonExistsStatus", null)).Count.ShouldBe(0);
(await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, OpenIddictConstants.Statuses.Redeemed)).Count.ShouldBe(1); (await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, OpenIddictConstants.Statuses.Redeemed, null)).Count.ShouldBe(1);
(await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, OpenIddictConstants.Statuses.Redeemed, "NonExistsType")).Count.ShouldBe(0); (await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, OpenIddictConstants.Statuses.Redeemed, "NonExistsType")).Count.ShouldBe(0);
(await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, OpenIddictConstants.Statuses.Redeemed, "TestType1")).Count.ShouldBe(1); (await _tokenRepository.FindAsync( _testData.Subject1, _testData.App1Id, OpenIddictConstants.Statuses.Redeemed, "TestType1")).Count.ShouldBe(1);
} }

Loading…
Cancel
Save