Base solution for your next web application
Open Closed

Create an API next to Web.Host #12287


User avatar
0
[email protected] created

Hi,

I am currently working on an ASP.NET Zero-based solution that includes a primary project named Web.Host. This project is successfully utilizing JWT-based authentication along with social login providers (e.g., Facebook, Google) configured through ABP modules.

I am attempting to add an additional API project named Web.Reports to the solution. The goal is to have Web.Reports use the same authentication mechanism as Web.Host, enabling the frontend to authenticate once and access endpoints from both Web.Host and Web.Reports seamlessly.

Best regards!


2 Answer(s)
  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @[email protected],

    I will review the code a bit more to provide the best solution.

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @[email protected],

    Based on your setup, it's possible to reuse the same authentication mechanism across both Web.Hostand Web.Reports without much customization. Since the TokenAuthController is already in the Web.Core project, both APIs can leverage the same logic seamlessly.

    To achieve this, I recommend the following steps:

    • Move the AuthConfigurer class from Web.Host toWeb.Core. This will allow both Web.Host and Web.Reports to share the same authentication configuration without duplicating code.
    • In the Startup.cs of your Web.Reports project, ensure that the authentication settings mirror those of Web.Host. Specifically, copy over the configurations related to JWT authentication, authorization policies, and any other relevant middleware.

    Once this setup is complete, the same token should work seamlessly across both APIs, allowing your frontend to authenticate once and access endpoints from both projects without issues.