Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bbb923f
Update versions, remove Polly, and add configuration files
giovanninocco Nov 30, 2024
86875f5
Enhance logging, JWT options, and health checks
giovanninocco Dec 2, 2024
8e48cfa
Standardize property names and improve documentation
giovanninocco Dec 2, 2024
3fbbc7e
Upgrade to .NET 9.0 and refine project configurations
giovanninocco Dec 2, 2024
0e6140b
Add OpenTelemetry support and update various configurations
giovanninocco Dec 3, 2024
af280e0
Refactor namespaces and update OpenTelemetry config
giovanninocco Dec 4, 2024
5f0ca21
Add console exporter support for OpenTelemetry
giovanninocco Dec 4, 2024
42292cf
Add new service, project, and OpenTelemetry config
giovanninocco Dec 4, 2024
3df7280
Add OtlpEndpoint to LoggerOptions and update exception handling
giovanninocco Dec 4, 2024
eda7085
Update error handling, tracing, and configuration
giovanninocco Dec 4, 2024
2ba4d28
Refactor and update configurations and dependencies
giovanninocco Dec 4, 2024
db339c2
Refactor for multiple roles and sync methods
giovanninocco Dec 5, 2024
dd2dfdf
Add CreateAdmin feature and refactor user creation
giovanninocco Dec 5, 2024
07bee95
Refactor and improve nullability handling
giovanninocco Dec 5, 2024
74926b3
Refactor and update codebase for C# 9.0 features
giovanninocco Dec 11, 2024
b525d35
Refactor JWT handling and improve code readability
giovanninocco Dec 13, 2024
5636ddc
Refactor authentication and JWT handling components
giovanninocco Dec 13, 2024
5894fd7
Enhance JWT authentication and code organization
giovanninocco Dec 14, 2024
48b01f3
Add JWT authentication and enhance authorization policies
giovanninocco Dec 14, 2024
23aa7c6
Enhance GenocsBuilder and update Program.cs structure
giovanninocco Dec 14, 2024
1040881
Update configuration settings and service details
giovanninocco Dec 14, 2024
2654fe6
Enable services and enhance configuration settings
giovanninocco Dec 14, 2024
f24c465
Update package versions and modify exception logic
giovanninocco Dec 14, 2024
5badcca
Update CHANGELOG for v7.2.0 release with recent changes and improvements
giovanninocco Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,52 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v7.2.0](https://github.com/Genocs/genocs-library/compare/v7.1.0...v7.2.0)

> 14 December 2024

- Update versions, remove Polly, and add configuration files [`bbb923f`](https://github.com/Genocs/genocs-library/commit/bbb923f2c15dc5bd99237d76a0114a2984f9d168)
- Refactor and update codebase for C# 9.0 features [`74926b3`](https://github.com/Genocs/genocs-library/commit/74926b3edc638b9a7179ae6d3e746eec346cd0ab)
- Add new service, project, and OpenTelemetry config [`42292cf`](https://github.com/Genocs/genocs-library/commit/42292cffc5b4b329377bf6adaf243504b3bc6073)
- Refactor for multiple roles and sync methods [`db339c2`](https://github.com/Genocs/genocs-library/commit/db339c2ef27cd15cbbde0bfe9b1c9dac6e0a0c12)
- Refactor authentication and JWT handling components [`5636ddc`](https://github.com/Genocs/genocs-library/commit/5636ddc9479d0a80a9c9c87c9175dc33f38d55bb)
- Update configuration settings and service details [`1040881`](https://github.com/Genocs/genocs-library/commit/104088196666c31668f93a52fb89d6d2a70b7943)
- Refactor namespaces and update OpenTelemetry config [`af280e0`](https://github.com/Genocs/genocs-library/commit/af280e0b6a7b08ab333f0ff2339aa068811f0f27)
- Refactor and update configurations and dependencies [`2ba4d28`](https://github.com/Genocs/genocs-library/commit/2ba4d2829a4e635e2b52b0ea022716edd75c6f1c)
- Add OpenTelemetry support and update various configurations [`0e6140b`](https://github.com/Genocs/genocs-library/commit/0e6140ba2ebb2bac7671e28e925546cca4611009)
- Add CreateAdmin feature and refactor user creation [`dd2dfdf`](https://github.com/Genocs/genocs-library/commit/dd2dfdfe40cd45cc3ba02d7aaa04f7b8c1368f47)
- Upgrade to .NET 9.0 and refine project configurations [`3fbbc7e`](https://github.com/Genocs/genocs-library/commit/3fbbc7e5597c7bb0b59383b39b0b4aedbf99bc8b)
- Enhance JWT authentication and code organization [`5894fd7`](https://github.com/Genocs/genocs-library/commit/5894fd7232171ff202a9c2946b88602a149eec03)
- Add JWT authentication and enhance authorization policies [`48b01f3`](https://github.com/Genocs/genocs-library/commit/48b01f31ac67b5bb9e60dcaf9d119031707bf23c)
- Enhance logging, JWT options, and health checks [`86875f5`](https://github.com/Genocs/genocs-library/commit/86875f5d53e372be8a82f1bd2030aaacda6a7914)
- Enable services and enhance configuration settings [`2654fe6`](https://github.com/Genocs/genocs-library/commit/2654fe6b756e97034960ba73c39b57429678295f)
- Refactor JWT handling and improve code readability [`b525d35`](https://github.com/Genocs/genocs-library/commit/b525d35a18add383b0960d4405069b91a97decd5)
- Refactor and improve nullability handling [`07bee95`](https://github.com/Genocs/genocs-library/commit/07bee95f1226ab4406078380da2b25744f413d8e)
- Add console exporter support for OpenTelemetry [`5f0ca21`](https://github.com/Genocs/genocs-library/commit/5f0ca21d0f36032c62102833ea95ad63c1b809aa)
- Update error handling, tracing, and configuration [`eda7085`](https://github.com/Genocs/genocs-library/commit/eda7085847b057983269dd6fd08c237644dfe553)
- Enhance GenocsBuilder and update Program.cs structure [`23aa7c6`](https://github.com/Genocs/genocs-library/commit/23aa7c6418365f49be9de771be028dae7758c02a)
- Standardize property names and improve documentation [`8e48cfa`](https://github.com/Genocs/genocs-library/commit/8e48cfa891777398b276965dd3f02d3b536e75ad)
- Add OtlpEndpoint to LoggerOptions and update exception handling [`3df7280`](https://github.com/Genocs/genocs-library/commit/3df72803f83a03922523c036cfe2686cd9c0bfec)
- Update package versions and modify exception logic [`f24c465`](https://github.com/Genocs/genocs-library/commit/f24c46508d67da55fab3cc96c3ebb295977e9222)

#### [v7.1.0](https://github.com/Genocs/genocs-library/compare/v7.0.0...v7.1.0)

> 29 November 2024

- Update packages and refactor MongoDB repository methods [`#126`](https://github.com/Genocs/genocs-library/pull/126)
- Ver 700 [`#125`](https://github.com/Genocs/genocs-library/pull/125)
- Update CHANGELOG for v7.0.0 release with recent changes and improvements [`#121`](https://github.com/Genocs/genocs-library/pull/121)
- Refactor RabbitMQ client to use async methods [`d5cf8ab`](https://github.com/Genocs/genocs-library/commit/d5cf8abe6b4a4a21712579373858431ea3f5589c)
- Update appsettings and refactor code for services [`b9e6e8c`](https://github.com/Genocs/genocs-library/commit/b9e6e8c43a700c1865f1ed23c561b0c69a4ce417)
- Update Docker, health checks, and service configurations [`828c7a7`](https://github.com/Genocs/genocs-library/commit/828c7a775b3eb095204e5df0e62614bfbebe6705)
- Add .env template, update appsettings for Docker compatibility, and modify service configurations [`c3c6488`](https://github.com/Genocs/genocs-library/commit/c3c64884098deafec6053bd3838eaefbb67bc4ea)
- Update package references to Genocs.Core and related packages to version 7.1.0 [`a8b8c4a`](https://github.com/Genocs/genocs-library/commit/a8b8c4a9baff9e54c9e38a0cd20bad4bbea5a0dd)
- Refactor and update nullability and configurations [`992c33d`](https://github.com/Genocs/genocs-library/commit/992c33d33e686d5f573d899c911cd297ad086637)
- Refactor constructors and update Program.cs endpoints [`4f14136`](https://github.com/Genocs/genocs-library/commit/4f14136419cb43d8619721f02ce4082c92d880fb)
- Refactor service registration and update dependencies [`78a7892`](https://github.com/Genocs/genocs-library/commit/78a789238db6c2e6def7b1d8103facf1092191e5)
- Upgrade packages and modify NotificationId property [`77bbd75`](https://github.com/Genocs/genocs-library/commit/77bbd75766d14dcde87d386e84e3ccfb248a5062)
- Disable Azure logging and clear connection strings [`3a44081`](https://github.com/Genocs/genocs-library/commit/3a440812ef71aa64ecf0a1a829943d8c2723edd6)

### [v7.0.0](https://github.com/Genocs/genocs-library/compare/v6.4.0...v7.0.0)

> 24 November 2024
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)dotnet.ruleset</CodeAnalysisRuleSet>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<Version>6.3.0</Version>
<Version>7.1.0</Version>
<LangVersion>13.0</LangVersion>
<Company>Genocs</Company>
<Copyright>Genocs 2024</Copyright>
Expand Down
15 changes: 15 additions & 0 deletions containers/infrastructure-monitoring.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
services:
aspire:
image: mcr.microsoft.com/dotnet/aspire-dashboard:9.0
hostname: aspire_dashboard
container_name: aspire_dashboard
ports:
- 18888:18888
- 4318:18889

environment:
- DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS=true

networks:
- genocs
# network_mode: host

grafana:
image: grafana/grafana
hostname: grafana
Expand Down
15 changes: 14 additions & 1 deletion genocs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application"
src\apps\docker-compose.override.yml = src\apps\docker-compose.override.yml
src\apps\docker-compose.yml = src\apps\docker-compose.yml
src\apps\identity-webapi.dockerfile = src\apps\identity-webapi.dockerfile
src\apps\order-webapi.dockerfile = src\apps\order-webapi.dockerfile
src\apps\local.env = src\apps\local.env
src\apps\order-webapi.dockerfile = src\apps\order-webapi.dockerfile
src\apps\product-webapi.dockerfile = src\apps\product-webapi.dockerfile
src\apps\signalr-webapi.dockerfile = src\apps\signalr-webapi.dockerfile
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Genocs.Secrets.AzureKeyVault", "src\Genocs.Secrets.AzureKeyVault\Genocs.Secrets.AzureKeyVault.csproj", "{ECBF1AEE-AE3A-4F81-9943-5675169DEFA7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Genocs.OpenTelemetry", "src\Genocs.OpenTelemetry\Genocs.OpenTelemetry.csproj", "{62380657-23D0-0ECD-8FFE-0B1DA5461D37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Genocs.Core.Demo.HelloWorld", "src\Genocs.Core.Demo.HelloWorld\Genocs.Core.Demo.HelloWorld.csproj", "{D7C394CF-487D-470D-B05C-CC2DD7EC290B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -297,6 +301,14 @@ Global
{ECBF1AEE-AE3A-4F81-9943-5675169DEFA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECBF1AEE-AE3A-4F81-9943-5675169DEFA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECBF1AEE-AE3A-4F81-9943-5675169DEFA7}.Release|Any CPU.Build.0 = Release|Any CPU
{62380657-23D0-0ECD-8FFE-0B1DA5461D37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62380657-23D0-0ECD-8FFE-0B1DA5461D37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62380657-23D0-0ECD-8FFE-0B1DA5461D37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62380657-23D0-0ECD-8FFE-0B1DA5461D37}.Release|Any CPU.Build.0 = Release|Any CPU
{D7C394CF-487D-470D-B05C-CC2DD7EC290B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7C394CF-487D-470D-B05C-CC2DD7EC290B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7C394CF-487D-470D-B05C-CC2DD7EC290B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7C394CF-487D-470D-B05C-CC2DD7EC290B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -325,6 +337,7 @@ Global
{B2028A73-6C94-4166-A0BB-22080805E351} = {140B7191-88E9-4EEE-9D86-9A70839F8507}
{6CE8740F-8561-481B-AC9F-D1E73C449235} = {B2028A73-6C94-4166-A0BB-22080805E351}
{B184733D-2415-4517-BC65-26ED22EEB2C2} = {51A2E158-4686-4764-91D5-3CDDD06280D4}
{D7C394CF-487D-470D-B05C-CC2DD7EC290B} = {220036E9-322D-4D4A-BA98-21DCF111C50A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FF634A51-3CA4-4FB3-A8ED-71C403516166}
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "8.0.10",
"version": "9.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}
}
2 changes: 1 addition & 1 deletion launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}
}
}
}
}
31 changes: 12 additions & 19 deletions src/Genocs.Auth/AccessTokenValidatorMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,36 @@ namespace Genocs.Auth;
/// <summary>
/// The access token validator middleware.
/// </summary>
public class AccessTokenValidatorMiddleware : IMiddleware
/// <remarks>
/// The AccessTokenValidatorMiddleware constructor.
/// </remarks>
/// <param name="accessTokenService">The access token service.</param>
/// <param name="options">The options.</param>
public class AccessTokenValidatorMiddleware(IAccessTokenService accessTokenService, JwtOptions options) : IMiddleware
{
private readonly IAccessTokenService _accessTokenService;
private readonly IEnumerable<string> _endpoints;

/// <summary>
/// The AccessTokenValidatorMiddleware constructor.
/// </summary>
/// <param name="accessTokenService">The access token service.</param>
/// <param name="options">The options.</param>
public AccessTokenValidatorMiddleware(IAccessTokenService accessTokenService, JwtOptions options)
{
_accessTokenService = accessTokenService;
_endpoints = options.AllowAnonymousEndpoints ?? Enumerable.Empty<string>();
}
private readonly IAccessTokenService _accessTokenService = accessTokenService;
private readonly IEnumerable<string> _allowAnonymousEndpoints = options.AllowAnonymousEndpoints ?? [];

/// <summary>
/// The InvokeAsync method.
/// </summary>
/// <param name="context">The http context.</param>
/// <param name="next">The request delegate.</param>
/// <returns></returns>
/// <returns>The task.</returns>
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
string path = context.Request.Path.HasValue ? context.Request.Path.Value : string.Empty;

if (_endpoints.Contains(path))
// Skip check on AnonymousEndpoints
if (_allowAnonymousEndpoints.Contains(path))
{
await next(context);

return;
}

if (await _accessTokenService.IsCurrentActiveToken())
if (_accessTokenService.IsCurrentActiveToken())
{
await next(context);

return;
}

Expand Down
30 changes: 27 additions & 3 deletions src/Genocs.Auth/Configurations/JwtOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.IdentityModel.Tokens;

namespace Genocs.Auth.Configurations;

public class JwtOptions
Expand All @@ -14,7 +16,12 @@ public class JwtOptions

public IEnumerable<string>? AllowAnonymousEndpoints { get; set; }
public CertificateOptions? Certificate { get; set; }
public string? Algorithm { get; set; }

/// <summary>
/// The algorithm used to sign the token.
/// Defaults to SecurityAlgorithms.HmacSha256 'HS256'.
/// </summary>
public string Algorithm { get; set; } = SecurityAlgorithms.HmacSha256;
public string? Issuer { get; set; }
public string? IssuerSigningKey { get; set; }
public string? Authority { get; set; }
Expand All @@ -31,7 +38,12 @@ public class JwtOptions
public bool RequireHttpsMetadata { get; set; }
public bool RequireExpirationTime { get; set; } = true;
public bool RequireSignedTokens { get; set; } = true;
public int ExpiryMinutes { get; set; }

/// <summary>
/// The expiration time of the token in minutes.
/// Defaults to 60 minutes.
/// </summary>
public int ExpiryMinutes { get; set; } = 60;
public TimeSpan? Expiry { get; set; }
public string? ValidAudience { get; set; }
public IEnumerable<string>? ValidAudiences { get; set; }
Expand Down Expand Up @@ -65,19 +77,31 @@ public class JwtOptions
/// Defaults to true.
/// </summary>
public bool IncludeErrorDetails { get; set; } = true;

public string? AuthenticationType { get; set; }
public string? NameClaimType { get; set; }

/// <summary>
/// The claim type that will be used to determine the user's roles.
/// Defaults to "Role".
/// Default is "Role".
/// </summary>
public string RoleClaimType { get; set; } = "Role";

public class CertificateOptions
{
/// <summary>
/// The location of the certificate.
/// </summary>
public string? Location { get; set; }

/// <summary>
/// The certificate as a byte array.
/// </summary>
public string? RawData { get; set; }

/// <summary>
/// The certificate password.
/// </summary>
public string? Password { get; set; }
}
}
11 changes: 2 additions & 9 deletions src/Genocs.Auth/DisabledAuthenticationPolicyEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ internal sealed class DisabledAuthenticationPolicyEvaluator : IPolicyEvaluator
/// <returns></returns>
public Task<AuthenticateResult> AuthenticateAsync(AuthorizationPolicy policy, HttpContext context)
{
var authenticationTicket = new AuthenticationTicket(
new ClaimsPrincipal(),
new AuthenticationProperties(),
JwtBearerDefaults.AuthenticationScheme);
var authenticationTicket = new AuthenticationTicket(new ClaimsPrincipal(), new AuthenticationProperties(), JwtBearerDefaults.AuthenticationScheme);

return Task.FromResult(AuthenticateResult.Success(authenticationTicket));
}
Expand All @@ -33,11 +30,7 @@ public Task<AuthenticateResult> AuthenticateAsync(AuthorizationPolicy policy, Ht
/// <param name="context"></param>
/// <param name="resource"></param>
/// <returns></returns>
public Task<PolicyAuthorizationResult> AuthorizeAsync(
AuthorizationPolicy policy,
AuthenticateResult authenticationResult,
HttpContext context,
object resource)
public Task<PolicyAuthorizationResult> AuthorizeAsync(AuthorizationPolicy policy, AuthenticateResult authenticationResult, HttpContext context, object resource)
{
return Task.FromResult(PolicyAuthorizationResult.Success());
}
Expand Down
Loading