@@ -200,62 +200,39 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
200200 app . UsePathBase ( pathBase ) ;
201201 }
202202
203-
204- //app.Use((context, next) =>
205- //{
206- // Log.Logger.Information("Custom middleware to avoid trailers");
207- // Log.Logger.Information("Custom middleware context.Response {@context.Response}", context.Response);
208- // Log.Logger.Information("Custom middleware context.Response.SupportsTrailers {context.Response.SupportsTrailers}", context.Response.SupportsTrailers());
209- // if (!context.Response.SupportsTrailers())
210- // {
211- // var headers = new HeaderDictionary();
212- // headers.Add("grpc-status", "0");
213-
214- // Log.Logger.Information("Custom middleware headers {@headers}", headers);
215- // context.Features.Set<IHttpResponseTrailersFeature>(new TestHttpResponseTrailersFeature
216- // {
217- // Trailers = headers
218- // });
219- // }
220-
221- // return next();
222-
223-
224- //});
225-
226- //app.UseSwagger()
227- // .UseSwaggerUI(setup =>
228- // {
229- // setup.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Basket.API V1");
230- // setup.OAuthClientId("basketswaggerui");
231- // setup.OAuthAppName("Basket Swagger UI");
232- // });
203+ app . UseSwagger ( )
204+ . UseSwaggerUI ( setup =>
205+ {
206+ setup . SwaggerEndpoint ( $ "{ ( ! string . IsNullOrEmpty ( pathBase ) ? pathBase : string . Empty ) } /swagger/v1/swagger.json", "Basket.API V1" ) ;
207+ setup . OAuthClientId ( "basketswaggerui" ) ;
208+ setup . OAuthAppName ( "Basket Swagger UI" ) ;
209+ } ) ;
233210
234211 app . UseRouting ( ) ;
235- // ConfigureAuth(app);
212+ ConfigureAuth ( app ) ;
236213
237- // app.UseStaticFiles();
214+ app . UseStaticFiles ( ) ;
238215
239216 app . UseCors ( "CorsPolicy" ) ;
240217 app . UseEndpoints ( endpoints =>
241218 {
242219 endpoints . MapGrpcService < BasketService > ( ) ;
243220 endpoints . MapDefaultControllerRoute ( ) ;
244221 endpoints . MapControllers ( ) ;
245- // endpoints.MapGet("/_proto/", async ctx =>
246- // {
247- // ctx.Response.ContentType = "text/plain";
248- // using var fs = new FileStream(Path.Combine(env.ContentRootPath, "Proto", "basket.proto"), FileMode.Open, FileAccess.Read);
249- // using var sr = new StreamReader(fs);
250- // while (!sr.EndOfStream)
251- // {
252- // var line = await sr.ReadLineAsync();
253- // if (line != "/* >>" || line != "<< */")
254- // {
255- // await ctx.Response.WriteAsync(line);
256- // }
257- // }
258- // });
222+ endpoints . MapGet ( "/_proto/" , async ctx =>
223+ {
224+ ctx . Response . ContentType = "text/plain" ;
225+ using var fs = new FileStream ( Path . Combine ( env . ContentRootPath , "Proto" , "basket.proto" ) , FileMode . Open , FileAccess . Read ) ;
226+ using var sr = new StreamReader ( fs ) ;
227+ while ( ! sr . EndOfStream )
228+ {
229+ var line = await sr . ReadLineAsync ( ) ;
230+ if ( line != "/* >>" || line != "<< */" )
231+ {
232+ await ctx . Response . WriteAsync ( line ) ;
233+ }
234+ }
235+ } ) ;
259236 endpoints . MapHealthChecks ( "/hc" , new HealthCheckOptions ( )
260237 {
261238 Predicate = _ => true ,
@@ -278,22 +255,22 @@ private void RegisterAppInsights(IServiceCollection services)
278255
279256 private void ConfigureAuthService ( IServiceCollection services )
280257 {
281- // prevent from mapping "sub" claim to nameidentifier.
282- // JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
283-
284- // var identityUrl = Configuration.GetValue<string>("IdentityUrl");
285-
286- // services.AddAuthentication(options =>
287- // {
288- // options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
289- // options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
290-
291- // }).AddJwtBearer(options =>
292- // {
293- // options.Authority = identityUrl;
294- // options.RequireHttpsMetadata = false;
295- // options.Audience = "basket";
296- // });
258+ // prevent from mapping "sub" claim to nameidentifier.
259+ JwtSecurityTokenHandler . DefaultInboundClaimTypeMap . Remove ( "sub" ) ;
260+
261+ var identityUrl = Configuration . GetValue < string > ( "IdentityUrl" ) ;
262+
263+ services . AddAuthentication ( options =>
264+ {
265+ options . DefaultAuthenticateScheme = JwtBearerDefaults . AuthenticationScheme ;
266+ options . DefaultChallengeScheme = JwtBearerDefaults . AuthenticationScheme ;
267+
268+ } ) . AddJwtBearer ( options =>
269+ {
270+ options . Authority = identityUrl ;
271+ options . RequireHttpsMetadata = false ;
272+ options . Audience = "basket" ;
273+ } ) ;
297274 }
298275
299276 protected virtual void ConfigureAuth ( IApplicationBuilder app )
@@ -303,8 +280,8 @@ protected virtual void ConfigureAuth(IApplicationBuilder app)
303280 app . UseMiddleware < ByPassAuthMiddleware > ( ) ;
304281 }
305282
306- // app.UseAuthentication();
307- // app.UseAuthorization();
283+ app . UseAuthentication ( ) ;
284+ app . UseAuthorization ( ) ;
308285 }
309286
310287 private void RegisterEventBus ( IServiceCollection services )
0 commit comments