Open Closed

I would like to specify the IP address that can be used to log in for each tenant #6130


User avatar
0
portx-dev created

I would like to specify the IP address that can be used to log in for each tenant. Is this possible with ABP Commercial's functions?

ABP Framework version: Commercial 7.4 UI type: Angular DB provider: EF Core

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    Just an idea:

    First, custom the tenant entity:

    ObjectExtensionManager.Instance.Modules()
        .ConfigureSaas(saas =>
        {
            saas.ConfigureTenant(tenant =>
            {
                tenant.AddOrUpdateProperty<string>( //property type: string
                    "AllowedIpAddress", //property name
                    property =>
                    {
                    }
                );
            });
        });
    

    Then, you can create a middleware that checks the login IP address:

    app.Use(async (httpContext, next) =>
    {
        if(httpContext.Request.Path.ToString().Contains("account/login", StringComparison.InvariantCultureIgnoreCase))
        {
            var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>();
            if (currentTenant.IsAvailable)
            {
                var tenant = await context.ServiceProvider.GetRequiredService<ITenantRepository>().FindAsync(currentTenant.GetId());
                var allowedIp = tenant.GetProperty<string>("AllowedIpAddress");
                if (!string.IsNullOrEmpty(allowedIp))
                {
                    var remoteIp = httpContext.Connection.RemoteIpAddress.ToString();
                    if (!remoteIp.Equals(allowedIp, StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new Exception("You are not allowed to login from this IP address.");
                    }
                }
            }
        }
        await next();
    });
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    portx-dev created

    thx

    Are there any plans to implement this kind of functionality in ABP Commercial?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    As I know we have no plan yet.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    portx-dev created

    ok,thx

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    :)

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 23, 2026, 09:57
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.