如何解决Blazor WebAssembly登录身份验证/来自.well-known / openid-configuration的登录提供了localhost URL而非公共URL
自动生成的oidc配置文件提供localhost而不是我的公共URL。如何设置它以提供正确的URL?
http://167.172.118.170/.well-known/openid-configuration
在我的测试站点的登录链接中:http://167.172.118.170/authentication/login,登录名重定向到本地地址,而不是公共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; }
}
没有提供服务器URL的选项。
解决方法
解决方案是添加以下内容:
使用IdentityServer4.Extensions;
//...
app.Use((ctx,next) =>
{
ctx.SetIdentityServerOrigin("http://167.172.118.170");
return next();
});
,
您的应用程序配置不正确。
您需要使用类似下面的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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。