Tenant could not be resolved with HostStrategy and DistributedCacheStore
Hi, I use redis as my distributed cache store and all tenant relevant information are stored in there in the following manner:
- "__tenant__identifier__MyTenantName"
- "__tenant__id__d59b44f1-1457-4be8-8f07-1aaf1226f500"
The HostStrategy gets my tenant name from the subdomain (https://MyTenantName.mydomain.com) and the identifier is resolved correctly.
But if the request is like (https://MYTENANTNAME.mydomain.com) the tenant is not found.
This is because redis is case sensitive. Did I miss something or would it be possible that the "DistributedCacheStore.cs" make all lowercase before reading and writing?
Thanks!
@marcelbeutner sorry for the slow reply. Did you find a solution or workaround?
I plan to add a normalized tenant identifier to prevent these issues but for now I'd recommend implementing IMultiTenantStrategy and/or IMultiTenantStore yourself to explicitly handle case as you see fit.
Thanks Andrew for your answer!
Yes, I have indeed found a workaround that solves my problem. I copied the DistributedCacheStore class and nomalized the keys with "ToLower()".
So far we haven't found any problems, not even in production, so I think it would be conceivable to include this in the master branch as well.
By the way: This library is really fantastic and I think it's a must for multi-tenant applications - great work!!
Best regards Marcel
Here are my little changes:
`
///
///
///
await cache.SetStringAsync($"{keyPrefix}id__{tenantInfo.Id}".ToLower(), bytes, options);
await cache.SetStringAsync($"{keyPrefix}identifier__{tenantInfo.Identifier}".ToLower(), bytes, options);
return true;
}
///
var result = JsonSerializer.Deserialize<TTenantInfo>(bytes);
// Refresh the identifier version to keep things synced
await cache.RefreshAsync($"{keyPrefix}identifier__{result?.Identifier}".ToLower());
return result;
}
///
///
var result = JsonSerializer.Deserialize<TTenantInfo>(bytes);
// Refresh the identifier version to keep things synced
await cache.RefreshAsync($"{keyPrefix}id__{result?.Id}".ToLower());
return result;
}
///
await cache.RemoveAsync($"{keyPrefix}id__{result.Id}".ToLower());
await cache.RemoveAsync($"{keyPrefix}identifier__{result.Identifier}".ToLower());
return true;
}
///