在我的 BlazorWebAssembly + ASP.NET Core Identity 测试站点 (.NET 5.0 RC1) 中,我在尝试登录时收到以下错误。
There was an error trying to log you in: 'Network Error'
我已将 appsettings OIDC 设置为以下内容:
{
"SiteName": "MyProject",
"oidc": {
"Authority": "https://167.172.118.170/",
"ClientId": "MyProject",
"DefaultScopes": [
"openid",
"profile"
],
"PostLogoutRedirectUri": "/",
"RedirectUri": "https://167.172.118.170/authentication/login-callback",
"ResponseType": "code"
}
}
为什么无法连接?
测试站点位于 http://167.172.118.170/代码可以在https://github.com/jonasarcangel/BlazorLoginNetworkErrorIssue中找到
最佳答案
现在很明显,Blazor 使用内部 url http://localhost:5008
作为权限,而不是外部 url http://167.172.118.170/
>
当客户端尝试连接http://localhost:5008/.well-known/openid-configuration
时,出现错误:连接被拒绝...
事实上客户端应该使用这个url:http://167.172.118.170/.well-known/openid-configuration
,但它并没有,因为权限的值是由 Blazor 确定。
如果您在浏览器地址栏中输入网址http://167.172.118.170/.well-known/openid-configuration
,您将看到有关身份提供商的所有配置信息。确实,http://167.172.118.170/
才是权威。但正如您所见,在 appsettings.json 文件中将权限设置为该 url 会被忽略,而会使用内部 url。
如何解决这个问题?我们应该告诉 Blazor 不要使用内部 URL,而应使用外部 URL...
建议的尝试:
在Web服务器项目的Startup类的ConfigureService中更改以下代码:
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationIdentityDbContext>
();
至
services.AddIdentityServer(options =>
{
options.IssuerUri = "https://167.172.118.170/";
})
.AddApiAuthorization<ApplicationUser,
ApplicationIdentityDbContext>();
坚持上述...问题就在这里,而不是其他地方。
祝你好运...
关于asp.net - 带有 ASP.Net Core Identity 登录链接的 Blazor WebAssembly 站点中出现网络错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64201620/