Open Closed

We want to extend api/account/login service to auto resolve tenant, How can we extend it? #4457


User avatar
0
mian.tayyab@innoppia.pk created

Hi Support Team,

We have a use case that get the email and password and Auto Resolve Tenant. We have successfully implemented via MVC UI but We need to implement it with API. api/account/login body { "userNameOrEmailAddress": "string", "password": "string", "rememberMe": true }

we want to login without Tenant ID and auto resolve their tenant.

Can you please guide me which AppService will be inherited and which Function.

Thanks


9 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team

    Hi,

    You can custom the Tenant resolver instead of AppService , see: https://docs.abp.io/en/abp/latest/Multi-Tenancy#custom-tenant-resolvers

  • User Avatar
    0
    mian.tayyab@innoppia.pk created

    I think you did not understand the requirement. We want to let users login via API call (without redirecting them to identity server). There is login api api/account/login Payload { "userNameOrEmailAddress": "emailAddress", "password": "string", "rememberMe": true }

    User may be belong to any tenant. When login request come, we want to learn their tenant and resolve it. Here is the sample code which we added custom login page for identity server.

    We want to implement same kind of logic on Login api call.

  • User Avatar
    0
    liangshiwei created
    Support Team

    Hi,

    May I ask, Which auth server are you using, openiddict or identityserver?

  • User Avatar
    0
    mian.tayyab@innoppia.pk created

    IdentityServer

    Can you please respond quickly Thanks

  • User Avatar
    0
    liangshiwei created
    Support Team

    Hi,

    You can replace the AbpResourceOwnerPasswordValidator service. https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs#L65

    PreConfigure<IdentityBuilder>(identityBuilder =>
    {
        identityBuilder.AddResourceOwnerValidator<MyAbpResourceOwnerPasswordValidator>();
    });
    
  • User Avatar
    0
    mian.tayyab@innoppia.pk created

    Hi,

    there is no such AddResourceOwnerValidator in

    PreConfigure<IdentityBuilder>(identityBuilder =>
    {
        identityBuilder.AddResourceOwnerValidator<MyAbpResourceOwnerPasswordValidator>();
    });
    

    Secondly I configured it as and it never hits on api/account/login call

     PreConfigure<IIdentityServerBuilder>(identityServerBuilder =>
            {
                identityServerBuilder.AddResourceOwnerValidator<CustomAbpResourceOwnerPasswordValidator>();
            });
    

    Can you please check it one more time and guide. Secondly What if we use OpenIddict then How it can be managed?

  • User Avatar
    0
    liangshiwei created
    Support Team

    Hi,

    Sorry, should be :

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        PreConfigure<IdentityServerBuilder>(identityBuilder =>
        {
            identityBuilder.AddResourceOwnerValidator<MyAbpResourceOwnerPasswordValidator>();
        });
    }
    

    For OpenIddict, you can replace the TokenController

  • User Avatar
    0
    mian.tayyab@innoppia.pk created

    Hello @liangshiwei

    Sorry, I think you could not understand the requirement. Volo.Abp.Account.Public.Web.Areas.Account.Controllers.AccountController is being used for api/account/login

    You were pushing me into another direction.

  • User Avatar
    0
    liangshiwei created
    Support Team

    Sorry, I thought the API you were talking about was the connect/token endpoint.

    Volo.Abp.Account.Public.Web.Areas.Account.Controllers.AccountController is being used for api/account/login

    We don't have such an app service, all things are done in the login model.

    There are some differences between IdentityServer and OpenIddict

    IdentityServer, you can custom login page: IdentityServerSupportedLoginModel

    [ExposeServices(typeof(LoginModel))]
    public class MyLoginModel : IdentityServerSupportedLoginModel
    {
    }
    

    Openiddict you can custom login page: OpenIddictSupportedLoginModel

    [ExposeServices(typeof(LoginModel))]
    public class MyLoginModel : OpenIddictSupportedLoginModel 
    {
    }
    
Made with ❤️ on ABP v8.2.0 Updated on February 19, 2024, 12:29