Open Closed

The CurrentUser details are null #6088


User avatar
0
cunyong.yu@vskysoft.com created

I created a module project, defined an interface in the“ Application. Contracts” project, implemented this interface in the” Application” and ”Controller” projects, and used the command ”abp generate proxy - t csharp - url' in the HttpApi. Client project http://localhost:44313 -M WorkCalendar -- without contracts "generated the proxy code, and then I referenced this proxy in ”Blazor. Server. Host ”and started the ”Blazor. Server. Host” and ”HttpApi. Host” projects. At this time, the ”CurrentUser” information obtained from the services in the Application project is null, and the services inherit IApplicationService and ITransientDependency interfaces, How can I obtain information about Blazor login users from the services in the Application project?

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, and please first use the search on the homepage. Provide us with the following info:

  • ABP Framework version: v7.2.2
  • UI Type: Blazor Server
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

18 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello cunyong.yu@vskysoft.com,

    Can you please share some logs or more steps to reproduce the issue?

  • User Avatar
    0
    cunyong.yu@vskysoft.com created

    I started the "AuthenServer", "HttpApi. Host", and "Blazor. Server. Host" services. Then log in to the 'admin' user on the page. “Blazor. Server. Host" calls the interface through "HttpApi. Client": Unable to obtain the current logged in user information in the interface. How can I obtain the logged in user information for calling the interface? If you need debugging, how can I send you the demo project?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    liming.ma@volosoft.com

  • User Avatar
    0
    cunyong.yu@vskysoft.com created

    hi I have sent the demo to your email.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the full steps?

    I'm going to reproduce the problem.

  • User Avatar
    0
    cunyong.yu@vskysoft.com created
    1. Start the "AuthenServer", "HttpApi. Host", and "Blazor. Server. Host" services.
    2. Log in to the 'admin' user on the page.
    3. Open the homepage of UserInfoDemo.
    4. Break the point in the GetAsync method of 'SampleAppService' to view details of _currentUser. Why there is no login user information in currentUser, or is there any other way to obtain it here.
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you upload your project to GitHub?

  • User Avatar
    0
    cunyong.yu@vskysoft.com created

    I'm very sorry, I missed a decryption file. I have sent it to you via email.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    src/UserInfoDemo.Application/Samples/SampleAppService.cs
    host/UserInfoDemo.HttpApi.Host/EntityFrameworkCore/UserInfoDemoHttpApiHostMigrationsDbContextFactory.cs
    
  • User Avatar
    0
    cunyong.yu@vskysoft.com created

    I'm very sorry for missing it again. It has been sent to you via email.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The UserInfoDemo.Blazor.Server.Host project is not a tiered project.

    It has openiddict integration and uses cookies. so you can't get access_token from cookies to call the api.

  • User Avatar
    0
    cunyong.yu@vskysoft.com created

    In this case, can I only fill in the user information in the Blazor project and then pass it to the interface?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    In this case, you shouldn't call the API from the blazor(it's a auth server project)

  • User Avatar
    0
    cunyong.yu@vskysoft.com created

    The documentation for abp states that you call the interface on the Blazor page. I followed the documentation, but if this is incorrect, how do I call the api?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    that you call the interface on the Blazor page.

    this means the tiered blazor app which is a pure UI project, your blaozr includes openiddict, account etc, and it is not a UI project.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    If you still want to call the API

    You can add AbpHttpClientIdentityModelWebModule module to your blazor project and override the HttpContextIdentityModelRemoteServiceHttpClientAuthenticator to return an access_token.

    https://github.com/abpframework/abp/blob/rel-7.2/framework/src/Volo.Abp.Http.Client.IdentityModel.Web/Volo/Abp/Http/Client/IdentityModel/Web/HttpContextIdentityModelRemoteServiceHttpClientAuthenticator.cs#L37-L46

  • User Avatar
    0
    cunyong.yu@vskysoft.com created

    Can you provide me with a demo? Thank you!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can't get the access_token from httpcontext in your blazor project by default. Because your situation does not match our design.

    You can request the auth server get a new access_token and set it to request in your custom HttpContextIdentityModelRemoteServiceHttpClientAuthenticator

    https://github.com/abpframework/abp/blob/rel-7.2/modules/openiddict/app/OpenIddict.Demo.Client.Console/Program.cs#L22-L32

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