Open Closed

Best way to fetch list of users or user repository from the identity server from a microservice module #1008


User avatar
0
Femi.madariola created

Hello Team

I have a solution that consists of:

  • one main application template (Main) and
  • one module application (Account) exposed via an Http.Api.host
  • and an identity server seperatated used by both other applications.

What is the best way to get the list of users from the module application (Account) because I have a grid that I need to show the list of users that performed certain activities. I got the user's ID when the action was performed from the "CurrentUser.Id" property.

Also how do I check or get the roles of the user from the Module application (Account) to confirm if the authenticated user has a certain role from the Identity server. When I check the user's role, it is currently blank.

  • ABP Framework version: 4.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

10 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You need to reference Identity module.

    e.g: Account module: https://github.com/abpframework/abp/blob/12d92700a0396367a7e749d662e92c167b7f260d/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AbpAccountApplicationModule.cs#L16

    Then you can inject the repository to get the user list.

    If you deploy identity as a separate service and use a separate database. You need to set the connection string:

    {
        "ConnectionStrings": {
            "MyModuleNameService": "Server=localhost;Database=MyProjectName_MyModuleNameService;Trusted_Connection=True",
            "AbpIdentity": "Server=localhost;Database=MyProjectName_IdentityService;Trusted_Connection=True"
      }
    }
    
  • User Avatar
    0
    Femi.madariola created

    Thanks for your response.

    I have added the AbpIdentityModules to both the Application and Domain layer (added this so I can use IdentityUser in the EFCore layer).

    I have also changed my appsettings to look like below:

    "AbpPermissionManagement": "Server=tcp:agromall.database.windows.net,1433;Initial Catalog=NewVCPDB;Persist Security Info=False;User ID=xxxxxxx;Password=xxxxxxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", "AbpIdentity": "Server=tcp:agromall.database.windows.net,1433;Initial Catalog=NewVCPDB;Persist Security Info=False;User ID=xxxxxxxxx;Password=xxxxxxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", "AM": "Server=tcp:agromall.database.windows.net,1433;Initial Catalog=AccountManagement;Persist Security Info=False;User ID=xxxxxxxxx;Password=xxxxxxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

    However I get this error below:

    Autofac.Core.DependencyResolutionException HResult=0x80131500 Message=An exception was thrown while activating Volo.Abp.Identity.IdentityDataSeedContributor -> Volo.Abp.Identity.IdentityDataSeeder. Source=Autofac StackTrace: at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType) at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Volo.Abp.Data.DataSeeder.<SeedAsync>d__7.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Castle.DynamicProxy.AsyncInterceptorBase.<ProceedAsynchronous>d__13.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.<ProceedAsync>d__7.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Volo.Abp.Uow.UnitOfWorkInterceptor.<InterceptAsync>d__3.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.<InterceptAsync>d__2.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at AM.AMHttpApiHostModule.<>c__DisplayClass5_0.<<SeedData>b__0>d.MoveNext() in C:\Users\FemiM\Documents\Agro\AM\host\AM.HttpApi.Host\AMHttpApiHostModule.cs:line 238 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) at Nito.AsyncEx.AsyncContext.<>c__DisplayClass15_0.<Run>b__0(Task t) at System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) at Nito.AsyncEx.AsyncContext.Run(Func1 action) at Volo.Abp.Threading.AsyncHelper.RunSync(Func1 action) at AM.AMHttpApiHostModule.SeedData(ApplicationInitializationContext context) in C:\Users\FemiM\Documents\Agro\AM\host\AM.HttpApi.Host\AMHttpApiHostModule.cs:line 234 at AM.AMHttpApiHostModule.OnApplicationInitialization(ApplicationInitializationContext context) in C:\Users\FemiM\Documents\Agro\AM\host\AM.HttpApi.Host\AMHttpApiHostModule.cs:line 229 at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)

    This exception was originally thrown at this call stack: [External Code]

    Inner Exception 1: DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Volo.Abp.Identity.IdentityDataSeeder' can be invoked with the available services and parameters: Cannot resolve parameter 'Volo.Abp.Identity.IIdentityRoleRepository roleRepository' of constructor 'Void .ctor(Volo.Abp.Guids.IGuidGenerator, Volo.Abp.Identity.IIdentityRoleRepository, Volo.Abp.Identity.IIdentityUserRepository, Microsoft.AspNetCore.Identity.ILookupNormalizer, Volo.Abp.Identity.IdentityUserManager, Volo.Abp.Identity.IdentityRoleManager, Volo.Abp.MultiTenancy.ICurrentTenant, Microsoft.Extensions.Options.IOptions1[Microsoft.AspNetCore.Identity.IdentityOptions])'.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Cannot resolve parameter 'Volo.Abp.Identity.IIdentityRoleRepository roleRepository' of constructor

    Did you add module dependencies?

     [DependsOn(
            typeof(AbpIdentityApplicationModule)
        )]
    
  • User Avatar
    0
    Femi.madariola created

    I have added the depends on for the entity framework project and it loads well and also shows the current roles, the user has.

    However, I can't seem to get the policies or permissions the user has been granted on the microservice. Meaning when I check the granted policies on the ​/api​/abp​/application-configuration endpoint from the main application, I see the policies that have been granted but when I check from that ​/api​/abp​/application-configuration endpoint on the Microservice the array is empty.

    How do I show the policies that have been granted to the user on the Microservice?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Can I check it remotely? shiwei.liang@volosoft.com

  • User Avatar
    0
    murat.yuceer created

    Can we list users from api instead of dbconnection?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes we can.

    You need to reference the AbpIdentityHttpApiClientModule module.

    See https://docs.abp.io/en/abp/latest/API/Dynamic-CSharp-API-Clients#usage

    Like:

    {
      "RemoteServices": {
        "AbpIdentity": {
          "BaseUrl": "http://localhost:48392/"
        } 
      } 
    }
    
  • User Avatar
    0
    murat.yuceer created

    I guess if i add like that it will fallback right (for internal gateway)

    { "RemoteServices": { "Default": { "BaseUrl": "http://localhost:48392/" } } }

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Yes.

    If the specified configuration is not provided, it will fallback to default.

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11