hi
. I need a list of roles in my custom module.
If you want to get roles list in your module then you need add Identity module to your module. If you wan to get roles list inyour main project you don't need to do this.
hi zhongfang
Can you?
hi
https://docs.abp.io/en/abp/latest/Best-Practices/Module-Architecture
| Your Module | operator | Identity Module | | --- | --- | --- | .Application | Add reference & Depends on| Identity.Application | .Application.Contracts |Add reference & Depends on|Identity.Application.Contracts| .Domain | Add reference & Depends on| Identity.Domain| .Domain.Shared | Add reference & Depends on| Identity.Domain.Shared| .EntityFrameworkCore | Add reference & Depends on| Identity.EntityFrameworkCore| .HttpApi | Add reference & Depends on|Identity.HttpApi| .HttpApi.Client | Add reference & Depends on| Identity.HttpApi.Client| .Web | Add reference & Depends on| Identity.Web |
hi
https://github.com/abpframework/abp/issues/15816 https://github.com/abpframework/abp/issues/10568
hi
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddOpenIddict()
.AddCore(builder =>
{
builder
.AddApplicationStore<MyAbpOpenIddictApplicationStore>()
.AddAuthorizationStore<MyAbpOpenIddictAuthorizationStore>()
.AddTokenStore<MyAbpOpenIddictTokenStore>();
});
}
public class MyAbpOpenIddictApplicationStore : AbpOpenIddictApplicationStore
{
public MyAbpOpenIddictApplicationStore(IOpenIddictApplicationRepository repository,
IUnitOfWorkManager unitOfWorkManager, IOpenIddictTokenRepository tokenRepository, IGuidGenerator guidGenerator,
AbpOpenIddictIdentifierConverter identifierConverter,
IOpenIddictDbConcurrencyExceptionHandler concurrencyExceptionHandler) : base(repository, unitOfWorkManager,
tokenRepository, guidGenerator, identifierConverter, concurrencyExceptionHandler)
{
}
public async override ValueTask DeleteAsync(OpenIddictApplicationModel application, CancellationToken cancellationToken)
{
Check.NotNull(application, nameof(application));
try
{
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.ReadCommitted))
{
await TokenRepository.DeleteManyByApplicationIdAsync(application.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(application.Id, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
}
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
await ConcurrencyExceptionHandler.HandleAsync(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
}
}
public class MyAbpOpenIddictAuthorizationStore : AbpOpenIddictAuthorizationStore
{
public MyAbpOpenIddictAuthorizationStore(IOpenIddictAuthorizationRepository repository,
IUnitOfWorkManager unitOfWorkManager, IGuidGenerator guidGenerator,
IOpenIddictApplicationRepository applicationRepository, IOpenIddictTokenRepository tokenRepository,
AbpOpenIddictIdentifierConverter identifierConverter,
IOpenIddictDbConcurrencyExceptionHandler concurrencyExceptionHandler) : base(repository, unitOfWorkManager,
guidGenerator, applicationRepository, tokenRepository, identifierConverter, concurrencyExceptionHandler)
{
}
public async override ValueTask DeleteAsync(OpenIddictAuthorizationModel authorization, CancellationToken cancellationToken)
{
Check.NotNull(authorization, nameof(authorization));
try
{
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.ReadCommitted))
{
await TokenRepository.DeleteManyByAuthorizationIdAsync(authorization.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(authorization.Id, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
}
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
await ConcurrencyExceptionHandler.HandleAsync(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
}
public async override ValueTask<long> PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken)
{
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.ReadCommitted))
{
var date = threshold.UtcDateTime;
var count = await Repository.PruneAsync(date, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
return count;
}
}
}
public class MyAbpOpenIddictTokenStore : AbpOpenIddictTokenStore
{
public MyAbpOpenIddictTokenStore(IOpenIddictTokenRepository repository, IUnitOfWorkManager unitOfWorkManager,
IGuidGenerator guidGenerator, IOpenIddictApplicationRepository applicationRepository,
IOpenIddictAuthorizationRepository authorizationRepository,
AbpOpenIddictIdentifierConverter identifierConverter,
IOpenIddictDbConcurrencyExceptionHandler concurrencyExceptionHandler) : base(repository, unitOfWorkManager,
guidGenerator, applicationRepository, authorizationRepository, identifierConverter, concurrencyExceptionHandler)
{
}
public async override ValueTask<long> PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken)
{
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.ReadCommitted))
{
var date = threshold.UtcDateTime;
var count = await Repository.PruneAsync(date, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
return count;
}
}
}
hi
Can you try to remove the app.UseUnitOfWork(); from your asp net core pipeline?
hi
You can override these methods to use another IsolationLevel, I will make it configurable in the next version.
Your question credit has been refunded.
hi
You can add Identity module as a reference to your custom module, add depends on it modules and inject the IdentityRoleManager or IIdentityRoleRepository
hi
But I'm unable to get the list of roles in my custom module using role manager. How can I do that? What's the best approach
Can you explain this in detail? Do you get any error logs?
hi
You can use the ID(guide) of "Customers" and "Invoices" in the Tenant_Admin Database without creating a relationship.
Different microservices may use different databases. It is not possible to create database relationships. So using ID is an option