From 4f8abb4a64db86c7bf2468e3f7b07e158fd5a1f0 Mon Sep 17 00:00:00 2001 From: Ho Ngoc Hai Date: Sat, 17 Jan 2026 22:06:10 +0700 Subject: [PATCH] feat: Add JWT Bearer authentication to Swagger UI. --- .../src/PromotionService.API/Program.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/promotion-service-net/src/PromotionService.API/Program.cs b/services/promotion-service-net/src/PromotionService.API/Program.cs index 38ac804c..ddddc9c3 100644 --- a/services/promotion-service-net/src/PromotionService.API/Program.cs +++ b/services/promotion-service-net/src/PromotionService.API/Program.cs @@ -87,6 +87,31 @@ try Version = "v1", Description = "PromotionService microservice API / API microservice PromotionService" }); + + // EN: Add JWT Bearer security definition / VI: Thêm định nghĩa bảo mật JWT Bearer + options.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme + { + Description = "JWT Authorization header using the Bearer scheme. Enter 'Bearer' [space] and then your token.", + Name = "Authorization", + In = Microsoft.OpenApi.Models.ParameterLocation.Header, + Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey, + Scheme = "Bearer" + }); + + options.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement + { + { + new Microsoft.OpenApi.Models.OpenApiSecurityScheme + { + Reference = new Microsoft.OpenApi.Models.OpenApiReference + { + Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + Array.Empty() + } + }); }); // EN: Add health checks / VI: Thêm health checks