|
|
|
@ -368,10 +368,7 @@ public partial class ProjectNameHttpApiHostModule |
|
|
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
|
|
|
.AddJwtBearer(options => |
|
|
|
{ |
|
|
|
options.Authority = configuration["AuthServer:Authority"]; |
|
|
|
options.Audience = configuration["AuthServer:ApiName"]; |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.MapInboundClaims = Convert.ToBoolean(configuration["AuthServer:MapInboundClaims"]); |
|
|
|
configuration.GetSection("AuthServer").Bind(options); |
|
|
|
}); |
|
|
|
|
|
|
|
if (!isDevelopment) |
|
|
|
@ -384,6 +381,30 @@ public partial class ProjectNameHttpApiHostModule |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureCors(IServiceCollection services, IConfiguration configuration) |
|
|
|
{ |
|
|
|
services.AddCors(options => |
|
|
|
{ |
|
|
|
options.AddPolicy(DefaultCorsPolicyName, builder => |
|
|
|
{ |
|
|
|
builder |
|
|
|
.WithOrigins( |
|
|
|
configuration["App:CorsOrigins"] |
|
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
|
|
|
.Select(o => o.RemovePostFix("/")) |
|
|
|
.ToArray() |
|
|
|
) |
|
|
|
.WithAbpExposedHeaders() |
|
|
|
// 引用 LINGYUN.Abp.AspNetCore.Mvc.Wrapper 包时可替换为 WithAbpWrapExposedHeaders
|
|
|
|
.WithExposedHeaders("_AbpWrapResult", "_AbpDontWrapResult") |
|
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains() |
|
|
|
.AllowAnyHeader() |
|
|
|
.AllowAnyMethod() |
|
|
|
.AllowCredentials(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureWrapper() |
|
|
|
{ |
|
|
|
Configure<AbpWrapperOptions>(options => |
|
|
|
@ -391,22 +412,17 @@ public partial class ProjectNameHttpApiHostModule |
|
|
|
// 取消注释包装结果
|
|
|
|
// options.IsEnabled = true;
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void PreConfigureWrapper() |
|
|
|
{ |
|
|
|
Configure<AbpHttpClientBuilderOptions>(options => |
|
|
|
{ |
|
|
|
// http服务间调用发送不需要包装结果的请求头
|
|
|
|
options.ProxyClientBuildActions.Add( |
|
|
|
(_, builder) => |
|
|
|
options.ProxyClientActions.Add( |
|
|
|
(_, _, client) => |
|
|
|
{ |
|
|
|
builder.ConfigureHttpClient((provider, client) => |
|
|
|
{ |
|
|
|
var wrapperOptions = provider.GetRequiredService<IOptions<AbpWrapperOptions>>(); |
|
|
|
var wrapperHeader = wrapperOptions.Value.IsEnabled |
|
|
|
? AbpHttpWrapConsts.AbpWrapResult |
|
|
|
: AbpHttpWrapConsts.AbpDontWrapResult; |
|
|
|
|
|
|
|
client.DefaultRequestHeaders.TryAddWithoutValidation(wrapperHeader, "true"); |
|
|
|
}); |
|
|
|
client.DefaultRequestHeaders.TryAddWithoutValidation(AbpHttpWrapConsts.AbpDontWrapResult, "true"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -420,28 +436,4 @@ public partial class ProjectNameHttpApiHostModule |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureCors(IServiceCollection services, IConfiguration configuration) |
|
|
|
{ |
|
|
|
services.AddCors(options => |
|
|
|
{ |
|
|
|
options.AddPolicy(DefaultCorsPolicyName, builder => |
|
|
|
{ |
|
|
|
builder |
|
|
|
.WithOrigins( |
|
|
|
configuration["App:CorsOrigins"] |
|
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
|
|
|
.Select(o => o.RemovePostFix("/")) |
|
|
|
.ToArray() |
|
|
|
) |
|
|
|
.WithAbpExposedHeaders() |
|
|
|
// 引用 LINGYUN.Abp.AspNetCore.Mvc.Wrapper 包时可替换为 WithAbpWrapExposedHeaders
|
|
|
|
.WithExposedHeaders("_AbpWrapResult", "_AbpDontWrapResult") |
|
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains() |
|
|
|
.AllowAnyHeader() |
|
|
|
.AllowAnyMethod() |
|
|
|
.AllowCredentials(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|