Browse Source

Add Cache feature.

pull/12084/head
maliming 4 years ago
parent
commit
49d7941622
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 4
      modules/openiddict/app/OpenIddict.Demo.API/Program.cs
  2. 1
      modules/openiddict/app/OpenIddict.Demo.Server/EntityFrameworkCore/ServerDataSeedContributor.cs
  3. 2
      modules/openiddict/app/OpenIddict.Demo.Server/OpenIddictServerModule.cs
  4. 3
      modules/openiddict/app/OpenIddict.Demo.Server/Pages/Index.cshtml.cs
  5. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AbpOpenIdDictControllerBase.cs
  6. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs
  7. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.AuthorizationCode.cs
  8. 4
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.cs
  9. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/UserInfoController.cs
  10. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo.Abp.OpenIddict.Domain.csproj
  11. 27
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictCacheBase.cs
  12. 29
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictDomainModule.cs
  13. 10
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictStoreBase.cs
  14. 124
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationCache.cs
  15. 221
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationStore.cs
  16. 7
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/IOpenIddictApplicationRepository.cs
  17. 9
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/OpenIddictApplication.cs
  18. 68
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/OpenIddictApplicationExtensions.cs
  19. 74
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/OpenIddictApplicationModel.cs
  20. 182
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationCache.cs
  21. 149
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/AbpOpenIddictAuthorizationStore.cs
  22. 7
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/IOpenIddictAuthorizationRepository.cs
  23. 9
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/OpenIddictAuthorization.cs
  24. 56
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/OpenIddictAuthorizationExtensions.cs
  25. 47
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/OpenIddictAuthorizationModel.cs
  26. 111
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeCache.cs
  27. 169
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeStore.cs
  28. 7
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/IOpenIddictScopeRepository.cs
  29. 9
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/OpenIddictScope.cs
  30. 56
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/OpenIddictScopeExtensions.cs
  31. 50
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/OpenIddictScopeModel.cs
  32. 210
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenCache.cs
  33. 152
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs
  34. 7
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/IOpenIddictTokenRepository.cs
  35. 9
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/OpenIddictToken.cs
  36. 68
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/OpenIddictTokenExtensions.cs
  37. 71
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/OpenIddictTokenModel.cs
  38. 21
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Applications/EfCoreOpenIddictApplicationRepository.cs
  39. 17
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Authorizations/EfCoreOpenIddictAuthorizationRepository.cs
  40. 1
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictDbContextModelCreatingExtensions.cs
  41. 15
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Scopes/EfCoreOpenIddictScopeRepository.cs
  42. 15
      modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreOpenIddictTokenRepository.cs
  43. 12
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs
  44. 15
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Authorizations/MongoOpenIddictAuthorizationRepository.cs
  45. 15
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Scopes/MongoOpenIddictScopeRepository.cs
  46. 15
      modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Tokens/MongoOpenIddictTokenRepository.cs
  47. 1
      modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/OpenIddictTestBase.cs
  48. 1
      modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/OpenIddictTestBaseModule.cs

4
modules/openiddict/app/OpenIddict.Demo.API/Program.cs

@ -1,9 +1,5 @@
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
var builder = WebApplication.CreateBuilder(args);

1
modules/openiddict/app/OpenIddict.Demo.Server/EntityFrameworkCore/ServerDataSeedContributor.cs

@ -1,6 +1,5 @@
using System.Globalization;
using OpenIddict.Abstractions;
using Volo;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;

2
modules/openiddict/app/OpenIddict.Demo.Server/OpenIddictServerModule.cs

@ -1,8 +1,6 @@
using System.Text;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Abstractions;
using OpenIddict.Demo.Server.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.Account;

3
modules/openiddict/app/OpenIddict.Demo.Server/Pages/Index.cshtml.cs

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace OpenIddict.Demo.Server.Pages;

1
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AbpOpenIdDictControllerBase.cs

@ -13,7 +13,6 @@ using OpenIddict.Abstractions;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity;
using Volo.Abp.OpenIddict.Localization;
using Volo.Abp.Security.Claims;
using IdentityUser = Volo.Abp.Identity.IdentityUser;
namespace Volo.Abp.OpenIddict.Controllers;

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

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;

1
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.AuthorizationCode.cs

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;

4
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.cs

@ -1,6 +1,4 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Abstractions;

1
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/UserInfoController.cs

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;

1
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo.Abp.OpenIddict.Domain.csproj

@ -10,6 +10,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Domain\Volo.Abp.Ddd.Domain.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" />
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.Domain\Volo.Abp.Identity.Domain.csproj" />
<ProjectReference Include="..\Volo.Abp.OpenIddict.Domain.Shared\Volo.Abp.OpenIddict.Domain.Shared.csproj" />
<PackageReference Include="IdentityModel" Version="6.0.0" />

27
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictCacheBase.cs

@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Caching;
namespace Volo.Abp.OpenIddict;
public class AbpOpenIddictCacheBase<TEntity, TModel, TStore>
where TModel : class
where TEntity : class
{
public ILogger<AbpOpenIddictCacheBase<TEntity, TModel, TStore>> Logger { get; set; }
protected IDistributedCache<TModel> Cache { get; }
protected IDistributedCache<TModel[]> ArrayCache { get; }
protected TStore Store { get; }
protected AbpOpenIddictCacheBase(IDistributedCache<TModel> cache, IDistributedCache<TModel[]> arrayCache, TStore store)
{
Cache = cache;
ArrayCache = arrayCache;
Store = store;
Logger = NullLogger<AbpOpenIddictCacheBase<TEntity, TModel, TStore>>.Instance;
}
}

29
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictDomainModule.cs

@ -2,9 +2,10 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Caching;
using Volo.Abp.Domain;
using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.OpenIddict.Applications;
@ -19,7 +20,9 @@ namespace Volo.Abp.OpenIddict;
[DependsOn(
typeof(AbpDddDomainModule),
typeof(AbpIdentityDomainModule),
typeof(AbpOpenIddictDomainSharedModule)
typeof(AbpOpenIddictDomainSharedModule),
typeof(AbpCachingModule),
typeof(AbpGuidsModule)
)]
public class AbpOpenIddictDomainModule : AbpModule
{
@ -65,12 +68,16 @@ public class AbpOpenIddictDomainModule : AbpModule
.AddCore(builder =>
{
builder
.SetDefaultApplicationEntity<OpenIddictApplication>()
.SetDefaultAuthorizationEntity<OpenIddictAuthorization>()
.SetDefaultScopeEntity<OpenIddictScope>()
.SetDefaultTokenEntity<OpenIddictToken>();
.SetDefaultApplicationEntity<OpenIddictApplicationModel>()
.SetDefaultAuthorizationEntity<OpenIddictAuthorizationModel>()
.SetDefaultScopeEntity<OpenIddictScopeModel>()
.SetDefaultTokenEntity<OpenIddictTokenModel>();
builder.DisableEntityCaching();
builder
.AddApplicationStore<AbpOpenIddictApplicationStore>()
.AddAuthorizationStore<AbpOpenIddictAuthorizationStore>()
.AddScopeStore<AbpOpenIddictScopeStore>()
.AddTokenStore<AbpOpenIddictTokenStore>();
services.ExecutePreConfiguredActions(builder);
})
@ -122,14 +129,6 @@ public class AbpOpenIddictDomainModule : AbpModule
services.ExecutePreConfiguredActions(builder);
});
services.Configure<OpenIddictCoreOptions>(options =>
{
options.DefaultApplicationType = typeof(OpenIddictApplication);
options.DefaultAuthorizationType = typeof(OpenIddictAuthorization);
options.DefaultScopeType = typeof(OpenIddictScope);
options.DefaultTokenType = typeof(OpenIddictToken);
});
services.ExecutePreConfiguredActions(openIddictBuilder);
}
}

10
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/AbpOpenIddictStoreBase.cs

@ -4,10 +4,10 @@ using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;
using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict;
@ -19,13 +19,13 @@ public abstract class AbpOpenIddictStoreBase<TRepository>
protected TRepository Repository { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IMemoryCache Cache { get; }
protected IGuidGenerator GuidGenerator { get; }
protected AbpOpenIddictStoreBase(TRepository repository, IUnitOfWorkManager unitOfWorkManager, IMemoryCache cache)
protected AbpOpenIddictStoreBase(TRepository repository, IUnitOfWorkManager unitOfWorkManager, IGuidGenerator guidGenerator)
{
Repository = repository;
UnitOfWorkManager = unitOfWorkManager;
Cache = cache;
GuidGenerator = guidGenerator;
Logger = NullLogger<AbpOpenIddictStoreBase<TRepository>>.Instance;
}
@ -40,6 +40,8 @@ public abstract class AbpOpenIddictStoreBase<TRepository>
return identifier.ToString("D");
}
protected virtual string WriteStream(Action<Utf8JsonWriter> action)
{
using (var stream = new MemoryStream())

124
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationCache.cs

@ -0,0 +1,124 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using OpenIddict.Abstractions;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.OpenIddict.Applications;
public class AbpOpenIddictApplicationCache : AbpOpenIddictCacheBase<OpenIddictApplication, OpenIddictApplicationModel, IOpenIddictApplicationStore<OpenIddictApplicationModel>>,
IOpenIddictApplicationCache<OpenIddictApplicationModel>,
ITransientDependency
{
public AbpOpenIddictApplicationCache(
IDistributedCache<OpenIddictApplicationModel> cache,
IDistributedCache<OpenIddictApplicationModel[]> arrayCache,
IOpenIddictApplicationStore<OpenIddictApplicationModel> store)
: base(cache, arrayCache, store)
{
}
public virtual async ValueTask AddAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
await RemoveAsync(application, cancellationToken);
await Cache.SetManyAsync(new List<KeyValuePair<string, OpenIddictApplicationModel>>
{
new KeyValuePair<string, OpenIddictApplicationModel>($"{nameof(FindByClientIdAsync)}_{await Store.GetClientIdAsync(application, cancellationToken)}", application),
new KeyValuePair<string, OpenIddictApplicationModel>($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(application, cancellationToken)}", application)
}, token: cancellationToken);
}
public virtual async ValueTask<OpenIddictApplicationModel> FindByClientIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Cache.GetOrAddAsync($"{nameof(FindByClientIdAsync)}_{identifier}", async () =>
{
var application = await Store.FindByClientIdAsync(identifier, cancellationToken);
if (application != null)
{
await AddAsync(application, cancellationToken);
}
return application;
}, token: cancellationToken);
}
public virtual async ValueTask<OpenIddictApplicationModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{identifier}", async () =>
{
var application = await Store.FindByIdAsync(identifier, cancellationToken);
if (application != null)
{
await AddAsync(application, cancellationToken);
}
return application;
}, token: cancellationToken);
}
public virtual async IAsyncEnumerable<OpenIddictApplicationModel> FindByPostLogoutRedirectUriAsync(string address, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(address, nameof(address));
var applications = await ArrayCache.GetOrAddAsync($"{nameof(FindByPostLogoutRedirectUriAsync)}_{address}", async () =>
{
var applications = new List<OpenIddictApplicationModel>();
await foreach (var application in Store.FindByPostLogoutRedirectUriAsync(address, cancellationToken))
{
applications.Add(application);
await AddAsync(application, cancellationToken);
}
return applications.ToArray();
}, token: cancellationToken);
foreach (var application in applications)
{
yield return application;
}
}
public virtual async IAsyncEnumerable<OpenIddictApplicationModel> FindByRedirectUriAsync(string address, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(address, nameof(address));
var applications = await ArrayCache.GetOrAddAsync($"{nameof(FindByRedirectUriAsync)}_{address}", async () =>
{
var applications = new List<OpenIddictApplicationModel>();
await foreach (var application in Store.FindByRedirectUriAsync(address, cancellationToken))
{
applications.Add(application);
await AddAsync(application, cancellationToken);
}
return applications.ToArray();
}, token: cancellationToken);
foreach (var application in applications)
{
yield return application;
}
}
public virtual async ValueTask RemoveAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
await Cache.RemoveAsync($"{nameof(FindByClientIdAsync)}_{await Store.GetClientIdAsync(application, cancellationToken)}", token: cancellationToken);
await Cache.RemoveAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(application, cancellationToken)}", token: cancellationToken);
var redirectUris = await Store.GetRedirectUrisAsync(application, cancellationToken);
await ArrayCache.RemoveManyAsync(redirectUris.Select(address => $"{nameof(FindByRedirectUriAsync)}_{address}").ToArray(), token: cancellationToken);
var postLogoutRedirectUris = await Store.GetPostLogoutRedirectUrisAsync(application, cancellationToken);
await ArrayCache.RemoveManyAsync(postLogoutRedirectUris.Select(address => $"{nameof(FindByPostLogoutRedirectUriAsync)}_{address}").ToArray(), token: cancellationToken);
}
}

