diff --git a/Dockerfile b/Dockerfile
index e10dba4..968edb3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,22 +3,22 @@ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Copy csproj files and restore
-COPY ["iYHCT360.Domain/iYHCT360.Domain.csproj", "iYHCT360.Domain/"]
-COPY ["iYHCT360.Contracts/iYHCT360.Contracts.csproj", "iYHCT360.Contracts/"]
-COPY ["iYHCT360.Application/iYHCT360.Application.csproj", "iYHCT360.Application/"]
-COPY ["iYHCT360.Infrastructure/iYHCT360.Infrastructure.csproj", "iYHCT360.Infrastructure/"]
-COPY ["iYHCT360.WebAPI/iYHCT360.WebAPI.csproj", "iYHCT360.WebAPI/"]
+COPY ["MyNewProjectName.Domain/MyNewProjectName.Domain.csproj", "MyNewProjectName.Domain/"]
+COPY ["MyNewProjectName.Contracts/MyNewProjectName.Contracts.csproj", "MyNewProjectName.Contracts/"]
+COPY ["MyNewProjectName.Application/MyNewProjectName.Application.csproj", "MyNewProjectName.Application/"]
+COPY ["MyNewProjectName.Infrastructure/MyNewProjectName.Infrastructure.csproj", "MyNewProjectName.Infrastructure/"]
+COPY ["MyNewProjectName.WebAPI/MyNewProjectName.WebAPI.csproj", "MyNewProjectName.WebAPI/"]
-RUN dotnet restore "iYHCT360.WebAPI/iYHCT360.WebAPI.csproj"
+RUN dotnet restore "MyNewProjectName.WebAPI/MyNewProjectName.WebAPI.csproj"
# Copy everything else and build
COPY . .
-WORKDIR "/src/iYHCT360.WebAPI"
-RUN dotnet build "iYHCT360.WebAPI.csproj" -c Release -o /app/build
+WORKDIR "/src/MyNewProjectName.WebAPI"
+RUN dotnet build "MyNewProjectName.WebAPI.csproj" -c Release -o /app/build
# Publish stage
FROM build AS publish
-RUN dotnet publish "iYHCT360.WebAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
+RUN dotnet publish "MyNewProjectName.WebAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Final stage
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
@@ -27,4 +27,4 @@ EXPOSE 8080
EXPOSE 8081
COPY --from=publish /app/publish .
-ENTRYPOINT ["dotnet", "iYHCT360.WebAPI.dll"]
+ENTRYPOINT ["dotnet", "MyNewProjectName.WebAPI.dll"]
diff --git a/MyNewProjectName.AdminAPI/appsettings.json b/MyNewProjectName.AdminAPI/appsettings.json
index 2aa297e..9a99411 100644
--- a/MyNewProjectName.AdminAPI/appsettings.json
+++ b/MyNewProjectName.AdminAPI/appsettings.json
@@ -40,4 +40,4 @@
"EnableResponseLogging": false
},
"AllowedHosts": "*"
-}
+}
\ No newline at end of file
diff --git a/MyNewProjectName.WebAPI/Extensions/ServiceCollectionExtensions.cs b/MyNewProjectName.WebAPI/Extensions/ServiceCollectionExtensions.cs
new file mode 100644
index 0000000..be5babe
--- /dev/null
+++ b/MyNewProjectName.WebAPI/Extensions/ServiceCollectionExtensions.cs
@@ -0,0 +1,239 @@
+using Microsoft.AspNetCore.Authentication.JwtBearer;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Configuration;
+using Microsoft.IdentityModel.Tokens;
+using Microsoft.OpenApi.Models;
+using System.Reflection;
+using System.Text;
+using System.Text.Json;
+using MyNewProjectName.Infrastructure.Options;
+using MyNewProjectName.Contracts.Common;
+
+namespace MyNewProjectName.WebAPI.Extensions;
+
+///
+/// Extension methods for configuring services in the dependency injection container
+///
+public static class ServiceCollectionExtensions
+{
+ ///
+ /// Configures Swagger/OpenAPI documentation with JWT Bearer authentication support
+ ///
+ public static IServiceCollection AddCustomSwagger(this IServiceCollection services)
+ {
+ services.AddSwaggerGen(c =>
+ {
+ c.SwaggerDoc("v1", new OpenApiInfo { Title = "MyNewProjectName API", Version = "v1" });
+
+ var securityScheme = new OpenApiSecurityScheme
+ {
+ Name = "Authorization",
+ Description = "Enter JWT Bearer token",
+ In = ParameterLocation.Header,
+ Type = SecuritySchemeType.Http,
+ Scheme = "bearer",
+ BearerFormat = "JWT"
+ };
+ c.AddSecurityDefinition("Bearer", securityScheme);
+
+ var securityRequirement = new OpenApiSecurityRequirement
+ {
+ {
+ new OpenApiSecurityScheme
+ {
+ Reference = new OpenApiReference
+ {
+ Type = ReferenceType.SecurityScheme,
+ Id = "Bearer"
+ }
+ },
+ new string[] {}
+ }
+ };
+ c.AddSecurityRequirement(securityRequirement);
+
+ // Set the comments path for the Swagger JSON and UI (only if XML file exists)
+ var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
+ var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
+ if (File.Exists(xmlPath))
+ {
+ c.IncludeXmlComments(xmlPath);
+ }
+ });
+
+ return services;
+ }
+
+ ///
+ /// Configures JWT Bearer authentication with custom token validation and error handling
+ ///
+ public static IServiceCollection AddJwtAuthentication(this IServiceCollection services, IConfiguration configuration)
+ {
+ var jwtOptionsSection = configuration.GetSection(JwtOptions.SectionName);
+ var jwtOptions = jwtOptionsSection.Get()
+ ?? throw new InvalidOperationException("JwtOptions configuration is missing");
+
+ services
+ .AddAuthentication(options =>
+ {
+ options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
+ options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
+ })
+ .AddJwtBearer(options =>
+ {
+ options.RequireHttpsMetadata = false;
+ options.SaveToken = true;
+ options.TokenValidationParameters = new TokenValidationParameters
+ {
+ ValidateIssuer = true,
+ ValidateAudience = true,
+ ValidateIssuerSigningKey = true,
+ ValidateLifetime = true,
+ ValidIssuer = jwtOptions.Issuer,
+ ValidAudience = jwtOptions.Audience,
+ IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.Secret)),
+ ClockSkew = TimeSpan.Zero
+ };
+
+ // Log token & claims for debugging
+ options.Events = new JwtBearerEvents
+ {
+ OnMessageReceived = context =>
+ {
+ var logger = context.HttpContext.RequestServices
+ .GetRequiredService()
+ .CreateLogger("JwtBearer");
+
+ // Có thể bật lại nếu cần debug Authorization header
+ // logger.LogInformation("JWT received. Authorization header: {Header}", context.Request.Headers["Authorization"].ToString());
+ return Task.CompletedTask;
+ },
+ OnTokenValidated = context =>
+ {
+ var logger = context.HttpContext.RequestServices
+ .GetRequiredService()
+ .CreateLogger("JwtBearer");
+
+ var claims = context.Principal?.Claims
+ .Select(c => $"{c.Type}={c.Value}")
+ .ToList() ?? new List();
+
+ // logger.LogInformation("JWT validated. Claims: {Claims}", string.Join(", ", claims));
+ return Task.CompletedTask;
+ },
+ OnAuthenticationFailed = context =>
+ {
+ var logger = context.HttpContext.RequestServices
+ .GetRequiredService()
+ .CreateLogger("JwtBearer");
+
+ logger.LogWarning(context.Exception, "JWT authentication failed");
+ return Task.CompletedTask;
+ },
+ OnChallenge = async context =>
+ {
+ // Ngăn không cho middleware mặc định ghi response lần nữa
+ context.HandleResponse();
+
+ var logger = context.HttpContext.RequestServices
+ .GetRequiredService()
+ .CreateLogger("JwtBearer");
+
+ if (context.Response.HasStarted)
+ {
+ logger.LogWarning("The response has already started, the JWT challenge middleware will not be executed.");
+ return;
+ }
+
+ var correlationId = context.HttpContext.Request.Headers["X-Correlation-ID"].FirstOrDefault() ?? "unknown";
+
+ var isExpired = context.AuthenticateFailure is SecurityTokenExpiredException;
+ var message = isExpired
+ ? "Token expired"
+ : "Unauthorized";
+
+ logger.LogInformation("JWT challenge. Expired: {Expired}, Error: {Error}, Description: {Description}, CorrelationId: {CorrelationId}",
+ isExpired, context.Error, context.ErrorDescription, correlationId);
+
+ context.Response.StatusCode = StatusCodes.Status401Unauthorized;
+ context.Response.ContentType = "application/json";
+
+ var response = new ServiceResponse