0

I using asp.net boilerplate as Web- project, and back-end for mobile apps.

The app is multitenancy.

I have a method to Validate mobile access code.

Here is it code

[AllowAnonymous]
        [ProducesResponseType(typeof(UserDataModel), 200)]
        [ProducesResponseType(401)]
        [HttpPost]
        public async Task<IActionResult> ValidateMobileAccessCode(MobileInvitationCodeInput input)
        {
            var tenant = await _tenantRepository.GetAll().Where(x => x.Id == AbpSession.TenantId).FirstOrDefaultAsync();
            var userId = await _userMobileAccessCodeService.ValidateCodeAndGetUserIdAsync(input.CodeValue);
            if (userId == null)
            {
                return Unauthorized();
            }

            var user = await _userManager.GetUserOrNullAsync(new UserIdentifier(AbpSession.TenantId, userId.Value));
            return Ok(new UserDataModel
            {
                UserId = userId.Value,
                CodeValue = input.CodeValue,
                Name = user.FullName,
                EmailAddress = user.EmailAddress,
                CompanyName = tenant == null ? "Host tenant" : tenant.TenancyName
            });
        }

But this row var tenant = await _tenantRepository.GetAll().Where(x => x.Id == AbpSession.TenantId).FirstOrDefaultAsync(); will return null, as I not have session in mobile app.

How I can get tenant id for the mobile app?

I tried to find solution over docs, but no luck

Eugene Sukh
  • 2,357
  • 4
  • 42
  • 86

1 Answers1

0

You can set up TenantId by Header Abp.TenantId. There is also possibility to resolve tenant throw a Custom Tenant Resolver Mechanism. You need to implement middleware which will be run before your request will be process and add this to configuration.

Configuration.MultiTenancy.Resolvers.Add<DefaultTenantResolveContributor>();

You should inheritate from interface:

ITenantResolveContributor
CrazyBaran
  • 572
  • 3
  • 20