MultiTenantIdentityServer4
MultiTenantIdentityServer4 copied to clipboard
there is a way of getting ITenantInfo inside AccountController ??
i am getting this error when trying to get ITenantInfo from DI inside this controller with code authorization workflow InvalidOperationException: Unable to resolve service for type 'Finbuckle.MultiTenant.ITenantInfo' while attempting to activate 'IdentityServerHost.Quickstart.UI.AccountController'.
Thanks.
Hi, I need a little more information. What kind of tenant strategy are you using? What is the url being processed when you get this error?
and i am using code workflow i think the error is happening when there is no tenant found.
i am using both Pathbase like the example and even if i am using static it's makes the same error. startup.cs : services.AddMultiTenant<TenantInfo>() .WithStaticStrategy("tenant-1") .WithBasePathStrategy() .WithPerTenantAuthentication(); app.UseMultiTenant(); app.Use(async (context, next) => { var mtc = context.GetMultiTenantContext<TenantInfo>(); var tenant = mtc?.TenantInfo; if (tenant != null && mtc.StrategyInfo.StrategyType == typeof(BasePathStrategy)) { context.Request.Path.StartsWithSegments("/" + tenant.Identifier, out var matched, out var newPath); context.Request.PathBase = Path.Join(context.Request.PathBase, matched); context.Request.Path = newPath; }
await next.Invoke();
});
and AccountController: private readonly ITenantInfo _tenantInfo; public AccountController( UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager, IIdentityServerInteractionService interaction, IClientStore clientStore, IAuthenticationSchemeProvider schemeProvider, IEventService events, ITenantInfo tenantInfo) { _userManager = userManager; _signInManager = signInManager; _interaction = interaction; _clientStore = clientStore; _schemeProvider = schemeProvider; _events = events; _tenantInfo = tenantInfo;
}
Login method POST: var t = _tenantInfo; var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberLogin, lockoutOnFailure: true);
if you need i will upload zip file of the project i just took the example and added this to the AccountController. Thanks.