Open Closed

Auth server endpoints 404 behind reverse proxy #9199


User avatar
0
shodgson created

Hello,

We're using the ABP microservice template for a blazor web app that is deployed on AKS.

Our auth server is currently deployed and reachable on a /auth path.

When trying to Submit the personal info or change password on the "My account" page of the auth server we get a 404. In the network tab we see that our /auth base path is not in the url used to do the request even though we have properly set the app.UsePathBase("/auth") in the auth server module.

Is there anything other than the base path that needs to be set in order to get the auth/account actions working under a base path on the auth server?

Thanks


6 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello,

    Have you configured your gateway according to this change?

    If you have configured it, the request should reach the Gateway and be passed to the AuthServer, can you verify this?

  • User Avatar
    0
    shodgson created

    Hey, thanks for the response.

    Unless i'm mistaken, the auth server requests targeting the /api/account/my-profile within the Account/Manage page does not go through the web gateway.

    Locally, when running everything as default and without any custom base path for my auth server, I do see all /api/account/my-profile requests reaching the auth server directly without going through the web gateway. I can repro the same behavior when starting from a new microservice template.

    Repro steps:

    • Create a new microservice solution with a Blazor web app
    • Go on the /Account/Manage page hosted on the auth server
    • Change password and submit
    • Notice that the /api/account requests are directly sent to the auth server and not the web gateway

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello,

    Yes, I can reproduce what you said last time. There is nothing wrong here, it works as expected. However, I think you are using UsePathBase incorrectly.

    If you use UsePathBase(โ€œ/authโ€), the requests should be /auth/api/account/... not /api/account/.... So you also need to change the endpoint of the controllers.

    I created a class like below to change the prefix of all controllers:

    public class GlobalRouteReplaceConvention : IApplicationModelConvention
    {
        private readonly string _oldPrefix;
        private readonly string _newPrefix;
    
        public GlobalRouteReplaceConvention(string oldPrefix, string newPrefix)
        {
            _oldPrefix = oldPrefix.Trim('/');
            _newPrefix = newPrefix.Trim('/');
        }
    
        public void Apply(ApplicationModel application)
        {
            foreach (var controller in application.Controllers)
            {
                foreach (var selector in controller.Selectors.Where(s => s.AttributeRouteModel != null))
                {
                    var template = selector.AttributeRouteModel.Template;
    
                    if (template.StartsWith(_oldPrefix))
                    {
                        selector.AttributeRouteModel.Template = _newPrefix + template.Substring(_oldPrefix.Length);
                    }
                    else
                    {
                        selector.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel(
                            new AttributeRouteModel(new Microsoft.AspNetCore.Mvc.RouteAttribute(_newPrefix)),
                            selector.AttributeRouteModel
                        );
                    }
                }
            }
        }
    }
    

    Then I called it in the ConfigureServices method of the module as follows:

            context.Services.AddControllers(options =>
            {
                options.Conventions.Insert(0, new GlobalRouteReplaceConvention("api", "auth/api"));
            });
    

    Result:

    Then I added app.UsePathBase(โ€œ/authโ€); middleware as you did.

    Then in my case everything works properly.

    If you think I misunderstood your question, I would be grateful if you could direct me again ๐Ÿ˜Š

  • User Avatar
    0
    shodgson created

    context.Services.AddControllers(options => { options.Conventions.Insert(0, new GlobalRouteReplaceConvention("api", "auth/api")); });

    I don't think replacing the api controller convention will work in my case.

    It's the actual url used to make the change-password request that is not accounting for the path base. I did try to change the conventions based on your response and the URL used internally is still the same as before.

    Where is that URL taken from and how can I override it to include my base path?

  • User Avatar
    0
    shodgson created

    I had to create a new script that set the abp.appPath to my pathBase cause that's what abp uses internally to call the auth server in the account-proxy.js. It's working now.

    account-proxy.js :

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi Shodgson ๐Ÿ‘‹,

    Apologies for the delay in responding โ€” we were off yesterday due to International Workers' Day. I'm really glad to hear that you were able to resolve the issue!

    Closing the issue now. Feel free to create a new one if you have any further questions.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with โค๏ธ on ABP v9.3.0-preview. Updated on May 12, 2025, 05:22