mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-15 05:25:36 +08:00
Merge pull request #176 from meysamhadeli/feat/config-identitiy-server-for-revers-proxy
feat: Config identity server for ingress revers proxy
This commit is contained in:
commit
fb3117ef94
@ -252,7 +252,7 @@ services:
|
||||
#######################################################
|
||||
elasticsearch:
|
||||
container_name: elasticsearch
|
||||
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
|
||||
image: elasticsearch:7.17.9
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 9200:9200
|
||||
@ -271,7 +271,7 @@ services:
|
||||
#######################################################
|
||||
kibana:
|
||||
container_name: kibana
|
||||
image: docker.elastic.co/kibana/kibana:7.9.2
|
||||
image: kibana:7.17.9
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 5601:5601
|
||||
@ -285,7 +285,6 @@ services:
|
||||
|
||||
networks:
|
||||
booking:
|
||||
name: booking
|
||||
|
||||
volumes:
|
||||
elasticsearch-data:
|
||||
|
||||
@ -95,7 +95,7 @@ services:
|
||||
#######################################################
|
||||
elasticsearch:
|
||||
container_name: elasticsearch
|
||||
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.9
|
||||
image: elasticsearch:7.17.9
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 9200:9200
|
||||
@ -114,7 +114,7 @@ services:
|
||||
#######################################################
|
||||
kibana:
|
||||
container_name: kibana
|
||||
image: docker.elastic.co/kibana/kibana:7.17.9
|
||||
image: kibana:7.17.9
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 5601:5601
|
||||
@ -141,8 +141,6 @@ services:
|
||||
|
||||
networks:
|
||||
booking:
|
||||
name: booking
|
||||
|
||||
|
||||
volumes:
|
||||
elasticsearch-data:
|
||||
|
||||
@ -16,7 +16,7 @@ public static class JwtExtensions
|
||||
{
|
||||
options.Authority = jwtOptions.Authority;
|
||||
options.TokenValidationParameters.ValidateAudience = false;
|
||||
options.RequireHttpsMetadata = false;
|
||||
options.RequireHttpsMetadata = jwtOptions.RequireHttpsMetadata;
|
||||
});
|
||||
|
||||
if (!string.IsNullOrEmpty(jwtOptions.Audience))
|
||||
|
||||
@ -20,7 +20,6 @@ var app = builder.Build();
|
||||
app.MapMinimalEndpoints();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseInfrastructure();
|
||||
|
||||
app.Run();
|
||||
|
||||
@ -26,8 +26,9 @@
|
||||
"Port": 5672
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "identity:5005",
|
||||
"Audience": "booking-api"
|
||||
"Authority": "https://myidentityserver.com",
|
||||
"Audience": "booking-api",
|
||||
"RequireHttpsMetadata": false
|
||||
},
|
||||
"Grpc": {
|
||||
"FlightAddress": "flight:5003",
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "https://localhost:5005",
|
||||
"Audience": "booking-api"
|
||||
"Audience": "booking-api",
|
||||
"RequireHttpsMetadata": true
|
||||
},
|
||||
"RabbitMqOptions": {
|
||||
"HostName": "localhost",
|
||||
|
||||
@ -12,7 +12,6 @@ using BuildingBlocks.MassTransit;
|
||||
using BuildingBlocks.Mongo;
|
||||
using BuildingBlocks.OpenTelemetry;
|
||||
using BuildingBlocks.PersistMessageProcessor;
|
||||
using BuildingBlocks.PersistMessageProcessor.Data;
|
||||
using BuildingBlocks.Swagger;
|
||||
using BuildingBlocks.Web;
|
||||
using Figgle;
|
||||
|
||||
@ -10,6 +10,16 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5003",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
"ConnectionString": "Server=postgres;Port=5432;Database=flight;User Id=postgres;Password=postgres;Include Error Detail=true"
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "http://myidentityserver.com",
|
||||
"Authority": "https://myidentityserver.com",
|
||||
"Audience": "flight-api",
|
||||
"RequireHttpsMetadata": false
|
||||
},
|
||||
|
||||
@ -16,7 +16,6 @@ using BuildingBlocks.Mongo;
|
||||
using BuildingBlocks.OpenTelemetry;
|
||||
using BuildingBlocks.PersistMessageProcessor;
|
||||
using BuildingBlocks.Swagger;
|
||||
using BuildingBlocks.Utils;
|
||||
using BuildingBlocks.Web;
|
||||
using Figgle;
|
||||
using Flight.Data;
|
||||
|
||||
@ -20,7 +20,6 @@ var app = builder.Build();
|
||||
app.MapMinimalEndpoints();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseInfrastructure();
|
||||
|
||||
app.Run();
|
||||
|
||||
@ -1,6 +1,24 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:42478",
|
||||
"sslPort": 44342
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5009",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
|
||||
@ -15,10 +15,6 @@
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "identity:5005",
|
||||
"Audience": "identity-api"
|
||||
},
|
||||
"LogOptions": {
|
||||
"Level": "information",
|
||||
"LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
|
||||
|
||||
@ -12,10 +12,6 @@
|
||||
"Password": "guest",
|
||||
"Port": 5672
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "https://localhost:5005",
|
||||
"Audience": "identity-api"
|
||||
},
|
||||
"LogOptions": {
|
||||
"Level": "information",
|
||||
"LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
|
||||
|
||||
@ -35,10 +35,8 @@ public static class IdentityServerExtensions
|
||||
.AddAspNetIdentity<User>()
|
||||
.AddResourceOwnerValidator<UserValidator>();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
identityServerBuilder.AddDeveloperSigningCredential();
|
||||
}
|
||||
//ref: https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html
|
||||
identityServerBuilder.AddDeveloperSigningCredential();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@ -26,6 +26,9 @@ using Serilog;
|
||||
|
||||
namespace Identity.Extensions.Infrastructure;
|
||||
|
||||
using Duende.IdentityServer.Extensions;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
|
||||
public static class InfrastructureExtensions
|
||||
{
|
||||
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
|
||||
@ -76,6 +79,14 @@ public static class InfrastructureExtensions
|
||||
|
||||
builder.Services.AddIdentityServer(env);
|
||||
|
||||
//ref: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-7.0&viewFallbackFrom=aspnetcore-2.2
|
||||
//ref: https://medium.com/@christopherlenard/identity-server-and-nginx-ingress-controller-in-kubernetes-7146c22a2466
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders =
|
||||
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@ -85,6 +96,10 @@ public static class InfrastructureExtensions
|
||||
var env = app.Environment;
|
||||
var appOptions = app.GetOptions<AppOptions>(nameof(AppOptions));
|
||||
|
||||
//ref: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-7.0&viewFallbackFrom=aspnetcore-2.2
|
||||
//ref: https://medium.com/@christopherlenard/identity-server-and-nginx-ingress-controller-in-kubernetes-7146c22a2466
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
app.UseProblemDetails();
|
||||
app.UseSerilogRequestLogging(options =>
|
||||
{
|
||||
@ -100,6 +115,22 @@ public static class InfrastructureExtensions
|
||||
|
||||
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
||||
|
||||
app.Use((httpContext, next) =>
|
||||
{
|
||||
httpContext.Request.Scheme = "https";
|
||||
return next();
|
||||
});
|
||||
|
||||
app.Use(async (ctx, next) =>
|
||||
{
|
||||
if (ctx.Request.Headers.ContainsKey("from-ingress"))
|
||||
{
|
||||
ctx.SetIdentityServerOrigin("https://myidentityserver.com");
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseCustomSwagger();
|
||||
|
||||
@ -20,7 +20,6 @@ var app = builder.Build();
|
||||
app.MapMinimalEndpoints();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseInfrastructure();
|
||||
|
||||
app.Run();
|
||||
|
||||
@ -9,8 +9,9 @@
|
||||
"ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true"
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "identity:5005",
|
||||
"Audience": "passenger-api"
|
||||
"Authority": "https://myidentityserver.com",
|
||||
"Audience": "passenger-api",
|
||||
"RequireHttpsMetadata": false
|
||||
},
|
||||
"MongoOptions": {
|
||||
"ConnectionString": "mongodb://mongo:27017",
|
||||
|
||||
@ -11,7 +11,8 @@
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "https://localhost:5005",
|
||||
"Audience": "passenger-api"
|
||||
"Audience": "passenger-api",
|
||||
"RequireHttpsMetadata": "true"
|
||||
},
|
||||
"RabbitMqOptions": {
|
||||
"HostName": "localhost",
|
||||
|
||||
@ -12,7 +12,6 @@ using BuildingBlocks.Mongo;
|
||||
using BuildingBlocks.OpenTelemetry;
|
||||
using BuildingBlocks.PersistMessageProcessor;
|
||||
using BuildingBlocks.Swagger;
|
||||
using BuildingBlocks.Utils;
|
||||
using BuildingBlocks.Web;
|
||||
using Figgle;
|
||||
using FluentValidation;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user