Open Closed

IAccessTokenProvider not registered after migrating from blazor webassembly to web app #8623


User avatar
0
franciscosl created
  • ABP Framework version: v8.3.2
  • UI Type: Blazor WebApp
  • Database System: EF Core - SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Previously I had an application in blazor webassembly since it was born in net core 6. After migrating to Blazor WebApp I am having problems since one of my components injects the IAccessTokenProvider interface (belongs to Microsoft.AspNetCore.Components.WebAssembly.Authentication.dll).

After the migration this service is no longer injected, moreover, I have tried to inject IAbpAccessTokenProvider, but the implementation I get is Volo.Abp.AspNetCore.Components.WebAssembly.WebApp.CookieBasedWebAssemblyAbpAccessTokenProvider, which after reviewing its code, returns a null string.

By default I use InteractiveAutoRenderMode with prerender set to false. I've tried to indicate in the component that it uses the InteractiveWebAssemblyRenderMode interface but it doesn't solve anything. Any idea?


18 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The web app has two modes, server and wasm.

    CookieBased means you don't need to get the access token because of the authentication state in the cookies.

    You can request the API, The browser will add the cookies automatically.

  • User Avatar
    0
    franciscosl created

    After trying to remove its use, the request continues to fail.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi

    Can you check if the request contains the authentication cookies in Chrome devtool?

    You’re not using tiered blazor project. Right?

  • User Avatar
    0
    franciscosl created

    Hello,

    The headers of the petition:

    Cookies:

    No, it is not tiered.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Are these cookies in the same domain and port?

  • User Avatar
    0
    franciscosl created

    Hello,

    The cookie domain is "localhost".

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You have a webapp project, but you have two domains. localhost and localhost:44362

    Can you explain this?

  • User Avatar
    0
    franciscosl created

    As far as I know we don't manage that, localhost is my computer and 44362 is the port where the application is exposed when debugging, which is configured in the appsettings.

    What are the risks of this being different, and do they need to be the same? If so, how can I change it?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the test project so I can reproduce the problem locally?

    liming.ma@volosoft.com

    Thanks

  • User Avatar
    0
    franciscosl created

    Hi, I can't share a sample project as it is a final application.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can test your code in a new template project and share the template source code.

    Thanks.

  • User Avatar
    0
    franciscosl created

    After creating a new project, the only thing I added was an AppService without complexity, with a method without parameters or functional implementation, to test a call to the api, and the result I get is the same as in the final application, attached images:

    Additionally, it also does not inject microsoft's IAccessTokenProvider.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you reproduce the Problem in the new template?

    If so, Please share the template with liming.ma@volosoft.com

    I will download and test it.

    Thanks.

  • User Avatar
    0
    franciscosl created

    Yes, as I have attached in the images, it does reproduce. I will send it to you now. Thank you!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks, you can share it via https://wetransfer.com/

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The requests to API are successful.

    I can see the authentication cookies are sent to API

  • User Avatar
    0
    franciscosl created

    Sorry, but I'm missing the point of this thread.

    1. You have asked about whether the cookie and the domain are on the same port.(https://abp.io/qa/questions/8623/3a17711b-c085-7e46-9c30-f1b7dd14075f).
    2. After answering you that the cookie appears localhost without port you told me that I have two domains and that I can explain it to you.(https://abp.io/qa/questions/8623/3a17713f-4e4b-d3d1-0501-248f5f43d968).
    3. I asked you what risks this entails and how I could change it, as I have not changed any of it, to which I received the reply of sending you the test project. Where you then asked me for a new abp project.
    4. I implement a new solution and add two screenshots where you can see that exactly the same thing is happening.
    5. I send you the project and your answer is that the api requests are correct, where in the gif you can't see the api headers and you can see that the cookie is "localhost".

    I need to get the token so I can assign it to a request.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Sorry, there is no access token in the no-tiered Blazor web app

    Because it uses the Cookie authentication.

    Cookie is represented a user.

Made with ❤️ on ABP v9.2.0-preview. Updated on January 16, 2025, 11:47