221
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/AbpOpenIddictApplicationStore.cs

@ -8,24 +8,23 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using OpenIddict.Abstractions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.OpenIddict.Tokens;
using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Applications;
public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictApplicationRepository>, IOpenIddictApplicationStore<OpenIddictApplication>, IScopedDependency
public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictApplicationRepository>, IOpenIddictApplicationStore<OpenIddictApplicationModel>
{
protected IOpenIddictTokenRepository TokenRepository { get; }
public AbpOpenIddictApplicationStore(
IOpenIddictApplicationRepository repository,
IUnitOfWorkManager unitOfWorkManager,
IMemoryCache cache,
IOpenIddictTokenRepository tokenRepository)
: base(repository, unitOfWorkManager, cache)
IOpenIddictTokenRepository tokenRepository,
IGuidGenerator guidGenerator)
: base(repository, unitOfWorkManager, guidGenerator)
{
TokenRepository = tokenRepository;
}
@ -35,21 +34,19 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return await Repository.GetCountAsync(cancellationToken);
}
public async ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplicationModel>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
return await Repository.CountAsync(query, cancellationToken);
throw new NotSupportedException();
}
public async ValueTask CreateAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public async ValueTask CreateAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
await Repository.InsertAsync(application, autoSave: true, cancellationToken: cancellationToken);
await Repository.InsertAsync(application.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
}
public async ValueTask DeleteAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public async ValueTask DeleteAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -57,27 +54,27 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
{
await TokenRepository.DeleteManyByApplicationIdAsync(application.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(application, cancellationToken: cancellationToken);
await Repository.DeleteAsync(application.Id, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
}
}
public async ValueTask<OpenIddictApplication> FindByIdAsync(string identifier, CancellationToken cancellationToken)
public async ValueTask<OpenIddictApplicationModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindAsync(ConvertIdentifierFromString(identifier), cancellationToken: cancellationToken);
return (await Repository.FindAsync(ConvertIdentifierFromString(identifier), cancellationToken: cancellationToken)).ToModel();
}
public async ValueTask<OpenIddictApplication> FindByClientIdAsync(string identifier, CancellationToken cancellationToken)
public async ValueTask<OpenIddictApplicationModel> FindByClientIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByClientIdAsync(identifier, cancellationToken: cancellationToken);
return (await Repository.FindByClientIdAsync(identifier, cancellationToken: cancellationToken)).ToModel();
}
public async IAsyncEnumerable<OpenIddictApplication> FindByPostLogoutRedirectUriAsync(string address, [EnumeratorCancellation] CancellationToken cancellationToken)
public async IAsyncEnumerable<OpenIddictApplicationModel> FindByPostLogoutRedirectUriAsync(string address, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(address, nameof(address));
@ -85,71 +82,69 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
foreach (var application in applications)
{
var addresses = await GetPostLogoutRedirectUrisAsync(application, cancellationToken);
var addresses = await GetPostLogoutRedirectUrisAsync(application.ToModel(), cancellationToken);
if (addresses.Contains(address, StringComparer.Ordinal))
{
yield return application;
yield return application.ToModel();
}
}
}
public async IAsyncEnumerable<OpenIddictApplication> FindByRedirectUriAsync(string address, [EnumeratorCancellation] CancellationToken cancellationToken)
public async IAsyncEnumerable<OpenIddictApplicationModel> FindByRedirectUriAsync(string address, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(address, nameof(address));
var applications = await Repository.FindByRedirectUriAsync(address, cancellationToken);
foreach (var application in applications)
{
var addresses = await GetRedirectUrisAsync(application, cancellationToken);
var addresses = await GetRedirectUrisAsync(application.ToModel(), cancellationToken);
if (addresses.Contains(address, StringComparer.Ordinal))
{
yield return application;
yield return application.ToModel();
}
}
}
public async ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
public ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplicationModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
return await Repository.GetAsync(query, state, cancellationToken);
throw new NotSupportedException();
}
public ValueTask<string> GetClientIdAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<string> GetClientIdAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
return new ValueTask<string>(application.ClientId);
}
public ValueTask<string> GetClientSecretAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<string> GetClientSecretAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
return new ValueTask<string>(application.ClientSecret);
}
public ValueTask<string> GetClientTypeAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<string> GetClientTypeAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
return new ValueTask<string>(application.Type);
}
public ValueTask<string> GetConsentTypeAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<string> GetConsentTypeAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
return new ValueTask<string>(application.ConsentType);
}
public ValueTask<string> GetDisplayNameAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<string> GetDisplayNameAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
return new ValueTask<string>(application.DisplayName);
}
public ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -158,15 +153,8 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(ImmutableDictionary.Create<CultureInfo, string>());
}
// Note: parsing the stringified display names is an expensive operation.
// To mitigate that, the resulting object is stored in the memory cache.
var key = string.Concat("7762c378-c113-4564-b14b-1402b3949aaa", "\x1e", application.DisplayNames);
var names = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(application.DisplayNames))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(application.DisplayNames);
var builder = ImmutableDictionary.CreateBuilder<CultureInfo, string>();
foreach (var property in document.RootElement.EnumerateObject())
@ -180,20 +168,18 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
builder[CultureInfo.GetCultureInfo(property.Name)] = value;
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(names);
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(builder.ToImmutable());
}
}
public ValueTask<string> GetIdAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<string> GetIdAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
return new ValueTask<string>(ConvertIdentifierToString(application.Id));
}
public ValueTask<ImmutableArray<string>> GetPermissionsAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<string>> GetPermissionsAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -202,15 +188,8 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return new ValueTask<ImmutableArray<string>>(ImmutableArray.Create<string>());
}
// Note: parsing the stringified permissions is an expensive operation.
// To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat("0347e0aa-3a26-410a-97e8-a83bdeb21a1f", "\x1e", application.Permissions);
var permissions = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(application.Permissions))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(application.Permissions);
var builder = ImmutableArray.CreateBuilder<string>(document.RootElement.GetArrayLength());
foreach (var element in document.RootElement.EnumerateArray())
@ -224,13 +203,11 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
builder.Add(value);
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableArray<string>>(permissions);
return new ValueTask<ImmutableArray<string>>(builder.ToImmutable());
}
}
public ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<string>> GetPostLogoutRedirectUrisAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -239,15 +216,8 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return new ValueTask<ImmutableArray<string>>(ImmutableArray.Create<string>());
}
// Note: parsing the stringified addresses is an expensive operation.
// To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat("fb14dfb9-9216-4b77-bfa9-7e85f8201ff4", "\x1e", application.PostLogoutRedirectUris);
var addresses = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(application.PostLogoutRedirectUris))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(application.PostLogoutRedirectUris);
var builder = ImmutableArray.CreateBuilder<string>(document.RootElement.GetArrayLength());
foreach (var element in document.RootElement.EnumerateArray())
@ -261,13 +231,11 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
builder.Add(value);
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableArray<string>>(addresses);
return new ValueTask<ImmutableArray<string>>(builder.ToImmutable());
};
}
public ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -276,29 +244,19 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
// To mitigate that, the resulting object is stored in the memory cache.
var key = string.Concat("2e3e9680-5654-48d8-a27d-b8bb4f0f1d50", "\x1e", application.Properties);
var properties = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(application.Properties))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(application.Properties);
var builder = ImmutableDictionary.CreateBuilder<string, JsonElement>();
foreach (var property in document.RootElement.EnumerateObject())
{
builder[property.Name] = property.Value.Clone();
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(builder.ToImmutable());
}
}
public ValueTask<ImmutableArray<string>> GetRedirectUrisAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<string>> GetRedirectUrisAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -307,15 +265,8 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return new ValueTask<ImmutableArray<string>>(ImmutableArray.Create<string>());
}
// Note: parsing the stringified addresses is an expensive operation.
// To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat("851d6f08-2ee0-4452-bbe5-ab864611ecaa", "\x1e", application.RedirectUris);
var addresses = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(application.RedirectUris))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(application.RedirectUris);
var builder = ImmutableArray.CreateBuilder<string>(document.RootElement.GetArrayLength());
foreach (var element in document.RootElement.EnumerateArray())
@ -329,13 +280,11 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
builder.Add(value);
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableArray<string>>(addresses);
return new ValueTask<ImmutableArray<string>>( builder.ToImmutable());
}
}
public ValueTask<ImmutableArray<string>> GetRequirementsAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public ValueTask<ImmutableArray<string>> GetRequirementsAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -344,15 +293,8 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return new ValueTask<ImmutableArray<string>>(ImmutableArray.Create<string>());
}
// Note: parsing the stringified requirements is an expensive operation.
// To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat("b4808a89-8969-4512-895f-a909c62a8995", "\x1e", application.Requirements);
var requirements = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(application.Requirements))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(application.Requirements);
var builder = ImmutableArray.CreateBuilder<string>(document.RootElement.GetArrayLength());
foreach (var element in document.RootElement.EnumerateArray())
@ -366,45 +308,33 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
builder.Add(value);
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableArray<string>>(requirements);
return new ValueTask<ImmutableArray<string>>(builder.ToImmutable());
}
}
public ValueTask<OpenIddictApplication> InstantiateAsync(CancellationToken cancellationToken)
public ValueTask<OpenIddictApplicationModel> InstantiateAsync(CancellationToken cancellationToken)
{
try
{
return new ValueTask<OpenIddictApplication>(Activator.CreateInstance<OpenIddictApplication>());
}
catch (MemberAccessException exception)
return new ValueTask<OpenIddictApplicationModel>(new OpenIddictApplicationModel
{
return new ValueTask<OpenIddictApplication>(Task.FromException<OpenIddictApplication>(exception));
}
Id = GuidGenerator.Create()
});
}
public async IAsyncEnumerable<OpenIddictApplication> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
public async IAsyncEnumerable<OpenIddictApplicationModel> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var applications = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var application in applications)
{
yield return application;
yield return application.ToModel();
}
}
public async IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, [EnumeratorCancellation] CancellationToken cancellationToken)
public IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplicationModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
var applications = await Repository.ListAsync(query, state, cancellationToken);
foreach (var application in applications)
{
yield return application;
}
throw new NotSupportedException();
}
public virtual ValueTask SetClientIdAsync(OpenIddictApplication application, string identifier, CancellationToken cancellationToken)
public virtual ValueTask SetClientIdAsync(OpenIddictApplicationModel application, string identifier, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -412,7 +342,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetClientSecretAsync(OpenIddictApplication application, string secret, CancellationToken cancellationToken)
public virtual ValueTask SetClientSecretAsync(OpenIddictApplicationModel application, string secret, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -420,7 +350,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetClientTypeAsync(OpenIddictApplication application, string type, CancellationToken cancellationToken)
public virtual ValueTask SetClientTypeAsync(OpenIddictApplicationModel application, string type, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -428,7 +358,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetConsentTypeAsync(OpenIddictApplication application, string type, CancellationToken cancellationToken)
public virtual ValueTask SetConsentTypeAsync(OpenIddictApplicationModel application, string type, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -436,7 +366,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetDisplayNameAsync(OpenIddictApplication application, string name, CancellationToken cancellationToken)
public virtual ValueTask SetDisplayNameAsync(OpenIddictApplicationModel application, string name, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -444,8 +374,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetDisplayNamesAsync(OpenIddictApplication application, ImmutableDictionary<CultureInfo, string> names,
CancellationToken cancellationToken)
public virtual ValueTask SetDisplayNamesAsync(OpenIddictApplicationModel application, ImmutableDictionary<CultureInfo, string> names, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -469,7 +398,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetPermissionsAsync(OpenIddictApplication application, ImmutableArray<string> permissions,
public virtual ValueTask SetPermissionsAsync(OpenIddictApplicationModel application, ImmutableArray<string> permissions,
CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -493,7 +422,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetPostLogoutRedirectUrisAsync(OpenIddictApplication application, ImmutableArray<string> addresses,
public virtual ValueTask SetPostLogoutRedirectUrisAsync(OpenIddictApplicationModel application, ImmutableArray<string> addresses,
CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -517,7 +446,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetPropertiesAsync(OpenIddictApplication application, ImmutableDictionary<string, JsonElement> properties,
public virtual ValueTask SetPropertiesAsync(OpenIddictApplicationModel application, ImmutableDictionary<string, JsonElement> properties,
CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -542,7 +471,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetRedirectUrisAsync(OpenIddictApplication application, ImmutableArray<string> addresses,
public virtual ValueTask SetRedirectUrisAsync(OpenIddictApplicationModel application, ImmutableArray<string> addresses,
CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -566,7 +495,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual ValueTask SetRequirementsAsync(OpenIddictApplication application, ImmutableArray<string> requirements,
public virtual ValueTask SetRequirementsAsync(OpenIddictApplicationModel application, ImmutableArray<string> requirements,
CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
@ -590,10 +519,12 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
return default;
}
public virtual async ValueTask UpdateAsync(OpenIddictApplication application, CancellationToken cancellationToken)
public virtual async ValueTask UpdateAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
await Repository.UpdateAsync(application, autoSave: true, cancellationToken: cancellationToken);
var entity = await Repository.GetAsync(application.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(application.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
}

7
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/IOpenIddictApplicationRepository.cs

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -9,17 +8,11 @@ namespace Volo.Abp.OpenIddict.Applications;
public interface IOpenIddictApplicationRepository : IBasicRepository<OpenIddictApplication, Guid>
{
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
}

9
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/OpenIddictApplication.cs

@ -5,6 +5,15 @@ namespace Volo.Abp.OpenIddict.Applications;
public class OpenIddictApplication : FullAuditedAggregateRoot<Guid>
{
public OpenIddictApplication()
{
}
public OpenIddictApplication(Guid id)
: base(id)
{
}
/// <summary>
/// Gets or sets the client identifier associated with the current application.
/// </summary>

68
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/OpenIddictApplicationExtensions.cs

@ -0,0 +1,68 @@
namespace Volo.Abp.OpenIddict.Applications;
public static class OpenIddictApplicationExtensions
{
public static OpenIddictApplication ToEntity(this OpenIddictApplicationModel model)
{
Check.NotNull(model, nameof(model));
return new OpenIddictApplication(model.Id)
{
ClientId = model.ClientId,
ClientSecret = model.ClientSecret,
ConsentType = model.ConsentType,
DisplayName = model.DisplayName,
DisplayNames = model.DisplayNames,
Permissions = model.Permissions,
PostLogoutRedirectUris = model.PostLogoutRedirectUris,
Properties = model.Properties,
RedirectUris = model.RedirectUris,
Requirements = model.Requirements,
Type = model.Type
};
}
public static OpenIddictApplication ToEntity(this OpenIddictApplicationModel model, OpenIddictApplication entity)
{
Check.NotNull(model, nameof(model));
Check.NotNull(entity, nameof(entity));
entity.ClientId = model.ClientId;
entity.ClientSecret = model.ClientSecret;
entity.ConsentType = model.ConsentType;
entity.DisplayName = model.DisplayName;
entity.DisplayNames = model.DisplayNames;
entity.Permissions = model.Permissions;
entity.PostLogoutRedirectUris = model.PostLogoutRedirectUris;
entity.Properties = model.Properties;
entity.RedirectUris = model.RedirectUris;
entity.Requirements = model.Requirements;
entity.Type = model.Type;
return entity;
}
public static OpenIddictApplicationModel ToModel(this OpenIddictApplication model)
{
if(model == null)
{
return null;
}
return new OpenIddictApplicationModel
{
Id = model.Id,
ClientId = model.ClientId,
ClientSecret = model.ClientSecret,
ConsentType = model.ConsentType,
DisplayName = model.DisplayName,
DisplayNames = model.DisplayNames,
Permissions = model.Permissions,
PostLogoutRedirectUris = model.PostLogoutRedirectUris,
Properties = model.Properties,
RedirectUris = model.RedirectUris,
Requirements = model.Requirements,
Type = model.Type
};
}
}

74
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Applications/OpenIddictApplicationModel.cs

@ -0,0 +1,74 @@
using System;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.OpenIddict.Applications;
[Serializable, IgnoreMultiTenancy]
public class OpenIddictApplicationModel
{
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the client identifier associated with the current application.
/// </summary>
public virtual string ClientId { get; set; }
/// <summary>
/// Gets or sets the client secret associated with the current application.
/// Note: depending on the application manager used to create this instance,
/// this property may be hashed or encrypted for security reasons.
/// </summary>
public virtual string ClientSecret { get; set; }
/// <summary>
/// Gets or sets the consent type associated with the current application.
/// </summary>
public virtual string ConsentType { get; set; }
/// <summary>
/// Gets or sets the display name associated with the current application.
/// </summary>
public virtual string DisplayName { get; set; }
/// <summary>
/// Gets or sets the localized display names
/// associated with the current application,
/// serialized as a JSON object.
/// </summary>
public virtual string DisplayNames { get; set; }
/// <summary>
/// Gets or sets the permissions associated with the
/// current application, serialized as a JSON array.
/// </summary>
public virtual string Permissions { get; set; }
/// <summary>
/// Gets or sets the logout callback URLs associated with
/// the current application, serialized as a JSON array.
/// </summary>
public virtual string PostLogoutRedirectUris { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current application.
/// </summary>
public virtual string Properties { get; set; }
/// <summary>
/// Gets or sets the callback URLs associated with the
/// current application, serialized as a JSON array.
/// </summary>
public virtual string RedirectUris { get; set; }
/// <summary>
/// Gets or sets the requirements associated with the
/// current application, serialized as a JSON array.
/// </summary>
public virtual string Requirements { get; set; }
/// <summary>
/// Gets or sets the application type associated with the current application.
/// </summary>
public virtual string Type { get; set; }
}

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

@ -0,0 +1,182 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using OpenIddict.Abstractions;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.OpenIddict.Authorizations;
public class AbpOpenIddictAuthorizationCache : AbpOpenIddictCacheBase<OpenIddictAuthorization, OpenIddictAuthorizationModel, IOpenIddictAuthorizationStore<OpenIddictAuthorizationModel>>,
IOpenIddictAuthorizationCache<OpenIddictAuthorizationModel>,
ITransientDependency
{
public AbpOpenIddictAuthorizationCache(
IDistributedCache<OpenIddictAuthorizationModel> cache,
IDistributedCache<OpenIddictAuthorizationModel[]> arrayCache,
IOpenIddictAuthorizationStore<OpenIddictAuthorizationModel> store)
: base(cache, arrayCache, store)
{
}
public async ValueTask AddAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
await RemoveAsync(authorization, cancellationToken);
await Cache.SetAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(authorization, cancellationToken)}", authorization, token: cancellationToken);
}
public async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, [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 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 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 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.
await foreach (var authorization in Store.FindAsync(subject, client, status, type, scopes, cancellationToken))
{
await AddAsync(authorization, cancellationToken);
yield return authorization;
}
}
public async IAsyncEnumerable<OpenIddictAuthorizationModel> FindByApplicationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var authorizations = await ArrayCache.GetOrAddAsync($"{nameof(FindByApplicationIdAsync)}_{identifier}", async () =>
{
var applications = new List<OpenIddictAuthorizationModel>();
await foreach (var authorization in Store.FindByApplicationIdAsync(identifier, cancellationToken))
{
applications.Add(authorization);
await AddAsync(authorization, cancellationToken);
}
return applications.ToArray();
}, token: cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
}
}
public async ValueTask<OpenIddictAuthorizationModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{identifier}",
async () => await Store.FindByIdAsync(identifier, cancellationToken), token: cancellationToken);
}
public async IAsyncEnumerable<OpenIddictAuthorizationModel> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
var authorizations = await ArrayCache.GetOrAddAsync($"{nameof(FindBySubjectAsync)}_{subject}", async () =>
{
var applications = new List<OpenIddictAuthorizationModel>();
await foreach (var authorization in Store.FindBySubjectAsync(subject, cancellationToken))
{
applications.Add(authorization);
await AddAsync(authorization, cancellationToken);
}
return applications.ToArray();
}, token: cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
}
}
public virtual async ValueTask RemoveAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
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(FindByApplicationIdAsync)}_{await Store.GetApplicationIdAsync(authorization, cancellationToken)}",
$"{nameof(FindBySubjectAsync)}_{await Store.GetSubjectAsync(authorization, cancellationToken)}"
}, token: cancellationToken);
await Cache.RemoveAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(authorization, cancellationToken)}", token: cancellationToken);
}
}

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

@ -7,16 +7,15 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using OpenIddict.Abstractions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.OpenIddict.Tokens;
using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Authorizations;
public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddictAuthorizationRepository>, IOpenIddictAuthorizationStore<OpenIddictAuthorization>, IScopedDependency
public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddictAuthorizationRepository>, IOpenIddictAuthorizationStore<OpenIddictAuthorizationModel>
{
protected IOpenIddictApplicationRepository ApplicationRepository { get; }
protected IOpenIddictTokenRepository TokenRepository { get; }
@ -24,10 +23,10 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
public AbpOpenIddictAuthorizationStore(
IOpenIddictAuthorizationRepository repository,
IUnitOfWorkManager unitOfWorkManager,
IMemoryCache cache,
IGuidGenerator guidGenerator,
IOpenIddictApplicationRepository applicationRepository,
IOpenIddictTokenRepository tokenRepository)
: base(repository, unitOfWorkManager, cache)
: base(repository, unitOfWorkManager, guidGenerator)
{
ApplicationRepository = applicationRepository;
TokenRepository = tokenRepository;
@ -38,21 +37,19 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return await Repository.GetCountAsync(cancellationToken);
}
public virtual async ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorizationModel>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
return await Repository.CountAsync(query, cancellationToken);
throw new NotSupportedException();
}
public virtual async ValueTask CreateAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
await Repository.InsertAsync(authorization, autoSave: true, cancellationToken: cancellationToken);
await Repository.InsertAsync(authorization.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
}
public virtual async ValueTask DeleteAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual async ValueTask DeleteAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -60,13 +57,13 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
{
await TokenRepository.DeleteManyByAuthorizationIdAsync(authorization.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(authorization, cancellationToken: cancellationToken);
await Repository.DeleteAsync(authorization.Id, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
@ -74,11 +71,11 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
yield return authorization.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> FindAsync(string subject, string client, string status, [EnumeratorCancellation] CancellationToken cancellationToken)
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));
@ -87,11 +84,11 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
yield return authorization.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> FindAsync(string subject, string client, string status, string type, [EnumeratorCancellation] CancellationToken cancellationToken)
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));
@ -101,11 +98,11 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
yield return authorization.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> FindAsync(string subject, string client, string status, string type, ImmutableArray<string> scopes, [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));
@ -116,43 +113,43 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
foreach (var authorization in authorizations)
{
if (new HashSet<string>(await GetScopesAsync(authorization, cancellationToken), StringComparer.Ordinal).IsSupersetOf(scopes))
if (new HashSet<string>(await GetScopesAsync(authorization.ToModel(), cancellationToken), StringComparer.Ordinal).IsSupersetOf(scopes))
{
yield return authorization;
yield return authorization.ToModel();
}
}
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> FindByApplicationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindByApplicationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var authorizations = await Repository.FindByApplicationIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
yield return authorization.ToModel();
}
}
public virtual async ValueTask<OpenIddictAuthorization> FindByIdAsync(string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<OpenIddictAuthorizationModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
return (await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken)).ToModel();
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
var authorizations = await Repository.FindBySubjectAsync(subject, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
yield return authorization.ToModel();
}
}
public virtual ValueTask <string> GetApplicationIdAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <string> GetApplicationIdAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -161,14 +158,12 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
: null);
}
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
public virtual ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorizationModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
return await Repository.GetAsync(query, state, cancellationToken);
throw new NotSupportedException();
}
public virtual ValueTask <DateTimeOffset?> GetCreationDateAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <DateTimeOffset?> GetCreationDateAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -177,14 +172,14 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
: new ValueTask<DateTimeOffset?>(DateTime.SpecifyKind(authorization.CreationDate.Value, DateTimeKind.Utc));
}
public virtual ValueTask <string> GetIdAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <string> GetIdAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
return new ValueTask<string>(ConvertIdentifierToString(authorization.Id));
}
public virtual ValueTask <ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -193,15 +188,8 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
// To mitigate that, the resulting object is stored in the memory cache.
var key = string.Concat("68056e1a-dbcf-412b-9a6a-d791c7dbe726", "\x1e", authorization.Properties);
var properties = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(authorization.Properties))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(authorization.Properties);
var builder = ImmutableDictionary.CreateBuilder<string, JsonElement>();
foreach (var property in document.RootElement.EnumerateObject())
@ -209,13 +197,11 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
builder[property.Name] = property.Value.Clone();
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(builder.ToImmutable());
}
}
public virtual ValueTask <ImmutableArray<string>> GetScopesAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <ImmutableArray<string>> GetScopesAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -224,15 +210,8 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return new ValueTask<ImmutableArray<string>>(ImmutableArray.Create<string>());
}
// Note: parsing the stringified scopes is an expensive operation.
// To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat("2ba4ab0f-e2ec-4d48-b3bd-28e2bb660c75", "\x1e", authorization.Scopes);
var scopes = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(authorization.Scopes))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(authorization.Scopes);
var builder = ImmutableArray.CreateBuilder<string>(document.RootElement.GetArrayLength());
foreach (var element in document.RootElement.EnumerateArray())
@ -246,61 +225,51 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
builder.Add(value);
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableArray<string>>(scopes);
return new ValueTask<ImmutableArray<string>>(builder.ToImmutable());
}
}
public virtual ValueTask <string> GetStatusAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <string> GetStatusAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
return new ValueTask<string>(authorization.Status);
}
public virtual ValueTask <string> GetSubjectAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <string> GetSubjectAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
return new ValueTask<string>(authorization.Subject);
}
public virtual ValueTask <string> GetTypeAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual ValueTask <string> GetTypeAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
return new ValueTask<string>(authorization.Type);
}
public virtual ValueTask <OpenIddictAuthorization> InstantiateAsync(CancellationToken cancellationToken)
public virtual ValueTask <OpenIddictAuthorizationModel> InstantiateAsync(CancellationToken cancellationToken)
{
try
{
return new ValueTask<OpenIddictAuthorization>(Activator.CreateInstance<OpenIddictAuthorization>());
}
catch (MemberAccessException exception)
return new ValueTask<OpenIddictAuthorizationModel>(new OpenIddictAuthorizationModel
{
return new ValueTask<OpenIddictAuthorization>(Task.FromException<OpenIddictAuthorization>(exception));
}
Id = GuidGenerator.Create()
});
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictAuthorizationModel> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var authorizations = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
yield return authorization.ToModel();
}
}
public virtual async IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorizationModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
var authorizations = await Repository.ListAsync(query, state, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
}
throw new NotSupportedException();
}
public virtual async ValueTask PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken)
@ -325,7 +294,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
}
}
public virtual async ValueTask SetApplicationIdAsync(OpenIddictAuthorization authorization, string identifier, CancellationToken cancellationToken)
public virtual async ValueTask SetApplicationIdAsync(OpenIddictAuthorizationModel authorization, string identifier, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -340,7 +309,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
}
}
public virtual ValueTask SetCreationDateAsync(OpenIddictAuthorization authorization, DateTimeOffset? date, CancellationToken cancellationToken)
public virtual ValueTask SetCreationDateAsync(OpenIddictAuthorizationModel authorization, DateTimeOffset? date, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -349,7 +318,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return default;
}
public virtual ValueTask SetPropertiesAsync(OpenIddictAuthorization authorization, ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
public virtual ValueTask SetPropertiesAsync(OpenIddictAuthorizationModel authorization, ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
if (properties is null || properties.IsEmpty)
{
@ -371,7 +340,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return default;
}
public virtual ValueTask SetScopesAsync(OpenIddictAuthorization authorization, ImmutableArray<string> scopes, CancellationToken cancellationToken)
public virtual ValueTask SetScopesAsync(OpenIddictAuthorizationModel authorization, ImmutableArray<string> scopes, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -394,7 +363,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return default;
}
public virtual ValueTask SetStatusAsync(OpenIddictAuthorization authorization, string status, CancellationToken cancellationToken)
public virtual ValueTask SetStatusAsync(OpenIddictAuthorizationModel authorization, string status, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -403,7 +372,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return default;
}
public virtual ValueTask SetSubjectAsync(OpenIddictAuthorization authorization, string subject, CancellationToken cancellationToken)
public virtual ValueTask SetSubjectAsync(OpenIddictAuthorizationModel authorization, string subject, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -412,7 +381,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return default;
}
public virtual ValueTask SetTypeAsync(OpenIddictAuthorization authorization, string type, CancellationToken cancellationToken)
public virtual ValueTask SetTypeAsync(OpenIddictAuthorizationModel authorization, string type, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
@ -421,10 +390,12 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
return default;
}
public virtual async ValueTask UpdateAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
public virtual async ValueTask UpdateAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
await Repository.UpdateAsync(authorization, autoSave: true, cancellationToken: cancellationToken);
var entity = await Repository.GetAsync(authorization.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(authorization.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
}

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

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -9,8 +8,6 @@ namespace Volo.Abp.OpenIddict.Authorizations;
public interface IOpenIddictAuthorizationRepository : IBasicRepository<OpenIddictAuthorization, Guid>
{
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default);
@ -23,11 +20,7 @@ public interface IOpenIddictAuthorizationRepository : IBasicRepository<OpenIddic
Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default);
}

9
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/OpenIddictAuthorization.cs

@ -5,6 +5,15 @@ namespace Volo.Abp.OpenIddict.Authorizations;
public class OpenIddictAuthorization : FullAuditedAggregateRoot<Guid>
{
public OpenIddictAuthorization()
{
}
public OpenIddictAuthorization(Guid id)
: base(id)
{
}
/// <summary>
/// Gets or sets the application associated with the current authorization.
/// </summary>

56
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/OpenIddictAuthorizationExtensions.cs

@ -0,0 +1,56 @@
namespace Volo.Abp.OpenIddict.Authorizations;
public static class OpenIddictAuthorizationExtensions
{
public static OpenIddictAuthorization ToEntity(this OpenIddictAuthorizationModel model)
{
Check.NotNull(model, nameof(model));
return new OpenIddictAuthorization(model.Id)
{
ApplicationId = model.ApplicationId,
CreationDate = model.CreationDate,
Properties = model.Properties,
Scopes = model.Scopes,
Status = model.Status,
Subject = model.Subject,
Type = model.Type
};
}
public static OpenIddictAuthorization ToEntity(this OpenIddictAuthorizationModel model, OpenIddictAuthorization entity)
{
Check.NotNull(model, nameof(model));
Check.NotNull(entity, nameof(entity));
entity.ApplicationId = model.ApplicationId;
entity.CreationDate = model.CreationDate;
entity.Properties = model.Properties;
entity.Scopes = model.Scopes;
entity.Status = model.Status;
entity.Subject = model.Subject;
entity.Type = model.Type;
return entity;
}
public static OpenIddictAuthorizationModel ToModel(this OpenIddictAuthorization model)
{
if(model == null)
{
return null;
}
return new OpenIddictAuthorizationModel
{
Id = model.Id,
ApplicationId = model.ApplicationId,
CreationDate = model.CreationDate,
Properties = model.Properties,
Scopes = model.Scopes,
Status = model.Status,
Subject = model.Subject,
Type = model.Type
};
}
}

47
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Authorizations/OpenIddictAuthorizationModel.cs

@ -0,0 +1,47 @@
using System;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.OpenIddict.Authorizations;
[Serializable, IgnoreMultiTenancy]
public class OpenIddictAuthorizationModel
{
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the application associated with the current authorization.
/// </summary>
public virtual Guid? ApplicationId { get; set; }
/// <summary>
/// Gets or sets the UTC creation date of the current authorization.
/// </summary>
public virtual DateTime? CreationDate { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current authorization.
/// </summary>
public virtual string Properties { get; set; }
/// <summary>
/// Gets or sets the scopes associated with the current
/// authorization, serialized as a JSON array.
/// </summary>
public virtual string Scopes { get; set; }
/// <summary>
/// Gets or sets the status of the current authorization.
/// </summary>
public virtual string Status { get; set; }
/// <summary>
/// Gets or sets the subject associated with the current authorization.
/// </summary>
public virtual string Subject { get; set; }
/// <summary>
/// Gets or sets the type of the current authorization.
/// </summary>
public virtual string Type { get; set; }
}

111
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeCache.cs

@ -0,0 +1,111 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using OpenIddict.Abstractions;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.OpenIddict.Scopes;
public class AbpOpenIddictScopeCacheAbpOpenIddictAuthorizationCache : AbpOpenIddictCacheBase<OpenIddictScope, OpenIddictScopeModel, IOpenIddictScopeStore<OpenIddictScopeModel>>,
IOpenIddictScopeCache<OpenIddictScopeModel>,
ITransientDependency
{
public AbpOpenIddictScopeCacheAbpOpenIddictAuthorizationCache(
IDistributedCache<OpenIddictScopeModel> cache,
IDistributedCache<OpenIddictScopeModel[]> arrayCache,
IOpenIddictScopeStore<OpenIddictScopeModel> store)
: base(cache, arrayCache, store)
{
}
public virtual async ValueTask AddAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
await RemoveAsync(scope, cancellationToken);
await Cache.SetAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(scope, cancellationToken)}", scope, token: cancellationToken);
await Cache.SetAsync($"{nameof(FindByNameAsync)}_{await Store.GetNameAsync(scope, cancellationToken)}", scope, token: cancellationToken);
}
public virtual async ValueTask<OpenIddictScopeModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{identifier}", async () =>
{
var scope = await Store.FindByIdAsync(identifier, cancellationToken);
if (scope != null)
{
await AddAsync(scope, cancellationToken);
}
return scope;
}, token: cancellationToken);
}
public virtual async ValueTask<OpenIddictScopeModel> FindByNameAsync(string name, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(name, nameof(name));
return await Cache.GetOrAddAsync($"{nameof(FindByNameAsync)}_{name}", async () =>
{
var scope = await Store.FindByNameAsync(name, cancellationToken);
if (scope != null)
{
await AddAsync(scope, cancellationToken);
}
return scope;
}, token: cancellationToken);
}
public virtual async IAsyncEnumerable<OpenIddictScopeModel> FindByNamesAsync(ImmutableArray<string> names, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(names, nameof(names));
// Note: this method is only partially cached.
await foreach (var scope in Store.FindByNamesAsync(names, cancellationToken))
{
await AddAsync(scope, cancellationToken);
yield return scope;
}
}
public virtual async IAsyncEnumerable<OpenIddictScopeModel> FindByResourceAsync(string resource, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(resource, nameof(resource));
var scopes = await ArrayCache.GetOrAddAsync($"{nameof(FindByResourceAsync)}_{resource}", async () =>
{
var scopes = new List<OpenIddictScopeModel>();
await foreach (var scope in Store.FindByResourceAsync(resource, cancellationToken))
{
scopes.Add(scope);
await AddAsync(scope, cancellationToken);
}
return scopes.ToArray();
}, token: cancellationToken);
foreach (var scope in scopes)
{
yield return scope;
}
}
public virtual async ValueTask RemoveAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
var resources = new List<string>();
foreach (var resource in await Store.GetResourcesAsync(scope, cancellationToken))
{
resources.Add($"{nameof(FindByResourceAsync)}_{resource}");
}
await ArrayCache.RemoveManyAsync(resources.ToArray(), token: cancellationToken);
await Cache.RemoveAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(scope, cancellationToken)}", token: cancellationToken);
await Cache.RemoveAsync($"{nameof(FindByNameAsync)}_{await Store.GetNameAsync(scope, cancellationToken)}", token: cancellationToken);
}
}

