public async Task <TTenant> GetTenantAsync(HttpContext httpContext)
        {
            if (httpContext == null)
            {
                return(null);
            }

            //ip restriction security
            var ip = httpContext.Connection.RemoteIpAddress.ToString();

            var tenantId = httpContext.Request.Query["TenantId"].ToString();

            if (!string.IsNullOrWhiteSpace(tenantId))
            {
                var tenant = await _store.GetTenantByIdAsync(tenantId);

                if (tenant != null)
                {
                    if (tenant.IpAddressAllowed(ip))
                    {
                        httpContext.Items["_tenant"]   = tenant;
                        httpContext.Items["_tenantId"] = tenant.Id;
                        _logger.LogInformation("Identified tenant: {tenant} from query string", tenant.Id);
                        return(tenant);
                    }
                }
            }

            httpContext.Items["_tenant"]   = null;
            httpContext.Items["_tenantId"] = null;
            _logger.LogWarning("Unable to identify tenant from query string.");
            return(null);
        }
Example #2
0
 public async Task <TTenant> GetTenantByIdAsync(object key)
 {
     return(await _store.GetTenantByIdAsync(key));
 }