Merge pull request #204 from meysamhadeli/develop

fix: Fix 401 in gateway
This commit is contained in:
Meysam Hadeli 2023-02-24 13:57:16 +03:30 committed by GitHub
commit 6e5f28487f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 29 deletions

View File

@ -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

View File

@ -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));

View File

@ -35,12 +35,5 @@
}
}
}
},
"Jwt": {
"Jwt": {
"Authority": "http://identity:80",
"RequireHttpsMetadata": false,
"MetadataAddress": "http://identity:80/.well-known/openid-configuration"
}
}
}

View File

@ -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": "*"
}

View File

@ -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 =>
{