From 7bbb8ebfe59c3b083700abe6b868fe5499f10dd8 Mon Sep 17 00:00:00 2001 From: Sergio Matias Date: Fri, 8 Aug 2025 23:05:27 -0600 Subject: [PATCH 1/3] Add tenant property to user --- Core.Thalos.BuildingBlocks/Adapters/TokenAdapter.cs | 1 + Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs | 8 ++++++++ .../Common/Constants/Claims.cs | 12 +++++++++++- Core.Thalos.BuildingBlocks/Services/TokenService.cs | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Core.Thalos.BuildingBlocks/Adapters/TokenAdapter.cs b/Core.Thalos.BuildingBlocks/Adapters/TokenAdapter.cs index c8e5da5..183b768 100644 --- a/Core.Thalos.BuildingBlocks/Adapters/TokenAdapter.cs +++ b/Core.Thalos.BuildingBlocks/Adapters/TokenAdapter.cs @@ -11,6 +11,7 @@ namespace Core.Thalos.BuildingBlocks public UserAdapter? User { get; set; } public RoleAdapter? Role { get; set; } + public TenantAdapter? Tenant { get; set; } public IEnumerable? Permissions { get; set; } public IEnumerable Modules { get; set; } = null!; diff --git a/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs b/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs index 684bdc8..3cc1e90 100644 --- a/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs +++ b/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs @@ -64,6 +64,14 @@ namespace Core.Thalos.BuildingBlocks [JsonPropertyName("displayName")] public string? DisplayName { get; set; } + /// + /// Gets or sets the Tenand ID of the user. + /// + [BsonElement("tenantId")] + [BsonRepresentation(BsonType.ObjectId)] + [JsonPropertyName("tenantId")] + public string TenantId { get; set; } = null!; + /// /// Gets or sets the role ID of the user. /// diff --git a/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs b/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs index b50ac6c..5988595 100644 --- a/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs +++ b/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs @@ -26,7 +26,17 @@ namespace Core.Thalos.BuildingBlocks public const string Id = "id"; /// - /// Claim name for user's role ID. + /// Claim name for user's tenant name. + /// + public const string Tenant = "tenant"; + + /// + /// Claim name for user's tenant identifier. + /// + public const string TenantId = "tenantId"; + + /// + /// Claim name for user's role name. /// public const string Role = "role"; diff --git a/Core.Thalos.BuildingBlocks/Services/TokenService.cs b/Core.Thalos.BuildingBlocks/Services/TokenService.cs index 790ff37..e8d3468 100644 --- a/Core.Thalos.BuildingBlocks/Services/TokenService.cs +++ b/Core.Thalos.BuildingBlocks/Services/TokenService.cs @@ -89,6 +89,8 @@ namespace Core.Thalos.BuildingBlocks new Claim(Claims.Name, adapter?.User?.DisplayName ?? string.Empty), new Claim(Claims.GUID, adapter?.User?.Guid ?? string.Empty), new Claim(Claims.Email, adapter?.User?.Email ?? string.Empty), + new Claim(Claims.Tenant, adapter?.Tenant?.Name ?? string.Empty), + new Claim(Claims.Tenant, adapter?.Tenant?.Id ?? string.Empty), new Claim(Claims.Role, adapter?.Role?.Name ?? string.Empty), new Claim(Claims.RoleId, adapter?.Role?.Id ?? string.Empty), new Claim(Claims.Applications, JsonSerializer.Serialize(adapter?.Role?.Applications), JsonClaimValueTypes.JsonArray), -- 2.49.1 From 0bd46f25943063f76baaca44e4b69ea1f8c00990 Mon Sep 17 00:00:00 2001 From: Sergio Matias Date: Fri, 8 Aug 2025 23:49:44 -0600 Subject: [PATCH 2/3] Remove GUID property from user --- Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs b/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs index 3cc1e90..35f99be 100644 --- a/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs +++ b/Core.Thalos.BuildingBlocks/Adapters/UserAdapter.cs @@ -16,14 +16,6 @@ namespace Core.Thalos.BuildingBlocks [CollectionAttributeName("Users")] public class UserAdapter : Document { - /// - /// Gets or sets the guid of the user. - /// - [BsonElement("guid")] - [BsonRepresentation(BsonType.String)] - [JsonPropertyName("guid")] - public string? Guid { get; set; } - /// /// Gets or sets the email address of the user. /// -- 2.49.1 From 4cd89c6a832270dc75ccc9310086c0d19ffaa915 Mon Sep 17 00:00:00 2001 From: Sergio Matias Date: Fri, 8 Aug 2025 23:51:23 -0600 Subject: [PATCH 3/3] Fix id property in user claims --- Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs | 2 +- Core.Thalos.BuildingBlocks/Services/TokenService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs b/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs index 5988595..5bd3e65 100644 --- a/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs +++ b/Core.Thalos.BuildingBlocks/Common/Constants/Claims.cs @@ -23,7 +23,7 @@ namespace Core.Thalos.BuildingBlocks /// /// Claim name for user's ID. /// - public const string Id = "id"; + public const string Id = "_id"; /// /// Claim name for user's tenant name. diff --git a/Core.Thalos.BuildingBlocks/Services/TokenService.cs b/Core.Thalos.BuildingBlocks/Services/TokenService.cs index e8d3468..84d537b 100644 --- a/Core.Thalos.BuildingBlocks/Services/TokenService.cs +++ b/Core.Thalos.BuildingBlocks/Services/TokenService.cs @@ -87,7 +87,7 @@ namespace Core.Thalos.BuildingBlocks { new Claim(Claims.Name, adapter?.User?.DisplayName ?? string.Empty), - new Claim(Claims.GUID, adapter?.User?.Guid ?? string.Empty), + new Claim(Claims.Id, adapter?.User?.Id ?? string.Empty), new Claim(Claims.Email, adapter?.User?.Email ?? string.Empty), new Claim(Claims.Tenant, adapter?.Tenant?.Name ?? string.Empty), new Claim(Claims.Tenant, adapter?.Tenant?.Id ?? string.Empty), -- 2.49.1