问题出在使用了HTTP协议而非HTTPS协议,需要将BFF和IdentityServer的配置改为HTTPS协议。可以通过在BFF中使用HTTPS,或者在IdentityServer中配置HTTP跳转至HTTPS来解决。代码示例:
BFF中使用HTTPS:
builder.WebHost.ConfigureKestrel(options => { options.ListenLocalhost(5000, o => o.UseHttps("certificate.pfx", "password")); });
该代码会让Kestrel在5000端口使用HTTPS协议,需要提供证书和密码。
{ "Api": { "BaseUrl": "https://localhost:5000" }, "IdentityServer": { "BaseUrl": "https://localhost:6001" } }
services.AddHttpClient("identity", client =>
{
client.BaseAddress = new Uri(configuration.GetValue
IdentityServer中配置HTTP跳转至HTTPS:
app.Use(async (context, next) => { if (context.Request.IsHttps || context.Request.Headers["X-Forwarded-Proto"] == Uri.UriSchemeHttps) { await next(); } else { var httpsUrl = "https://" + context.Request.Host + context.Request.Path; context.Response.Redirect(httpsUrl); } });
该代码会检查请求是否使用HTTPS协议,如果不是则跳转至HTTPS地址。
{ "Api": { "BaseUrl": "https://localhost:5000" }, "IdentityServer": { "BaseUrl": "http://localhost:6001" } }
注意,这里使用的是HTTP地址。
services.AddHttpClient("identity", client =>
{
client.BaseAddress = new Uri(configuration.GetValue
注意,这里使用的是HTTP地址。
以上是两种解决方案,可以根据项目需求进行选择。