Open Closed

Use a different authentication method for specific tenant #6637


User avatar
0
manuel42 created
  • ABP Framework version: v8.0.3
  • UI Type:MVC
  • 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:

We have a ABP based application running on azure. Is it supported by ABP to implement a specific authorization method only valid for a special tenant ?

This means the user of this special tenant should able to login with their windows user without using a password for authentication. All users from other tenants need to pass their user and password to login.

Thank you in advance for the help!


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This can be done, but you will need a custom module code

    For example:

    Configure allowed tenants:

    appsettings.json

     "ExternalTenantProviders": {
        "tenantA" : "windows,google",
        "tenantB" : "google"
     }
    

    Here I used a configuration file, you can create an entity stored to the database

    Replace the ExternalProviderSettingsHelper

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(ExternalProviderSettingsHelper))]
    public class MyExternalProviderSettingsHelper : ExternalProviderSettingsHelper
    {
        private readonly IConfiguration _configuration;
        private readonly ICurrentTenant _currentTenant;
        
        public MyExternalProviderSettingsHelper(ICurrentTenant currentTenant, IOptions<AbpExternalProviderOptions> externalProvidersOptions, ISettingManager settingManager, IJsonSerializer jsonSerializer, IConfiguration configuration) : base(currentTenant, externalProvidersOptions, settingManager, jsonSerializer)
        {
            _currentTenant = currentTenant;
            _configuration = configuration;
        }
    
        public override async Task<List<ExternalProviderSettings>> GetAllAsync()
        {
            var settings = await base.GetAllAsync();
    
            if (_currentTenant.IsAvailable)
            {
                var allowedProviders = _configuration[$"ExternalTenantProviders:{_currentTenant.Name}"];
    
                if (allowedProviders.IsNullOrWhiteSpace())
                {
                    settings.Clear();
                }
                else
                {
                    settings = settings.Where(x => allowedProviders.Split(",").Contains(x.Name)).ToList();
                }
            }
    
            return settings;
        }
    }
    
  • User Avatar
    0
    manuel42 created

    Thank you for the example. What do you mean with "custom module code" ? I am not sure If I understand it correct, I need to replace the service in the application template right ?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I am not sure If I understand it correct, I need to replace the service in the application template right ?

    Yes. here is the document: https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Guide

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11