mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-11 02:20:20 +08:00
Merge pull request #204 from meysamhadeli/develop
fix: Fix 401 in gateway
This commit is contained in:
commit
6e5f28487f
@ -1,9 +1,10 @@
|
||||
# https://github.com/Huachao/vscode-restclient
|
||||
@api-gateway=https://localhost:5000
|
||||
@identity-api=https://localhost:5005
|
||||
@identity-api=http://localhost:6005
|
||||
@flight-api=https://localhost:5003
|
||||
@passenger-api=https://localhost:5012
|
||||
@booking-api=https://localhost:5010
|
||||
|
||||
@contentType = application/json
|
||||
@flightid = 1
|
||||
@passengerId = 1
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
using BuildingBlocks.Jwt;
|
||||
using BuildingBlocks.Logging;
|
||||
using BuildingBlocks.Web;
|
||||
using Figgle;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Serilog;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@ -13,7 +11,6 @@ Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));
|
||||
|
||||
|
||||
builder.AddCustomSerilog(env);
|
||||
builder.Services.AddJwt();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
@ -31,16 +28,7 @@ app.UseAuthorization();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
endpoints.MapReverseProxy(proxyPipeline =>
|
||||
{
|
||||
proxyPipeline.Use(async (context, next) =>
|
||||
{
|
||||
var token = await context.GetTokenAsync("access_token");
|
||||
context.Request.Headers["Authorization"] = $"Bearer {token}";
|
||||
|
||||
await next().ConfigureAwait(false);
|
||||
});
|
||||
});
|
||||
endpoints.MapReverseProxy();
|
||||
});
|
||||
|
||||
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": {
|
||||
"destinations": {
|
||||
"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": "*"
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ using Serilog;
|
||||
namespace Identity.Extensions.Infrastructure;
|
||||
|
||||
using Configurations;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
|
||||
public static class InfrastructureExtensions
|
||||
{
|
||||
@ -89,6 +90,15 @@ public static class InfrastructureExtensions
|
||||
var env = app.Environment;
|
||||
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.UseSerilogRequestLogging(options =>
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user