Adding tenant_id to claims, so that it can be retrieved from HttpContext.User

This commit is contained in:
espent1004 2020-02-01 20:51:39 +01:00
parent 48e795fda2
commit 069baa2aad
3 changed files with 7 additions and 2 deletions

View File

@ -106,6 +106,11 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Services
if (!string.IsNullOrWhiteSpace(user.ZipCode))
claims.Add(new Claim("address_zip_code", user.ZipCode));
if (user.TenantId != 0)
{
claims.Add(new Claim("tenant_id", user.TenantId.ToString()));
}
if (_userManager.SupportsUserEmail)
{
claims.AddRange(new[]

View File

@ -95,7 +95,6 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
{
var user = _appUserParser.Parse(HttpContext.User);
var vm = await _orderSvc.GetMyOrders(user);
if (user.TenantId == 1)

View File

@ -33,7 +33,8 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
SecurityNumber = claims.Claims.FirstOrDefault(x => x.Type == "card_security_number")?.Value ?? "",
State = claims.Claims.FirstOrDefault(x => x.Type == "address_state")?.Value ?? "",
Street = claims.Claims.FirstOrDefault(x => x.Type == "address_street")?.Value ?? "",
ZipCode = claims.Claims.FirstOrDefault(x => x.Type == "address_zip_code")?.Value ?? ""
ZipCode = claims.Claims.FirstOrDefault(x => x.Type == "address_zip_code")?.Value ?? "",
TenantId = int.Parse(claims.Claims.FirstOrDefault(x => x.Type == "tenant_id")?.Value ?? "0")
};
}
throw new ArgumentException(message: "The principal must be a ClaimsPrincipal", paramName: nameof(principal));