169
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/AbpOpenIddictScopeStore.cs

@ -7,20 +7,19 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using OpenIddict.Abstractions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Scopes;
public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRepository>, IOpenIddictScopeStore<OpenIddictScope>, IScopedDependency
public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRepository>, IOpenIddictScopeStore<OpenIddictScopeModel>
{
public AbpOpenIddictScopeStore(
public AbpOpenIddictScopeStore(
IOpenIddictScopeRepository repository,
IUnitOfWorkManager unitOfWorkManager,
IMemoryCache cache)
: base(repository, unitOfWorkManager, cache)
IGuidGenerator guidGenerator)
: base(repository, unitOfWorkManager, guidGenerator)
{
}
@ -30,42 +29,40 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return await Repository.GetCountAsync(cancellationToken);
}
public virtual async ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScope>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScopeModel>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
return await Repository.CountAsync(query, cancellationToken);
throw new NotSupportedException();
}
public virtual async ValueTask CreateAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
await Repository.InsertAsync(scope, autoSave: true, cancellationToken: cancellationToken);
await Repository.InsertAsync(scope.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
}
public virtual async ValueTask DeleteAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual async ValueTask DeleteAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
await Repository.DeleteAsync(scope, autoSave: true, cancellationToken: cancellationToken);
await Repository.DeleteAsync(scope.Id, autoSave: true, cancellationToken: cancellationToken);
}
public virtual async ValueTask<OpenIddictScope> FindByIdAsync(string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<OpenIddictScopeModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
return (await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken)).ToModel();
}
public virtual async ValueTask<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken)
public virtual async ValueTask<OpenIddictScopeModel> FindByNameAsync(string name, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(name, nameof(name));
return await Repository.FindByNameAsync(name, cancellationToken);
return (await Repository.FindByNameAsync(name, cancellationToken)).ToModel();
}
public virtual async IAsyncEnumerable<OpenIddictScope> FindByNamesAsync(ImmutableArray<string> names, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictScopeModel> FindByNamesAsync(ImmutableArray<string> names, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(names, nameof(names));
foreach (var name in names)
@ -76,38 +73,38 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
var scopes = await Repository.FindByNamesAsync(names.ToArray(), cancellationToken);
foreach (var scope in scopes)
{
yield return scope;
yield return scope.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictScope> FindByResourceAsync(string resource, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictScopeModel> FindByResourceAsync(string resource, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(resource, nameof(resource));
var scopes = await Repository.FindByResourceAsync(resource, cancellationToken);
foreach (var scope in scopes)
{
var resources = await GetResourcesAsync(scope, cancellationToken);
var resources = await GetResourcesAsync(scope.ToModel(), cancellationToken);
if (resources.Contains(resource, StringComparer.Ordinal))
{
yield return scope;
yield return scope.ToModel();
}
}
}
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
public virtual ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScopeModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
return await Repository.GetAsync(query, state, cancellationToken);
throw new NotSupportedException();
}
public virtual ValueTask<string> GetDescriptionAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<string> GetDescriptionAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
return new ValueTask<string>(scope.Description);
}
public virtual ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<CultureInfo, string>> GetDescriptionsAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -116,15 +113,8 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(ImmutableDictionary.Create<CultureInfo, string>());
}
// Note: parsing the stringified descriptions is an expensive operation.
// To mitigate that, the resulting object is stored in the memory cache.
var key = string.Concat("42891062-8f69-43ba-9111-db7e8ded2553", "\x1e", scope.Descriptions);
var descriptions = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(scope.Descriptions))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(scope.Descriptions);
var builder = ImmutableDictionary.CreateBuilder<CultureInfo, string>();
foreach (var property in document.RootElement.EnumerateObject())
@ -138,20 +128,18 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
builder[CultureInfo.GetCultureInfo(property.Name)] = value;
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(descriptions);
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(builder.ToImmutable());
}
}
public virtual ValueTask<string> GetDisplayNameAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<string> GetDisplayNameAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
return new ValueTask<string>(scope.DisplayName);
}
public virtual ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<CultureInfo, string>> GetDisplayNamesAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -160,15 +148,8 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(ImmutableDictionary.Create<CultureInfo, string>());
}
// Note: parsing the stringified display names is an expensive operation.
// To mitigate that, the resulting object is stored in the memory cache.
var key = string.Concat("e17d437b-bdd2-43f3-974e-46d524f4bae1", "\x1e", scope.DisplayNames);
var names = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(scope.DisplayNames))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(scope.DisplayNames);
var builder = ImmutableDictionary.CreateBuilder<CultureInfo, string>();
foreach (var property in document.RootElement.EnumerateObject())
@ -182,27 +163,25 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
builder[CultureInfo.GetCultureInfo(property.Name)] = value;
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(names);
return new ValueTask<ImmutableDictionary<CultureInfo, string>>(builder.ToImmutable());
}
}
public virtual ValueTask<string> GetIdAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<string> GetIdAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
return new ValueTask<string>(ConvertIdentifierToString(scope.Id));
}
public virtual ValueTask<string> GetNameAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<string> GetNameAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
return new ValueTask<string>(scope.Name);
}
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -211,15 +190,8 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
// To mitigate that, the resulting object is stored in the memory cache.
var key = string.Concat("78d8dfdd-3870-442e-b62e-dc9bf6eaeff7", "\x1e", scope.Properties);
var properties = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(scope.Properties))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(scope.Properties);
var builder = ImmutableDictionary.CreateBuilder<string, JsonElement>();
foreach (var property in document.RootElement.EnumerateObject())
@ -227,13 +199,11 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
builder[property.Name] = property.Value.Clone();
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(builder.ToImmutable());
}
}
public virtual ValueTask<ImmutableArray<string>> GetResourcesAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableArray<string>> GetResourcesAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -242,15 +212,8 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return new ValueTask<ImmutableArray<string>>(ImmutableArray.Create<string>());
}
// Note: parsing the stringified resources is an expensive operation.
// To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat("b6148250-aede-4fb9-a621-07c9bcf238c3", "\x1e", scope.Resources);
var resources = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(scope.Resources))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(scope.Resources);
var builder = ImmutableArray.CreateBuilder<string>(document.RootElement.GetArrayLength());
foreach (var element in document.RootElement.EnumerateArray())
@ -264,45 +227,33 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
builder.Add(value);
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableArray<string>>(resources);
return new ValueTask<ImmutableArray<string>>(builder.ToImmutable());
}
}
public virtual ValueTask<OpenIddictScope> InstantiateAsync(CancellationToken cancellationToken)
public virtual ValueTask<OpenIddictScopeModel> InstantiateAsync(CancellationToken cancellationToken)
{
try
return new ValueTask<OpenIddictScopeModel>(new OpenIddictScopeModel
{
return new ValueTask<OpenIddictScope>(Activator.CreateInstance<OpenIddictScope>());
}
catch (MemberAccessException exception)
{
return new ValueTask<OpenIddictScope>(Task.FromException<OpenIddictScope>(exception));
}
Id = GuidGenerator.Create()
});
}
public virtual async IAsyncEnumerable<OpenIddictScope> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictScopeModel> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var scopes = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var scope in scopes)
{
yield return scope;
yield return scope.ToModel();
}
}
public async IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, [EnumeratorCancellation] CancellationToken cancellationToken)
public IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScopeModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
var scopes = await Repository.ListAsync(query, state, cancellationToken);
foreach (var scope in scopes)
{
yield return scope;
}
throw new NotSupportedException();
}
public virtual ValueTask SetDescriptionAsync(OpenIddictScope scope, string description, CancellationToken cancellationToken)
public virtual ValueTask SetDescriptionAsync(OpenIddictScopeModel scope, string description, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -311,7 +262,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return default;
}
public virtual ValueTask SetDescriptionsAsync(OpenIddictScope scope, ImmutableDictionary<CultureInfo, string> descriptions, CancellationToken cancellationToken)
public virtual ValueTask SetDescriptionsAsync(OpenIddictScopeModel scope, ImmutableDictionary<CultureInfo, string> descriptions, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -335,7 +286,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return default;
}
public virtual ValueTask SetDisplayNameAsync(OpenIddictScope scope, string name, CancellationToken cancellationToken)
public virtual ValueTask SetDisplayNameAsync(OpenIddictScopeModel scope, string name, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -344,7 +295,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return default;
}
public virtual ValueTask SetDisplayNamesAsync(OpenIddictScope scope, ImmutableDictionary<CultureInfo, string> names, CancellationToken cancellationToken)
public virtual ValueTask SetDisplayNamesAsync(OpenIddictScopeModel scope, ImmutableDictionary<CultureInfo, string> names, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -368,7 +319,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return default;
}
public virtual ValueTask SetNameAsync(OpenIddictScope scope, string name, CancellationToken cancellationToken)
public virtual ValueTask SetNameAsync(OpenIddictScopeModel scope, string name, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -377,7 +328,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return default;
}
public virtual ValueTask SetPropertiesAsync(OpenIddictScope scope, ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
public virtual ValueTask SetPropertiesAsync(OpenIddictScopeModel scope, ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -401,7 +352,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return default;
}
public virtual ValueTask SetResourcesAsync(OpenIddictScope scope, ImmutableArray<string> resources, CancellationToken cancellationToken)
public virtual ValueTask SetResourcesAsync(OpenIddictScopeModel scope, ImmutableArray<string> resources, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
@ -424,10 +375,12 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
return default;
}
public virtual async ValueTask UpdateAsync(OpenIddictScope scope, CancellationToken cancellationToken)
public virtual async ValueTask UpdateAsync(OpenIddictScopeModel scope, CancellationToken cancellationToken)
{
Check.NotNull(scope, nameof(scope));
await Repository.UpdateAsync(scope, autoSave: true, cancellationToken: cancellationToken);
var entity = await Repository.GetAsync(scope.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(scope.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
}

7
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/IOpenIddictScopeRepository.cs

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -9,8 +8,6 @@ namespace Volo.Abp.OpenIddict.Scopes;
public interface IOpenIddictScopeRepository : IBasicRepository<OpenIddictScope, Guid>
{
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken = default);
Task<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken = default);
@ -19,9 +16,5 @@ public interface IOpenIddictScopeRepository : IBasicRepository<OpenIddictScope,
Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
}

9
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/OpenIddictScope.cs

@ -5,6 +5,15 @@ namespace Volo.Abp.OpenIddict.Scopes;
public class OpenIddictScope : FullAuditedAggregateRoot<Guid>
{
public OpenIddictScope()
{
}
public OpenIddictScope(Guid id)
: base(id)
{
}
/// <summary>
/// Gets or sets the public description associated with the current scope.
/// </summary>

56
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/OpenIddictScopeExtensions.cs

@ -0,0 +1,56 @@
namespace Volo.Abp.OpenIddict.Scopes;
public static class OpenIddictScopeExtensions
{
public static OpenIddictScope ToEntity(this OpenIddictScopeModel model)
{
Check.NotNull(model, nameof(model));
return new OpenIddictScope(model.Id)
{
Description = model.Description,
Descriptions = model.Descriptions,
DisplayName = model.DisplayName,
DisplayNames = model.DisplayNames,
Name = model.Name,
Properties = model.Properties,
Resources = model.Resources
};
}
public static OpenIddictScope ToEntity(this OpenIddictScopeModel model, OpenIddictScope entity)
{
Check.NotNull(model, nameof(model));
Check.NotNull(entity, nameof(entity));
entity.Description = model.Description;
entity.Descriptions = model.Descriptions;
entity.DisplayName = model.DisplayName;
entity.DisplayNames = model.DisplayNames;
entity.Name = model.Name;
entity.Properties = model.Properties;
entity.Resources = model.Resources;
return entity;
}
public static OpenIddictScopeModel ToModel(this OpenIddictScope model)
{
if(model == null)
{
return null;
}
return new OpenIddictScopeModel
{
Id = model.Id,
Description = model.Description,
Descriptions = model.Descriptions,
DisplayName = model.DisplayName,
DisplayNames = model.DisplayNames,
Name = model.Name,
Properties = model.Properties,
Resources = model.Resources
};
}
}

50
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Scopes/OpenIddictScopeModel.cs

@ -0,0 +1,50 @@
using System;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.OpenIddict.Scopes;
[Serializable, IgnoreMultiTenancy]
public class OpenIddictScopeModel
{
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the public description associated with the current scope.
/// </summary>
public virtual string Description { get; set; }
/// <summary>
/// Gets or sets the localized public descriptions associated
/// with the current scope, serialized as a JSON object.
/// </summary>
public virtual string Descriptions { get; set; }
/// <summary>
/// Gets or sets the display name associated with the current scope.
/// </summary>
public virtual string DisplayName { get; set; }
/// <summary>
/// Gets or sets the localized display names
/// associated with the current application,
/// serialized as a JSON object.
/// </summary>
public virtual string DisplayNames { get; set; }
/// <summary>
/// Gets or sets the unique name associated with the current scope.
/// </summary>
public virtual string Name { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current scope.
/// </summary>
public virtual string Properties { get; set; }
/// <summary>
/// Gets or sets the resources associated with the
/// current scope, serialized as a JSON array.
/// </summary>
public virtual string Resources { get; set; }
}

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

@ -0,0 +1,210 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using OpenIddict.Abstractions;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.OpenIddict.Tokens;
public class AbpOpenIddictTokenCache : AbpOpenIddictCacheBase<OpenIddictToken, OpenIddictTokenModel, IOpenIddictTokenStore<OpenIddictTokenModel>>,
IOpenIddictTokenCache<OpenIddictTokenModel>,
ITransientDependency
{
public AbpOpenIddictTokenCache(
IDistributedCache<OpenIddictTokenModel> cache,
IDistributedCache<OpenIddictTokenModel[]> arrayCache,
IOpenIddictTokenStore<OpenIddictTokenModel> store)
: base(cache, arrayCache, store)
{
}
public virtual async ValueTask AddAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
await RemoveAsync(token, cancellationToken);
await Cache.SetAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(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)
{
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 = new List<OpenIddictTokenModel>();
await foreach (var token in Store.FindAsync(subject, client, status, type, 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> FindByApplicationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var tokens = await ArrayCache.GetOrAddAsync($"{nameof(FindByApplicationIdAsync)}_{identifier}", async () =>
{
var tokens = new List<OpenIddictTokenModel>();
await foreach (var token in Store.FindByApplicationIdAsync(identifier, 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> FindByAuthorizationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var tokens = await ArrayCache.GetOrAddAsync($"{nameof(FindByAuthorizationIdAsync)}_{identifier}", async () =>
{
var tokens = new List<OpenIddictTokenModel>();
await foreach (var token in Store.FindByAuthorizationIdAsync(identifier, cancellationToken))
{
tokens.Add(token);
await AddAsync(token, cancellationToken);
}
return tokens.ToArray();
}, token: cancellationToken);
foreach (var token in tokens)
{
yield return token;
}
}
public virtual async ValueTask<OpenIddictTokenModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Cache.GetOrAddAsync($"{nameof(FindByIdAsync)}_{identifier}", async () =>
{
var token = await Store.FindByIdAsync(identifier, cancellationToken);
if (token != null)
{
await AddAsync(token, cancellationToken);
}
return token;
}, token: cancellationToken);
}
public virtual async ValueTask<OpenIddictTokenModel> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Cache.GetOrAddAsync($"{nameof(FindByReferenceIdAsync)}_{identifier}", async () =>
{
var token = await Store.FindByReferenceIdAsync(identifier, cancellationToken);
if (token != null)
{
await AddAsync(token, cancellationToken);
}
return token;
}, token: cancellationToken);
}
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
var tokens = await ArrayCache.GetOrAddAsync($"{nameof(FindBySubjectAsync)}_{subject}", async () =>
{
var tokens = new List<OpenIddictTokenModel>();
await foreach (var token in Store.FindBySubjectAsync(subject, cancellationToken))
{
tokens.Add(token);
await AddAsync(token, cancellationToken);
}
return tokens.ToArray();
}, token: cancellationToken);
foreach (var token in tokens)
{
yield return token;
}
}
public virtual async ValueTask RemoveAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
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(FindByApplicationIdAsync)}_{await Store.GetApplicationIdAsync(token, cancellationToken)}",
$"{nameof(FindByAuthorizationIdAsync)}_{await Store.GetAuthorizationIdAsync(token, cancellationToken)}",
$"{nameof(FindBySubjectAsync)}_{await Store.GetSubjectAsync(token, cancellationToken)}"
}, token: cancellationToken);
await Cache.RemoveAsync($"{nameof(FindByIdAsync)}_{await Store.GetIdAsync(token, cancellationToken)}", token: cancellationToken);
await Cache.RemoveAsync($"{nameof(FindByReferenceIdAsync)}_{await Store.GetReferenceIdAsync(token, cancellationToken)}", token: cancellationToken);
}
}

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

@ -7,16 +7,15 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using OpenIddict.Abstractions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.OpenIddict.Authorizations;
using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Tokens;
public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRepository>, IOpenIddictTokenStore<OpenIddictToken>, IScopedDependency
public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRepository>, IOpenIddictTokenStore<OpenIddictTokenModel>
{
protected IOpenIddictApplicationRepository ApplicationRepository { get; }
protected IOpenIddictAuthorizationRepository AuthorizationRepository { get; }
@ -24,10 +23,10 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
public AbpOpenIddictTokenStore(
IOpenIddictTokenRepository repository,
IUnitOfWorkManager unitOfWorkManager,
IMemoryCache cache,
IGuidGenerator guidGenerator,
IOpenIddictApplicationRepository applicationRepository,
IOpenIddictAuthorizationRepository authorizationRepository)
: base(repository, unitOfWorkManager, cache)
: base(repository, unitOfWorkManager, guidGenerator)
{
ApplicationRepository = applicationRepository;
AuthorizationRepository = authorizationRepository;
@ -38,26 +37,26 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return await Repository.GetCountAsync(cancellationToken);
}
public virtual async ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual ValueTask<long> CountAsync<TResult>(Func<IQueryable<OpenIddictTokenModel>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
return await Repository.CountAsync(query, cancellationToken);
throw new NotSupportedException();
}
public virtual async ValueTask CreateAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
await Repository.InsertAsync(token, autoSave: true, cancellationToken: cancellationToken);
await Repository.InsertAsync(token.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
}
public virtual async ValueTask DeleteAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual async ValueTask DeleteAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
await Repository.DeleteAsync(token, autoSave: true, cancellationToken: cancellationToken);
await Repository.DeleteAsync(token.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
}
public virtual async IAsyncEnumerable<OpenIddictToken> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
@ -65,11 +64,11 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), cancellationToken);
foreach (var token in tokens)
{
yield return token;
yield return token.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictToken> FindAsync(string subject, string client, string status, [EnumeratorCancellation] CancellationToken cancellationToken)
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));
@ -78,11 +77,11 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, cancellationToken);
foreach (var token in tokens)
{
yield return token;
yield return token.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictToken> 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));
@ -92,58 +91,58 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken);
foreach (var token in tokens)
{
yield return token;
yield return token.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictToken> FindByApplicationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindByApplicationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var tokens = await Repository.FindByApplicationIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
foreach (var token in tokens)
{
yield return token;
yield return token.ToModel();
}
}
public virtual async IAsyncEnumerable<OpenIddictToken> FindByAuthorizationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindByAuthorizationIdAsync(string identifier, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var tokens = await Repository.FindByAuthorizationIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
foreach (var token in tokens)
{
yield return token;
yield return token.ToModel();
}
}
public virtual async ValueTask<OpenIddictToken> FindByIdAsync(string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<OpenIddictTokenModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
return (await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken)).ToModel();
}
public virtual async ValueTask<OpenIddictToken> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<OpenIddictTokenModel> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByReferenceIdAsync(identifier, cancellationToken);
return (await Repository.FindByReferenceIdAsync(identifier, cancellationToken)).ToModel();
}
public virtual async IAsyncEnumerable<OpenIddictToken> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
var tokens = await Repository.FindBySubjectAsync(subject, cancellationToken);
foreach (var token in tokens)
{
yield return token;
yield return token.ToModel();
}
}
public virtual ValueTask<string> GetApplicationIdAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetApplicationIdAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -152,14 +151,12 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
: null);
}
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
public virtual ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictTokenModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
return await Repository.GetAsync(query, state, cancellationToken);
throw new NotSupportedException();
}
public virtual ValueTask<string> GetAuthorizationIdAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetAuthorizationIdAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -168,7 +165,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
: null);
}
public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -180,7 +177,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return new ValueTask<DateTimeOffset?>(DateTime.SpecifyKind(token.CreationDate.Value, DateTimeKind.Utc));
}
public virtual ValueTask<DateTimeOffset?> GetExpirationDateAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<DateTimeOffset?> GetExpirationDateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -192,21 +189,21 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return new ValueTask<DateTimeOffset?>(DateTime.SpecifyKind(token.ExpirationDate.Value, DateTimeKind.Utc));
}
public virtual ValueTask<string> GetIdAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetIdAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
return new ValueTask<string>(ConvertIdentifierToString(token.Id));
}
public virtual ValueTask<string> GetPayloadAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetPayloadAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
return new ValueTask<string>(token.Payload);
}
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -215,15 +212,8 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return new ValueTask<ImmutableDictionary<string, JsonElement>>(ImmutableDictionary.Create<string, JsonElement>());
}
// Note: parsing the stringified properties is an expensive operation.
// To mitigate that, the resulting object is stored in the memory cache.
var key = string.Concat("d0509397-1bbf-40e7-97e1-5e6d7bc2536c", "\x1e", token.Properties);
var properties = Cache.GetOrCreate(key, entry =>
using (var document = JsonDocument.Parse(token.Properties))
{
entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
using var document = JsonDocument.Parse(token.Properties);
var builder = ImmutableDictionary.CreateBuilder<string, JsonElement>();
foreach (var property in document.RootElement.EnumerateObject())
@ -231,13 +221,11 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
builder[property.Name] = property.Value.Clone();
}
return builder.ToImmutable();
});
return new ValueTask<ImmutableDictionary<string, JsonElement>>(properties);
return new ValueTask<ImmutableDictionary<string, JsonElement>>(builder.ToImmutable());
}
}
public virtual ValueTask<DateTimeOffset?> GetRedemptionDateAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<DateTimeOffset?> GetRedemptionDateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -249,64 +237,54 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return new ValueTask<DateTimeOffset?>(DateTime.SpecifyKind(token.RedemptionDate.Value, DateTimeKind.Utc));
}
public virtual ValueTask<string> GetReferenceIdAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetReferenceIdAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
return new ValueTask<string>(token.ReferenceId);
}
public virtual ValueTask<string> GetStatusAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetStatusAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
return new ValueTask<string>(token.Status);
}
public virtual ValueTask<string> GetSubjectAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetSubjectAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
return new ValueTask<string>(token.Subject);
}
public virtual ValueTask<string> GetTypeAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual ValueTask<string> GetTypeAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
return new ValueTask<string>(token.Type);
}
public virtual ValueTask<OpenIddictToken> InstantiateAsync(CancellationToken cancellationToken)
public virtual ValueTask<OpenIddictTokenModel> InstantiateAsync(CancellationToken cancellationToken)
{
try
{
return new ValueTask<OpenIddictToken>(Activator.CreateInstance<OpenIddictToken>());
}
catch (MemberAccessException exception)
return new ValueTask<OpenIddictTokenModel>(new OpenIddictTokenModel
{
return new ValueTask<OpenIddictToken>(Task.FromException<OpenIddictToken>(exception));
}
Id = GuidGenerator.Create()
});
}
public virtual async IAsyncEnumerable<OpenIddictToken> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual async IAsyncEnumerable<OpenIddictTokenModel> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var tokens = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var token in tokens)
{
yield return token;
yield return token.ToModel();
}
}
public virtual async IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, [EnumeratorCancellation] CancellationToken cancellationToken)
public virtual IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictTokenModel>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
Check.NotNull(query, nameof(query));
var tokens = await Repository.ListAsync(query, state, cancellationToken);
foreach (var token in tokens)
{
yield return token;
}
throw new NotSupportedException();
}
public virtual async ValueTask PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken)
@ -331,7 +309,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
}
}
public virtual async ValueTask SetApplicationIdAsync(OpenIddictToken token, string identifier, CancellationToken cancellationToken)
public virtual async ValueTask SetApplicationIdAsync(OpenIddictTokenModel token, string identifier, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -346,7 +324,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
}
}
public virtual async ValueTask SetAuthorizationIdAsync(OpenIddictToken token, string identifier, CancellationToken cancellationToken)
public virtual async ValueTask SetAuthorizationIdAsync(OpenIddictTokenModel token, string identifier, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -361,7 +339,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
}
}
public virtual ValueTask SetCreationDateAsync(OpenIddictToken token, DateTimeOffset? date, CancellationToken cancellationToken)
public virtual ValueTask SetCreationDateAsync(OpenIddictTokenModel token, DateTimeOffset? date, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -370,7 +348,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetExpirationDateAsync(OpenIddictToken token, DateTimeOffset? date, CancellationToken cancellationToken)
public virtual ValueTask SetExpirationDateAsync(OpenIddictTokenModel token, DateTimeOffset? date, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -379,7 +357,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetPayloadAsync(OpenIddictToken token, string payload, CancellationToken cancellationToken)
public virtual ValueTask SetPayloadAsync(OpenIddictTokenModel token, string payload, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -388,7 +366,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetPropertiesAsync(OpenIddictToken token, ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
public virtual ValueTask SetPropertiesAsync(OpenIddictTokenModel token, ImmutableDictionary<string, JsonElement> properties, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -412,7 +390,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetRedemptionDateAsync(OpenIddictToken token, DateTimeOffset? date, CancellationToken cancellationToken)
public virtual ValueTask SetRedemptionDateAsync(OpenIddictTokenModel token, DateTimeOffset? date, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -421,7 +399,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetReferenceIdAsync(OpenIddictToken token, string identifier, CancellationToken cancellationToken)
public virtual ValueTask SetReferenceIdAsync(OpenIddictTokenModel token, string identifier, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -430,7 +408,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetStatusAsync(OpenIddictToken token, string status, CancellationToken cancellationToken)
public virtual ValueTask SetStatusAsync(OpenIddictTokenModel token, string status, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -439,7 +417,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetSubjectAsync(OpenIddictToken token, string subject, CancellationToken cancellationToken)
public virtual ValueTask SetSubjectAsync(OpenIddictTokenModel token, string subject, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -448,7 +426,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual ValueTask SetTypeAsync(OpenIddictToken token, string type, CancellationToken cancellationToken)
public virtual ValueTask SetTypeAsync(OpenIddictTokenModel token, string type, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
@ -457,10 +435,12 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
return default;
}
public virtual async ValueTask UpdateAsync(OpenIddictToken token, CancellationToken cancellationToken)
public virtual async ValueTask UpdateAsync(OpenIddictTokenModel token, CancellationToken cancellationToken)
{
Check.NotNull(token, nameof(token));
await Repository.UpdateAsync(token, autoSave: true, cancellationToken: cancellationToken);
var entity = await Repository.GetAsync(token.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(token.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
}

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

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -13,8 +12,6 @@ public interface IOpenIddictTokenRepository : IBasicRepository<OpenIddictToken,
Task DeleteManyByAuthorizationIdAsync(Guid authorizationId, bool autoSave = false, CancellationToken cancellationToken = default);
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default);
@ -31,11 +28,7 @@ public interface IOpenIddictTokenRepository : IBasicRepository<OpenIddictToken,
Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default);
}

9
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/OpenIddictToken.cs

@ -5,6 +5,15 @@ namespace Volo.Abp.OpenIddict.Tokens;
public class OpenIddictToken : FullAuditedAggregateRoot<Guid>
{
public OpenIddictToken()
{
}
public OpenIddictToken(Guid id)
: base(id)
{
}
/// <summary>
/// Gets or sets the application associated with the current token.
/// </summary>

68
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/OpenIddictTokenExtensions.cs

@ -0,0 +1,68 @@
namespace Volo.Abp.OpenIddict.Tokens;
public static class OpenIddictTokenExtensions
{
public static OpenIddictToken ToEntity(this OpenIddictTokenModel model)
{
Check.NotNull(model, nameof(model));
return new OpenIddictToken(model.Id)
{
ApplicationId = model.ApplicationId,
AuthorizationId = model.AuthorizationId,
CreationDate = model.CreationDate,
ExpirationDate = model.ExpirationDate,
Payload = model.Payload,
Properties = model.Properties,
RedemptionDate = model.RedemptionDate,
ReferenceId = model.ReferenceId,
Status = model.Status,
Subject = model.Subject,
Type = model.Type
};
}
public static OpenIddictToken ToEntity(this OpenIddictTokenModel model, OpenIddictToken entity)
{
Check.NotNull(model, nameof(model));
Check.NotNull(entity, nameof(entity));
entity.ApplicationId = model.ApplicationId;
entity.AuthorizationId = model.AuthorizationId;
entity.CreationDate = model.CreationDate;
entity.ExpirationDate = model.ExpirationDate;
entity.Payload = model.Payload;
entity.Properties = model.Properties;
entity.RedemptionDate = model.RedemptionDate;
entity.ReferenceId = model.ReferenceId;
entity.Status = model.Status;
entity.Subject = model.Subject;
entity.Type = model.Type;
return entity;
}
public static OpenIddictTokenModel ToModel(this OpenIddictToken model)
{
if(model == null)
{
return null;
}
return new OpenIddictTokenModel
{
Id = model.Id,
ApplicationId = model.ApplicationId,
AuthorizationId = model.AuthorizationId,
CreationDate = model.CreationDate,
ExpirationDate = model.ExpirationDate,
Payload = model.Payload,
Properties = model.Properties,
RedemptionDate = model.RedemptionDate,
ReferenceId = model.ReferenceId,
Status = model.Status,
Subject = model.Subject,
Type = model.Type
};
}
}

71
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/OpenIddictTokenModel.cs

@ -0,0 +1,71 @@
using System;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.OpenIddict.Tokens;
[Serializable, IgnoreMultiTenancy]
public class OpenIddictTokenModel
{
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the application associated with the current token.
/// </summary>
public virtual Guid? ApplicationId { get; set; }
/// <summary>
/// Gets or sets the authorization associated with the current token.
/// </summary>
public virtual Guid? AuthorizationId { get; set; }
/// <summary>
/// Gets or sets the UTC creation date of the current token.
/// </summary>
public virtual DateTime? CreationDate { get; set; }
/// <summary>
/// Gets or sets the UTC expiration date of the current token.
/// </summary>
public virtual DateTime? ExpirationDate { get; set; }
/// <summary>
/// Gets or sets the payload of the current token, if applicable.
/// Note: this property is only used for reference tokens
/// and may be encrypted for security reasons.
/// </summary>
public virtual string Payload { get; set; }
/// <summary>
/// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current token.
/// </summary>
public virtual string Properties { get; set; }
/// <summary>
/// Gets or sets the UTC redemption date of the current token.
/// </summary>
public virtual DateTime? RedemptionDate { get; set; }
/// <summary>
/// Gets or sets the reference identifier associated
/// with the current token, if applicable.
/// Note: this property is only used for reference tokens
/// and may be hashed or encrypted for security reasons.
/// </summary>
public virtual string ReferenceId { get; set; }
/// <summary>
/// Gets or sets the status of the current token.
/// </summary>
public virtual string Status { get; set; }
/// <summary>
/// Gets or sets the subject associated with the current token.
/// </summary>
public virtual string Subject { get; set; }
/// <summary>
/// Gets or sets the type of the current token.
/// </summary>
public virtual string Type { get; set; }
}

21
modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Applications/EfCoreOpenIddictApplicationRepository.cs

@ -18,35 +18,24 @@ public class EfCoreOpenIddictApplicationRepository : EfCoreRepository<IOpenIddic
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.PostLogoutRedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.RedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync(), state)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
@ -55,10 +44,4 @@ public class EfCoreOpenIddictApplicationRepository : EfCoreRepository<IOpenIddic
.TakeIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(count.HasValue, count.Value)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync(), state)
.ToListAsync(GetCancellationToken(cancellationToken));
}
}

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

@ -19,11 +19,6 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository<IOpenIdd
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
@ -65,12 +60,6 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository<IOpenIdd
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync(), state)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
var query = (await GetDbSetAsync())
@ -90,12 +79,6 @@ public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository<IOpenIdd
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync(), state)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
var tokenQueryable = (await GetDbContextAsync()).Tokens.AsQueryable();

1
modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictDbContextModelCreatingExtensions.cs

@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.OpenIddict.Authorizations;

15
modules/openiddict/src/Volo.Abp.OpenIddict.EntityFrameworkCore/Volo/Abp/OpenIddict/Scopes/EfCoreOpenIddictScopeRepository.cs

@ -18,11 +18,6 @@ public class EfCoreOpenIddictScopeRepository : EfCoreRepository<IOpenIddictDbCon
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
@ -43,11 +38,6 @@ public class EfCoreOpenIddictScopeRepository : EfCoreRepository<IOpenIddictDbCon
return await (await GetQueryableAsync()).Where(x => x.Resources.Contains(resource)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync())
@ -56,9 +46,4 @@ public class EfCoreOpenIddictScopeRepository : EfCoreRepository<IOpenIddictDbCon
.TakeIf<OpenIddictScope, IQueryable<OpenIddictScope>>(count.HasValue, count.Value)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).ToListAsync(GetCancellationToken(cancellationToken));
}
}

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

