Compare commits
15 Commits
feature/re
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
| e3d75fbfa8 | |||
| 9872c1b88b | |||
| fe4c0696e8 | |||
| 3b752f182f | |||
| 4a2ed52a2f | |||
| 5277896bdc | |||
| 9a02f0e4d6 | |||
| 4cd89c6a83 | |||
| 0bd46f2594 | |||
| 7bbb8ebfe5 | |||
| 035da054d6 | |||
| a025bd87c1 | |||
| ff404ec105 | |||
| 8d1e218eb9 | |||
| db10d185da |
32
Core.Thalos.BuildingBlocks/Adapters/CatalogAdapter.cs
Normal file
32
Core.Thalos.BuildingBlocks/Adapters/CatalogAdapter.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Core.Blueprint.Mongo;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
|
||||||
|
namespace Core.Thalos.BuildingBlocks.Adapters
|
||||||
|
{
|
||||||
|
[CollectionAttributeName("Catalogs")]
|
||||||
|
public class CatalogAdapter : Document
|
||||||
|
{
|
||||||
|
[BsonElement("name")]
|
||||||
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("key")]
|
||||||
|
public string? Key { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("description")]
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<CatalogValue>? Values { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CatalogValue
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonElement("_id")]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string _Id { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("value")]
|
||||||
|
public string Value { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
53
Core.Thalos.BuildingBlocks/Adapters/TenantAdapter.cs
Normal file
53
Core.Thalos.BuildingBlocks/Adapters/TenantAdapter.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using Core.Blueprint.Mongo;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
|
||||||
|
namespace Core.Thalos.BuildingBlocks
|
||||||
|
{
|
||||||
|
[CollectionAttributeName("Tenants")]
|
||||||
|
public class TenantAdapter : Document
|
||||||
|
{
|
||||||
|
[BsonElement("name")]
|
||||||
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("taxIdentifier")]
|
||||||
|
public string TaxIdentifier { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("addressLine1")]
|
||||||
|
public string AddressLine1 { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("addressLine2")]
|
||||||
|
[BsonIgnoreIfNull]
|
||||||
|
public string? AddressLine2 { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("city")]
|
||||||
|
public string City { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("state")]
|
||||||
|
public string State { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("country")]
|
||||||
|
public string Country { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("postalCode")]
|
||||||
|
public string PostalCode { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("contactEmail")]
|
||||||
|
public string ContactEmail { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("contactPhone")]
|
||||||
|
public string ContactPhone { get; set; } = null!;
|
||||||
|
|
||||||
|
[BsonElement("website")]
|
||||||
|
[BsonIgnoreIfNull]
|
||||||
|
public string? Website { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("connectionString")]
|
||||||
|
[BsonIgnoreIfNull]
|
||||||
|
public string? ConnectionString { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("isolated")]
|
||||||
|
public bool Isolated { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
public UserAdapter? User { get; set; }
|
public UserAdapter? User { get; set; }
|
||||||
|
|
||||||
public RoleAdapter? Role { get; set; }
|
public RoleAdapter? Role { get; set; }
|
||||||
|
public TenantAdapter? Tenant { get; set; }
|
||||||
|
|
||||||
public IEnumerable<PermissionAdapter>? Permissions { get; set; }
|
public IEnumerable<PermissionAdapter>? Permissions { get; set; }
|
||||||
public IEnumerable<ModuleAdapter> Modules { get; set; } = null!;
|
public IEnumerable<ModuleAdapter> Modules { get; set; } = null!;
|
||||||
|
|||||||
@@ -16,14 +16,6 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
[CollectionAttributeName("Users")]
|
[CollectionAttributeName("Users")]
|
||||||
public class UserAdapter : Document
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the email address of the user.
|
/// Gets or sets the email address of the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -64,6 +56,14 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
[JsonPropertyName("displayName")]
|
[JsonPropertyName("displayName")]
|
||||||
public string? DisplayName { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the role ID of the user.
|
/// Gets or sets the role ID of the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -72,28 +72,6 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
[JsonPropertyName("roleId")]
|
[JsonPropertyName("roleId")]
|
||||||
public string RoleId { get; set; } = null!;
|
public string RoleId { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the array of companies associated with the user.
|
|
||||||
/// </summary>
|
|
||||||
[BsonElement("companies")]
|
|
||||||
[JsonPropertyName("companies")]
|
|
||||||
public string[] Companies { get; set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the array of projects associated with the user.
|
|
||||||
/// </summary>
|
|
||||||
[BsonElement("projects")]
|
|
||||||
[JsonPropertyName("projects")]
|
|
||||||
public string[]? Projects { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the boolean of the consent form accepted by the user.
|
|
||||||
/// </summary>
|
|
||||||
[BsonElement("consentFormAccepted")]
|
|
||||||
[JsonPropertyName("consentFormAccepted")]
|
|
||||||
[BsonIgnoreIfNull]
|
|
||||||
public bool ConsentFormAccepted { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the timestamp of the last login of the user.
|
/// Gets or sets the timestamp of the last login of the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ using Microsoft.Extensions.Configuration;
|
|||||||
namespace Core.Thalos.BuildingBlocks
|
namespace Core.Thalos.BuildingBlocks
|
||||||
{
|
{
|
||||||
public class GoogleAuthorization(
|
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)
|
public async Task<UserCredential> ExchangeCodeForToken(string code)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,10 +23,20 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Claim name for user's ID.
|
/// Claim name for user's ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string Id = "id";
|
public const string Id = "_id";
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public const string Role = "role";
|
public const string Role = "role";
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The identifier route.
|
/// The identifier route.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string Id = "{id}";
|
public const string Id = "{_id}";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Authentication route.
|
/// The Authentication route.
|
||||||
@@ -74,7 +74,7 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ChangeStatus route.
|
/// The ChangeStatus route.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string ChangeStatus = "{id}/{newStatus}/ChangeStatus";
|
public const string ChangeStatus = "{_id}/{newStatus}/ChangeStatus";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The AddCompany route.
|
/// The AddCompany route.
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Microsoft.Identity.Web;
|
using Microsoft.Identity.Web;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
@@ -87,8 +86,6 @@ namespace Core.Thalos.BuildingBlocks.Configuration
|
|||||||
options.Audience = jwtIssuerOptions?.Audience;
|
options.Audience = jwtIssuerOptions?.Audience;
|
||||||
options.SigningCredentials = new SigningCredentials(rsaPrivateKey, SecurityAlgorithms.RsaSha256);
|
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)
|
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)
|
public static void AddGoogleAuthentication(IServiceCollection services, GoogleAuthSettings googleAuthSettings)
|
||||||
{
|
{
|
||||||
|
services.AddSingleton<GoogleAuthSettings>(googleAuthSettings);
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.DefaultAuthenticateScheme = Schemes.GoogleScheme;
|
options.DefaultAuthenticateScheme = Schemes.GoogleScheme;
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
public class GoogleAccessTokenAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options,
|
public class GoogleAccessTokenAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options,
|
||||||
ILoggerFactory logger,
|
ILoggerFactory logger,
|
||||||
UrlEncoder encoder,
|
UrlEncoder encoder,
|
||||||
IConfiguration config) : AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
|
IConfiguration config,
|
||||||
|
GoogleAuthSettings googleSettings
|
||||||
|
) : AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
|
||||||
|
|
||||||
{
|
{
|
||||||
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||||
{
|
{
|
||||||
@@ -31,7 +34,7 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
idToken,
|
idToken,
|
||||||
new GoogleJsonWebSignature.ValidationSettings
|
new GoogleJsonWebSignature.ValidationSettings
|
||||||
{
|
{
|
||||||
Audience = new[] { config["Authentication:Google:ClientId"]! }
|
Audience = new[] { googleSettings.ClientId! }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (InvalidJwtException)
|
catch (InvalidJwtException)
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ using Microsoft.Extensions.Configuration;
|
|||||||
|
|
||||||
namespace Core.Thalos.BuildingBlocks
|
namespace Core.Thalos.BuildingBlocks
|
||||||
{
|
{
|
||||||
public class GoogleAuthHelper(IConfiguration config) : IGoogleAuthHelper
|
public class GoogleAuthHelper(IConfiguration config, GoogleAuthSettings googleSettings) : IGoogleAuthHelper
|
||||||
{
|
{
|
||||||
public ClientSecrets GetClientSecrets()
|
public ClientSecrets GetClientSecrets()
|
||||||
{
|
{
|
||||||
string clientId = config["Authentication:Google:ClientId"]!;
|
string clientId = googleSettings.ClientId ?? string.Empty;
|
||||||
string clientSecret = config["Authentication:Google:ClientSecret"]!;
|
string clientSecret = googleSettings.ClientSecret ?? string.Empty;
|
||||||
|
|
||||||
return new() { ClientId = clientId, ClientSecret = clientSecret };
|
return new() { ClientId = clientId, ClientSecret = clientSecret };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,8 +87,10 @@ namespace Core.Thalos.BuildingBlocks
|
|||||||
{
|
{
|
||||||
|
|
||||||
new Claim(Claims.Name, adapter?.User?.DisplayName ?? string.Empty),
|
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.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.Role, adapter?.Role?.Name ?? string.Empty),
|
||||||
new Claim(Claims.RoleId, adapter?.Role?.Id ?? string.Empty),
|
new Claim(Claims.RoleId, adapter?.Role?.Id ?? string.Empty),
|
||||||
new Claim(Claims.Applications, JsonSerializer.Serialize(adapter?.Role?.Applications), JsonClaimValueTypes.JsonArray),
|
new Claim(Claims.Applications, JsonSerializer.Serialize(adapter?.Role?.Applications), JsonClaimValueTypes.JsonArray),
|
||||||
|
|||||||
Reference in New Issue
Block a user