Blazor WebAssembly login authentication/login from .well-known/openid-configuration 给出 localhost URL 而不是 public URL

Blazor WebAssembly login authentication/login from .well-known/openid-configuration gives localhost URL instead of public URL

自动生成的 oidc 配置文件给出了 localhost 而不是我的 public URL。我该如何设置它才能提供正确的 URL?

http://167.172.118.170/.well-known/openid-configuration

在我的测试站点的登录 link 中:http://167.172.118.170/authentication/login 登录重定向到本地主机地址而不是 public 167.172.118.170 地址,如下所示:

http://localhost:5008/connect/authorize?client_id=MyProject.Web.Client&redirect_uri=http%3A%2F%2F167.172.118.170%2Fauthentication%2Flogin-callback&response_type=code&scope=MyProject.Web.ServerAPI%20openid%20profile&state=b18bc58127b54ea9aaff1a210b7899de&code_challenge=OOIuUi2yJnYcjZZIu4LveJfbLz0Na7IKkzlDTKb81IE&code_challenge_method=S256&response_mode=query

如何配置它以使其转至 http://167.172.118.170/connect/authorize

这是身份验证剃刀文件的内容:

@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" />

@code{
    [Parameter] public string Action { get; set; }
}

https://github.com/jonasarcangel/BlazorLoginNetworkErrorIssue/blob/master/src/MyProject.Web.Client.Shell/Pages/Authentication.razor

没有提供服务器的选项URL。

您的应用程序配置不正确。

您需要在 Program.cs

中使用类似下面的代码配置您的身份服务器
builder.Services.AddOidcAuthentication(options =>
        {
            builder.Configuration.Bind("OidcConfiguration", options.ProviderOptions);
        });

“OidcConfiguration”来自您的配置文件,将具有如下参数:

"OidcConfiguration": {
    "Authority": "https://YourIdentityServerIP",
    "ClientId": "YourClienId",
    "DefaultScopes": [
      "openid",
      "profile",
      "api"
    ],
    "RedirectUri": "https://yourclientapp/authentication/login-callback",
    "PostLogoutRedirectUri": "https://yourclientapp/authentication/logout-callback",
    "ResponseType": "code"

  }

您可以使用这两个链接查看我如何在宠物项目中配置我的

程序文件: https://github.com/oteebest/edu-client-blazor/blob/master/CBTClient/Program.cs

appsetting.json https://github.com/oteebest/edu-client-blazor/blob/master/CBTClient/wwwroot/appsettings.json

解决方案是添加以下内容:

使用IdentityServer4.Extensions;

//...
app.Use((ctx, next) => 
{
    ctx.SetIdentityServerOrigin("http://167.172.118.170");
    return next();
});