9 Commits

Author SHA1 Message Date
fe4c0696e8 Merge branch 'development' into feature/add-tenant-to-user 2025-08-26 14:16:33 -06:00
3b752f182f fix 2025-08-26 14:11:09 -06:00
4a2ed52a2f fix 2025-08-26 14:10:48 -06:00
5277896bdc Add tenant identifier in user property 2025-08-26 14:10:29 -06:00
9a02f0e4d6 Fixed google settings 2025-08-22 21:04:25 -06:00
4cd89c6a83 Fix id property in user claims 2025-08-08 23:51:23 -06:00
0bd46f2594 Remove GUID property from user 2025-08-08 23:49:44 -06:00
7bbb8ebfe5 Add tenant property to user 2025-08-08 23:05:27 -06:00
035da054d6 Fix Change status route 2025-08-07 13:16:37 -06:00
9 changed files with 45 additions and 22 deletions

View File

@@ -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<PermissionAdapter>? Permissions { get; set; }
public IEnumerable<ModuleAdapter> Modules { get; set; } = null!;

View File

@@ -16,14 +16,6 @@ namespace Core.Thalos.BuildingBlocks
[CollectionAttributeName("Users")]
public class UserAdapter : Document
{
/// <summary>
/// Gets or sets the guid of the user.
/// </summary>
[BsonElement("guid")]
[BsonRepresentation(BsonType.String)]
[JsonPropertyName("guid")]
public string? Guid { get; set; }
/// <summary>
/// Gets or sets the email address of the user.
/// </summary>
@@ -64,6 +56,14 @@ namespace Core.Thalos.BuildingBlocks
[JsonPropertyName("displayName")]
public string? DisplayName { get; set; }
/// <summary>
/// Gets or sets the Tenand ID of the user.
/// </summary>
[BsonElement("tenantId")]
[BsonRepresentation(BsonType.ObjectId)]
[JsonPropertyName("tenantId")]
public string TenantId { get; set; } = null!;
/// <summary>
/// Gets or sets the role ID of the user.
/// </summary>
@@ -96,5 +96,13 @@ namespace Core.Thalos.BuildingBlocks
[BsonRepresentation(BsonType.String)]
[JsonPropertyName("token")]
public string? Token { get; set; } = null;
/// <summary>
/// Gets or sets the tenant identifier associated with the user.
/// </summary>
[BsonElement("tenantId")]
[BsonRepresentation(BsonType.ObjectId)]
[JsonPropertyName("tenantId")]
public string? TenantId { get; set; }
}
}

View File

@@ -5,9 +5,9 @@ using Microsoft.Extensions.Configuration;
namespace Core.Thalos.BuildingBlocks
{
public class GoogleAuthorization(
IGoogleAuthHelper googleHelper, IConfiguration config) : IGoogleAuthorization
IGoogleAuthHelper googleHelper, IConfiguration config, GoogleAuthSettings googlesettings) : IGoogleAuthorization
{
private string RedirectUrl = config["Authentication:Google:RedirectUri"]!;
private string RedirectUrl = googlesettings.RedirectUri ?? string.Empty;
public async Task<UserCredential> ExchangeCodeForToken(string code)
{

View File

@@ -23,10 +23,20 @@ namespace Core.Thalos.BuildingBlocks
/// <summary>
/// Claim name for user's ID.
/// </summary>
public const string Id = "id";
public const string Id = "_id";
/// <summary>
/// Claim name for user's role ID.
/// Claim name for user's tenant name.
/// </summary>
public const string Tenant = "tenant";
/// <summary>
/// Claim name for user's tenant identifier.
/// </summary>
public const string TenantId = "tenantId";
/// <summary>
/// Claim name for user's role name.
/// </summary>
public const string Role = "role";

View File

@@ -74,7 +74,7 @@ namespace Core.Thalos.BuildingBlocks
/// <summary>
/// The ChangeStatus route.
/// </summary>
public const string ChangeStatus = "{id}/{newStatus}/ChangeStatus";
public const string ChangeStatus = "{_id}/{newStatus}/ChangeStatus";
/// <summary>
/// The AddCompany route.

View File

@@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Web;
using Microsoft.IdentityModel.Tokens;
using System.Security.Cryptography;
@@ -87,8 +86,6 @@ namespace Core.Thalos.BuildingBlocks.Configuration
options.Audience = jwtIssuerOptions?.Audience;
options.SigningCredentials = new SigningCredentials(rsaPrivateKey, SecurityAlgorithms.RsaSha256);
});
services.AddSingleton<IOptions<JwtIssuerOptions>>(Microsoft.Extensions.Options.Options.Create(jwtIssuerOptions));
}
public static void AddAzureAuthentication(AuthSettings authSettings, IConfiguration configuration, IServiceCollection services)
@@ -116,6 +113,8 @@ namespace Core.Thalos.BuildingBlocks.Configuration
public static void AddGoogleAuthentication(IServiceCollection services, GoogleAuthSettings googleAuthSettings)
{
services.AddSingleton<GoogleAuthSettings>(googleAuthSettings);
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = Schemes.GoogleScheme;

View File

@@ -11,7 +11,10 @@ namespace Core.Thalos.BuildingBlocks
public class GoogleAccessTokenAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
IConfiguration config) : AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
IConfiguration config,
GoogleAuthSettings googleSettings
) : AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
{
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
@@ -31,7 +34,7 @@ namespace Core.Thalos.BuildingBlocks
idToken,
new GoogleJsonWebSignature.ValidationSettings
{
Audience = new[] { config["Authentication:Google:ClientId"]! }
Audience = new[] { googleSettings.ClientId! }
});
}
catch (InvalidJwtException)

View File

@@ -4,12 +4,12 @@ using Microsoft.Extensions.Configuration;
namespace Core.Thalos.BuildingBlocks
{
public class GoogleAuthHelper(IConfiguration config) : IGoogleAuthHelper
public class GoogleAuthHelper(IConfiguration config, GoogleAuthSettings googleSettings) : IGoogleAuthHelper
{
public ClientSecrets GetClientSecrets()
{
string clientId = config["Authentication:Google:ClientId"]!;
string clientSecret = config["Authentication:Google:ClientSecret"]!;
string clientId = googleSettings.ClientId ?? string.Empty;
string clientSecret = googleSettings.ClientSecret ?? string.Empty;
return new() { ClientId = clientId, ClientSecret = clientSecret };
}

View File

@@ -87,8 +87,10 @@ 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),
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),