mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-28 00:20:24 +08:00
fix: Fix 401 in gateway
This commit is contained in:
parent
a70320b705
commit
af4b9866a8
@ -1,9 +1,10 @@
|
|||||||
# https://github.com/Huachao/vscode-restclient
|
# https://github.com/Huachao/vscode-restclient
|
||||||
@api-gateway=https://localhost:5000
|
@api-gateway=https://localhost:5000
|
||||||
@identity-api=https://localhost:5005
|
@identity-api=http://localhost:6005
|
||||||
@flight-api=https://localhost:5003
|
@flight-api=https://localhost:5003
|
||||||
@passenger-api=https://localhost:5012
|
@passenger-api=https://localhost:5012
|
||||||
@booking-api=https://localhost:5010
|
@booking-api=https://localhost:5010
|
||||||
|
|
||||||
@contentType = application/json
|
@contentType = application/json
|
||||||
@flightid = 1
|
@flightid = 1
|
||||||
@passengerId = 1
|
@passengerId = 1
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
using BuildingBlocks.Jwt;
|
|
||||||
using BuildingBlocks.Logging;
|
using BuildingBlocks.Logging;
|
||||||
using BuildingBlocks.Web;
|
using BuildingBlocks.Web;
|
||||||
using Figgle;
|
using Figgle;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@ -13,7 +11,6 @@ Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));
|
|||||||
|
|
||||||
|
|
||||||
builder.AddCustomSerilog(env);
|
builder.AddCustomSerilog(env);
|
||||||
builder.Services.AddJwt();
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
|
|
||||||
@ -31,16 +28,7 @@ app.UseAuthorization();
|
|||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapControllers();
|
endpoints.MapControllers();
|
||||||
endpoints.MapReverseProxy(proxyPipeline =>
|
endpoints.MapReverseProxy();
|
||||||
{
|
|
||||||
proxyPipeline.Use(async (context, next) =>
|
|
||||||
{
|
|
||||||
var token = await context.GetTokenAsync("access_token");
|
|
||||||
context.Request.Headers["Authorization"] = $"Bearer {token}";
|
|
||||||
|
|
||||||
await next().ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
||||||
|
|||||||
@ -35,12 +35,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"Jwt": {
|
|
||||||
"Jwt": {
|
|
||||||
"Authority": "http://identity:80",
|
|
||||||
"RequireHttpsMetadata": false,
|
|
||||||
"MetadataAddress": "http://identity:80/.well-known/openid-configuration"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,7 @@
|
|||||||
"identity": {
|
"identity": {
|
||||||
"destinations": {
|
"destinations": {
|
||||||
"destination1": {
|
"destination1": {
|
||||||
"address": "https://localhost:5005"
|
"address": "http://localhost:6005"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -68,12 +68,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Jwt": {
|
|
||||||
"Jwt": {
|
|
||||||
"Authority": "http://localhost:6005",
|
|
||||||
"RequireHttpsMetadata": false,
|
|
||||||
"MetadataAddress": "http://localhost:6005/.well-known/openid-configuration"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ using Serilog;
|
|||||||
namespace Identity.Extensions.Infrastructure;
|
namespace Identity.Extensions.Infrastructure;
|
||||||
|
|
||||||
using Configurations;
|
using Configurations;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
public static class InfrastructureExtensions
|
public static class InfrastructureExtensions
|
||||||
{
|
{
|
||||||
@ -89,6 +90,15 @@ public static class InfrastructureExtensions
|
|||||||
var env = app.Environment;
|
var env = app.Environment;
|
||||||
var appOptions = app.GetOptions<AppOptions>(nameof(AppOptions));
|
var appOptions = app.GetOptions<AppOptions>(nameof(AppOptions));
|
||||||
|
|
||||||
|
var forwardHeaderOptions = new ForwardedHeadersOptions
|
||||||
|
{
|
||||||
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||||
|
};
|
||||||
|
forwardHeaderOptions.KnownNetworks.Clear();
|
||||||
|
forwardHeaderOptions.KnownProxies.Clear();
|
||||||
|
|
||||||
|
app.UseForwardedHeaders(forwardHeaderOptions);
|
||||||
|
|
||||||
app.UseProblemDetails();
|
app.UseProblemDetails();
|
||||||
app.UseSerilogRequestLogging(options =>
|
app.UseSerilogRequestLogging(options =>
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user