11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using System . Net . Sockets ;
45using System . Text . Json . Serialization ;
2122
2223namespace HwProj . Utils . Configuration ;
2324
24- public static class StartupExtensions
25+ public static class StartupExtensions
2526{
2627 public static IServiceCollection ConfigureHwProjServices ( this IServiceCollection services , string serviceName )
2728 {
2829 services . AddAutoMapper ( AppDomain . CurrentDomain . GetAssemblies ( ) )
2930 . AddCors ( )
30- . AddMvc ( )
31+ . AddControllers ( )
3132 . AddJsonOptions ( options =>
3233 options . JsonSerializerOptions . ReferenceHandler = ReferenceHandler . IgnoreCycles ) ;
3334
@@ -37,17 +38,24 @@ public static IServiceCollection ConfigureHwProjServices(this IServiceCollection
3738
3839 if ( serviceName == "API Gateway" )
3940 {
40- c . AddSecurityDefinition ( "Bearer" ,
41- new OpenApiSecurityScheme
41+ var securityScheme = new OpenApiSecurityScheme
42+ {
43+ Name = "Bearer" ,
44+ Description = "Enter JWT Bearer token _only_" ,
45+ In = ParameterLocation . Header ,
46+ Type = SecuritySchemeType . Http ,
47+ Scheme = "bearer" ,
48+ BearerFormat = "JWT" ,
49+ Reference = new OpenApiReference
4250 {
43- In = ParameterLocation . Header ,
44- Description = "Please enter into field the word 'Bearer' following by space and JWT" ,
45- Name = "Authorization" ,
46- Type = SecuritySchemeType . ApiKey
47- } ) ;
51+ Id = JwtBearerDefaults . AuthenticationScheme ,
52+ Type = ReferenceType . SecurityScheme
53+ }
54+ } ;
55+ c . AddSecurityDefinition ( securityScheme . Reference . Id , securityScheme ) ;
4856 c . AddSecurityRequirement ( new OpenApiSecurityRequirement
4957 {
50- { "Bearer" , Enumerable . Empty < string > ( ) } ,
58+ { securityScheme , Array . Empty < string > ( ) } ,
5159 } ) ;
5260 }
5361 } ) ;
@@ -143,7 +151,9 @@ public static IApplicationBuilder ConfigureHwProj(this IApplicationBuilder app,
143151 . AllowAnyHeader ( )
144152 . SetIsOriginAllowed ( origin => true )
145153 . AllowCredentials ( ) ) ;
146- app . UseMvc ( ) ;
154+ app . UseRouting ( ) ;
155+ app . UseAuthorization ( ) ;
156+ app . UseEndpoints ( endpoints => endpoints . MapControllers ( ) ) ;
147157
148158 return app ;
149159 }
0 commit comments