@ -38,11 +38,6 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbCon
await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken));
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client).ToListAsync(GetCancellationToken(cancellationToken));
@ -83,11 +78,6 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbCon
return await (await GetQueryableAsync()).Where(x => x.Subject == subject).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync())
@ -97,11 +87,6 @@ public class EfCoreOpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbCon
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
return await (from token in await GetQueryableAsync()

12
modules/openiddict/src/Volo.Abp.OpenIddict.MongoDB/Volo/Abp/OpenIddict/Applications/MongoOpenIddictApplicationRepository.cs

@ -17,13 +17,6 @@ public class MongoOpenIddictApplicationRepository : MongoDbRepository<OpenIddict
{
}
public async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken))
.As<IMongoQueryable<OpenIddictApplication>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
@ -54,9 +47,4 @@ public class MongoOpenIddictApplicationRepository : MongoDbRepository<OpenIddict
.As<IMongoQueryable<OpenIddictApplication>>()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}
}

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

@ -19,11 +19,6 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
{
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken)).As<IMongoQueryable<OpenIddictAuthorization>>().LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
@ -60,11 +55,6 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.Subject == subject).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
@ -74,11 +64,6 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
.As<IMongoQueryable<OpenIddictAuthorization>>().ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
var tokenQueryable = await GetMongoQueryableAsync<OpenIddictToken>(GetCancellationToken(cancellationToken));

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

@ -17,11 +17,6 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
{
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken)).As<IMongoQueryable<OpenIddictScope>>().LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
@ -46,11 +41,6 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
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)
@ -59,9 +49,4 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
.As<IMongoQueryable<OpenIddictScope>>()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}
}

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

@ -39,11 +39,6 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken));
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject && x.ApplicationId == client)
@ -96,11 +91,6 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
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)
@ -110,11 +100,6 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
return await (from token in await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))

1
modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/OpenIddictTestBase.cs

@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
using Volo.Abp.Testing;

1
modules/openiddict/test/Volo.Abp.OpenIddict.TestBase/OpenIddictTestBaseModule.cs

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Authorization;
using Volo.Abp.Autofac;
using Volo.Abp.Data;

Loading…
Cancel
Save