11using MARKETPLACEAPI . MiddleWare ;
22using Microsoft . AspNetCore . Authentication . JwtBearer ;
3+ using Microsoft . AspNetCore . HttpOverrides ;
34using Microsoft . IdentityModel . Tokens ;
45using System . Text ;
56using MARKETPLACEAPI . Models ;
910
1011public class Startup
1112{
12- private readonly IConfiguration _configuration ;
13-
14- public Startup ( IConfiguration configuration )
15- {
16- _configuration = configuration ;
17- }
18-
19- public void ConfigureServices ( IServiceCollection services )
20- {
21- // Add your services configuration here if needed.
22- services . Configure < MarketPlaceDBSettings > (
23- _configuration . GetSection ( "MarketPlaceDatabase" ) ) ;
24- services . AddSingleton < UserService > ( ) ;
25- services . AddSingleton < ProjectService > ( ) ;
26- services . AddSingleton < NftService > ( ) ;
27- services . AddSingleton < UserNftService > ( ) ;
28- services . AddSingleton < ProjectLikeService > ( ) ;
29- services . AddSingleton < NftLikeService > ( ) ;
30- services . AddSingleton < PortfolioService > ( ) ;
31- services . AddSingleton < ProjectDetailService > ( ) ;
32- services . AddSingleton < ProjectUpdateService > ( ) ;
33- services . AddSingleton < CategoryService > ( ) ;
34- services . AddSingleton < AuthService > ( ) ;
35- services . AddControllers ( ) ;
36- // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
37- services . AddEndpointsApiExplorer ( ) ;
38- services . AddSwaggerGen (
39- options =>
40- {
41- options . SwaggerDoc ( "v1" , new ( ) { Title = "CROWDLAUNCH" , Version = "v1" } ) ;
42- options . AddSecurityDefinition ( "Bearer" , new OpenApiSecurityScheme
43- {
44- In = ParameterLocation . Header ,
45- Description = "Enter a vailid token" ,
46- Name = "Authorization" ,
47- Type = SecuritySchemeType . Http ,
48- BearerFormat = "JWT" ,
49- Scheme = "Bearer"
50- } ) ;
51- options . AddSecurityRequirement ( new OpenApiSecurityRequirement {
13+ private readonly IConfiguration _configuration ;
14+
15+ public Startup ( IConfiguration configuration )
16+ {
17+ _configuration = configuration ;
18+ }
19+
20+ public void ConfigureServices ( IServiceCollection services )
21+ {
22+ // Add your services configuration here if needed.
23+ services . Configure < MarketPlaceDBSettings > (
24+ _configuration . GetSection ( "MarketPlaceDatabase" ) ) ;
25+ services . AddSingleton < UserService > ( ) ;
26+ services . AddSingleton < ProjectService > ( ) ;
27+ services . AddSingleton < NftService > ( ) ;
28+ services . AddSingleton < UserNftService > ( ) ;
29+ services . AddSingleton < ProjectLikeService > ( ) ;
30+ services . AddSingleton < NftLikeService > ( ) ;
31+ services . AddSingleton < PortfolioService > ( ) ;
32+ services . AddSingleton < ProjectDetailService > ( ) ;
33+ services . AddSingleton < ProjectUpdateService > ( ) ;
34+ services . AddSingleton < CategoryService > ( ) ;
35+ services . AddSingleton < AuthService > ( ) ;
36+ services . AddControllers ( ) ;
37+ // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
38+ services . AddEndpointsApiExplorer ( ) ;
39+ services . AddSwaggerGen (
40+ options =>
41+ {
42+ options . SwaggerDoc ( "v1" , new ( ) { Title = "CROWDLAUNCH" , Version = "v1" } ) ;
43+ options . AddSecurityDefinition ( "Bearer" , new OpenApiSecurityScheme
44+ {
45+ In = ParameterLocation . Header ,
46+ Description = "Enter a vailid token" ,
47+ Name = "Authorization" ,
48+ Type = SecuritySchemeType . Http ,
49+ BearerFormat = "JWT" ,
50+ Scheme = "Bearer"
51+ } ) ;
52+ options . AddSecurityRequirement ( new OpenApiSecurityRequirement {
5253 {
5354 new OpenApiSecurityScheme {
5455 Reference = new OpenApiReference {
@@ -58,67 +59,76 @@ public void ConfigureServices(IServiceCollection services)
5859 } ,
5960 new string [ ] { }
6061 }
61- } ) ;
62- }
63- ) ;
64- services . AddAuthentication ( JwtBearerDefaults . AuthenticationScheme )
65- . AddJwtBearer ( options =>
66- {
67- options . TokenValidationParameters = new TokenValidationParameters
62+ } ) ;
63+ }
64+ ) ;
65+ services . AddAuthentication ( JwtBearerDefaults . AuthenticationScheme )
66+ . AddJwtBearer ( options => {
67+ options . TokenValidationParameters = new TokenValidationParameters
68+ {
69+ ValidateIssuer = true ,
70+ ValidateAudience = true ,
71+ ValidateLifetime = true ,
72+ ValidateIssuerSigningKey = true ,
73+
74+ ValidIssuer = _configuration [ "Jwt:Issuer" ] ,
75+ ValidAudience = _configuration [ "Jwt:Issuer" ] ,
76+ IssuerSigningKey = new SymmetricSecurityKey ( Encoding . UTF8 . GetBytes ( Environment . GetEnvironmentVariable ( "JWT_KEY" ) ! ) )
77+ } ;
78+ }
79+ ) ;
80+
81+ services . AddCors ( options =>
6882 {
69- ValidateIssuer = true ,
70- ValidateAudience = true ,
71- ValidateLifetime = true ,
72- ValidateIssuerSigningKey = true ,
73-
74- ValidIssuer = _configuration [ "Jwt:Issuer" ] ,
75- ValidAudience = _configuration [ "Jwt:Issuer" ] ,
76- IssuerSigningKey = new SymmetricSecurityKey ( Encoding . UTF8 . GetBytes ( Environment . GetEnvironmentVariable ( "JWT_KEY" ) ! ) )
77- } ;
78- }
79- ) ;
80-
81- services . AddCors ( options =>
82- {
83- options . AddPolicy ( "CorsPolicy" , builder => builder
84- . AllowAnyMethod ( )
85- . AllowAnyHeader ( )
86- . SetIsOriginAllowed ( ( host ) => true )
87- . AllowCredentials ( )
88- ) ;
89- } ) ;
90- }
91-
92- public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
93- {
94- // Other middleware and configurations...
95- // Configure the HTTP request pipeline.
96- if ( env . IsDevelopment ( ) )
97- {
98- app . UseSwagger ( ) ;
99- app . UseSwaggerUI ( ) ;
83+ options . AddPolicy ( "CorsPolicy" , builder => builder
84+ . AllowAnyMethod ( )
85+ . AllowAnyHeader ( )
86+ . SetIsOriginAllowed ( ( host ) => true )
87+ . AllowCredentials ( )
88+ ) ;
89+ } ) ;
10090 }
10191
92+ public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
93+ {
94+ // Other middleware and configurations...
95+ // Configure the HTTP request pipeline.
96+ if ( env . IsDevelopment ( ) )
97+ {
98+ app . UseSwagger ( ) ;
99+ app . UseSwaggerUI ( ) ;
100+ }
102101
103- app . UseHttpsRedirection ( ) ;
104102
105- app . UseAuthentication ( ) ;
106103
107- app . UseCors ( "CorsPolicy" ) ;
108- app . UseTokenMiddleware ( ) ;
109- // Add the ExceptionLoggingMiddleware to the pipeline.
110- string logFilePath = Path . Combine ( env . ContentRootPath , "exceptions.log" ) ;
111- app . UseMiddleware < ExceptionLoggingMiddleware > ( logFilePath ) ;
104+ app . UseHttpsRedirection ( ) ;
112105
106+ // using Microsoft.AspNetCore.HttpOverrides;
113107
114- app . UseRouting ( ) ;
115- app . UseAuthorization ( ) ;
116- app . UseEndpoints ( endpoints =>
117- {
118- endpoints . MapControllers ( ) ;
119- } ) ;
108+ app . UseForwardedHeaders ( new ForwardedHeadersOptions
109+ {
110+ ForwardedHeaders = ForwardedHeaders . XForwardedFor | ForwardedHeaders . XForwardedProto
111+ } ) ;
112+
113+ app . UseAuthentication ( ) ;
114+
115+ app . UseAuthentication ( ) ;
120116
121- // The following middleware will only execute if an exception is not thrown.
122- // You can continue adding other middleware to the pipeline here.
123- }
124- }
117+ app . UseCors ( "CorsPolicy" ) ;
118+ app . UseTokenMiddleware ( ) ;
119+ // Add the ExceptionLoggingMiddleware to the pipeline.
120+ string logFilePath = Path . Combine ( env . ContentRootPath , "exceptions.log" ) ;
121+ app . UseMiddleware < ExceptionLoggingMiddleware > ( logFilePath ) ;
122+
123+
124+ app . UseRouting ( ) ;
125+ app . UseAuthorization ( ) ;
126+ app . UseEndpoints ( endpoints =>
127+ {
128+ endpoints . MapControllers ( ) ;
129+ } ) ;
130+
131+ // The following middleware will only execute if an exception is not thrown.
132+ // You can continue adding other middleware to the pipeline here.
133+ }
134+ }
0 commit comments