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)
-
0
Hello cunyong.yu@vskysoft.com,
Can you please share some logs or more steps to reproduce the issue?
-
0
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?
-
0
hi
liming.ma@volosoft.com
-
0
hi I have sent the demo to your email.
-
0
hi
Can you share the full steps?
I'm going to reproduce the problem.
-
0
- Start the "AuthenServer", "HttpApi. Host", and "Blazor. Server. Host" services.
- Log in to the 'admin' user on the page.
- Open the homepage of UserInfoDemo.
- 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.
-
0
-
0
I'm very sorry, I missed a decryption file. I have sent it to you via email.
-
0
hi
src/UserInfoDemo.Application/Samples/SampleAppService.cs host/UserInfoDemo.HttpApi.Host/EntityFrameworkCore/UserInfoDemoHttpApiHostMigrationsDbContextFactory.cs
-
0
I'm very sorry for missing it again. It has been sent to you via email.
-
0
hi
The
UserInfoDemo.Blazor.Server.Host
project is not atiered
project.It has
openiddict
integration and uses cookies. so you can't getaccess_token
from cookies to call the api. -
0
In this case, can I only fill in the user information in the Blazor project and then pass it to the interface?
-
0
hi
In this case, you shouldn't call the API from the blazor(it's a auth server project)
-
0
-
0
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. -
0
If you still want to call the API
You can add
AbpHttpClientIdentityModelWebModule
module to your blazor project and override theHttpContextIdentityModelRemoteServiceHttpClientAuthenticator
to return anaccess_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
-
0
Can you provide me with a demo? Thank you!
-
0
hi
You can't get the
access_token
fromhttpcontext
in yourblazor
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