Align OpenIddict endpoints with configured path base
This commit is contained in:
parent
17279cb6e0
commit
293303c989
@ -13,6 +13,7 @@ using OpenIddict.Validation.AspNetCore;
|
||||
EnvLoader.LoadDotEnvIfDevelopment();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var pathBase = NormalizePathBase(builder.Configuration["PathBase"]);
|
||||
|
||||
builder.Services.AddDbContext<MemberCenterDbContext>(options =>
|
||||
{
|
||||
@ -51,9 +52,12 @@ builder.Services.AddOpenIddict()
|
||||
})
|
||||
.AddServer(options =>
|
||||
{
|
||||
options.SetAuthorizationEndpointUris("/oauth/authorize");
|
||||
options.SetTokenEndpointUris("/oauth/token", "/auth/login", "/auth/refresh");
|
||||
options.SetLogoutEndpointUris("/auth/logout");
|
||||
options.SetAuthorizationEndpointUris(WithPathBase(pathBase, "/oauth/authorize"));
|
||||
options.SetTokenEndpointUris(
|
||||
WithPathBase(pathBase, "/oauth/token"),
|
||||
WithPathBase(pathBase, "/auth/login"),
|
||||
WithPathBase(pathBase, "/auth/refresh"));
|
||||
options.SetLogoutEndpointUris(WithPathBase(pathBase, "/auth/logout"));
|
||||
var issuer = builder.Configuration["Auth:Issuer"];
|
||||
if (!string.IsNullOrWhiteSpace(issuer))
|
||||
{
|
||||
@ -128,13 +132,11 @@ builder.Services.AddHttpClient<SendEngineWebhookPublisher>();
|
||||
builder.Services.AddScoped<ISendEngineWebhookPublisher, SendEngineWebhookPublisher>();
|
||||
|
||||
var app = builder.Build();
|
||||
var pathBase = builder.Configuration["PathBase"];
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
if (!string.IsNullOrWhiteSpace(pathBase))
|
||||
{
|
||||
var normalizedPathBase = pathBase.StartsWith('/') ? pathBase : $"/{pathBase}";
|
||||
app.UsePathBase(normalizedPathBase);
|
||||
app.UsePathBase(pathBase);
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
@ -144,3 +146,22 @@ app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
static string? NormalizePathBase(string? pathBase)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(pathBase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var normalized = pathBase.StartsWith('/') ? pathBase : $"/{pathBase}";
|
||||
return normalized.Length > 1 ? normalized.TrimEnd('/') : normalized;
|
||||
}
|
||||
|
||||
static string WithPathBase(string? pathBase, string relativePath)
|
||||
{
|
||||
var normalizedRelativePath = relativePath.StartsWith('/') ? relativePath : $"/{relativePath}";
|
||||
return string.IsNullOrWhiteSpace(pathBase)
|
||||
? normalizedRelativePath
|
||||
: $"{pathBase}{normalizedRelativePath}";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user