|
|
@ -200,41 +200,18 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API |
|
|
|
app.UsePathBase(pathBase); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//app.Use((context, next) =>
|
|
|
|
//{
|
|
|
|
// Log.Logger.Information("Custom middleware to avoid trailers");
|
|
|
|
// Log.Logger.Information("Custom middleware context.Response {@context.Response}", context.Response);
|
|
|
|
// Log.Logger.Information("Custom middleware context.Response.SupportsTrailers {context.Response.SupportsTrailers}", context.Response.SupportsTrailers());
|
|
|
|
// if (!context.Response.SupportsTrailers())
|
|
|
|
// {
|
|
|
|
// var headers = new HeaderDictionary();
|
|
|
|
// headers.Add("grpc-status", "0");
|
|
|
|
|
|
|
|
// Log.Logger.Information("Custom middleware headers {@headers}", headers);
|
|
|
|
// context.Features.Set<IHttpResponseTrailersFeature>(new TestHttpResponseTrailersFeature
|
|
|
|
// {
|
|
|
|
// Trailers = headers
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return next();
|
|
|
|
|
|
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
//app.UseSwagger()
|
|
|
|
// .UseSwaggerUI(setup =>
|
|
|
|
// {
|
|
|
|
// setup.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Basket.API V1");
|
|
|
|
// setup.OAuthClientId("basketswaggerui");
|
|
|
|
// setup.OAuthAppName("Basket Swagger UI");
|
|
|
|
// });
|
|
|
|
app.UseSwagger() |
|
|
|
.UseSwaggerUI(setup => |
|
|
|
{ |
|
|
|
setup.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Basket.API V1"); |
|
|
|
setup.OAuthClientId("basketswaggerui"); |
|
|
|
setup.OAuthAppName("Basket Swagger UI"); |
|
|
|
}); |
|
|
|
|
|
|
|
app.UseRouting(); |
|
|
|
// ConfigureAuth(app);
|
|
|
|
ConfigureAuth(app); |
|
|
|
|
|
|
|
// app.UseStaticFiles();
|
|
|
|
app.UseStaticFiles(); |
|
|
|
|
|
|
|
app.UseCors("CorsPolicy"); |
|
|
|
app.UseEndpoints(endpoints => |
|
|
@ -242,20 +219,20 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API |
|
|
|
endpoints.MapGrpcService<BasketService>(); |
|
|
|
endpoints.MapDefaultControllerRoute(); |
|
|
|
endpoints.MapControllers(); |
|
|
|
// endpoints.MapGet("/_proto/", async ctx =>
|
|
|
|
// {
|
|
|
|
// ctx.Response.ContentType = "text/plain";
|
|
|
|
// using var fs = new FileStream(Path.Combine(env.ContentRootPath, "Proto", "basket.proto"), FileMode.Open, FileAccess.Read);
|
|
|
|
// using var sr = new StreamReader(fs);
|
|
|
|
// while (!sr.EndOfStream)
|
|
|
|
// {
|
|
|
|
// var line = await sr.ReadLineAsync();
|
|
|
|
// if (line != "/* >>" || line != "<< */")
|
|
|
|
// {
|
|
|
|
// await ctx.Response.WriteAsync(line);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
endpoints.MapGet("/_proto/", async ctx => |
|
|
|
{ |
|
|
|
ctx.Response.ContentType = "text/plain"; |
|
|
|
using var fs = new FileStream(Path.Combine(env.ContentRootPath, "Proto", "basket.proto"), FileMode.Open, FileAccess.Read); |
|
|
|
using var sr = new StreamReader(fs); |
|
|
|
while (!sr.EndOfStream) |
|
|
|
{ |
|
|
|
var line = await sr.ReadLineAsync(); |
|
|
|
if (line != "/* >>" || line != "<< */") |
|
|
|
{ |
|
|
|
await ctx.Response.WriteAsync(line); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
endpoints.MapHealthChecks("/hc", new HealthCheckOptions() |
|
|
|
{ |
|
|
|
Predicate = _ => true, |
|
|
@ -278,22 +255,22 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API |
|
|
|
|
|
|
|
private void ConfigureAuthService(IServiceCollection services) |
|
|
|
{ |
|
|
|
// prevent from mapping "sub" claim to nameidentifier.
|
|
|
|
// JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
|
|
|
|
|
|
|
|
// var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
|
|
|
|
|
|
|
// services.AddAuthentication(options =>
|
|
|
|
// {
|
|
|
|
// options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
// options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
|
|
|
// }).AddJwtBearer(options =>
|
|
|
|
// {
|
|
|
|
// options.Authority = identityUrl;
|
|
|
|
// options.RequireHttpsMetadata = false;
|
|
|
|
// options.Audience = "basket";
|
|
|
|
// });
|
|
|
|
// prevent from mapping "sub" claim to nameidentifier.
|
|
|
|
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub"); |
|
|
|
|
|
|
|
var identityUrl = Configuration.GetValue<string>("IdentityUrl"); |
|
|
|
|
|
|
|
services.AddAuthentication(options => |
|
|
|
{ |
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
|
|
|
|
}).AddJwtBearer(options => |
|
|
|
{ |
|
|
|
options.Authority = identityUrl; |
|
|
|
options.RequireHttpsMetadata = false; |
|
|
|
options.Audience = "basket"; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void ConfigureAuth(IApplicationBuilder app) |
|
|
@ -303,8 +280,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API |
|
|
|
app.UseMiddleware<ByPassAuthMiddleware>(); |
|
|
|
} |
|
|
|
|
|
|
|
// app.UseAuthentication();
|
|
|
|
// app.UseAuthorization();
|
|
|
|
app.UseAuthentication(); |
|
|
|
app.UseAuthorization(); |
|
|
|
} |
|
|
|
|
|
|
|
private void RegisterEventBus(IServiceCollection services) |
|
|
|