如何解决MVC Core中的IdentityServer登录错误:加载外部登录信息时出错
环境:MVC Core 3.1,VS2019,IdentityServer4
我在VS2019中使用“个人用户帐户”创建了asp.net核心Web应用程序。对其进行了修改,以使用IdentityServer对用户进行身份验证(我们具有IdentityServer4内置的身份验证服务)。通过单击“ OpenIdConnect”按钮登录时,我已正确重定向到IdentityServer,在其中输入了用户名和密码并成功进行了身份验证(我可以从IdentityServer的日志中进行验证)。但是当重定向回我的应用程序时,出现了此错误“加载外部登录信息时出错。”。
IdentityServer应该不是问题,因为我们还有其他使用Web Forms构建的应用程序,并且MVC已成功对其进行身份验证。但这是我们使用IdentityServer的第一个MVC Core项目,所以我不知道是否缺少某些选择。
我已经搜索了所有Internet,但没有找到解决方案。请帮忙。
我在Startup.cs中的代码如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc",options =>
{
options.SignInScheme = "Cookies";
options.Authority = "[my-identityserver-url]";
options.RequireHttpsMetadata = true;
options.ClientId = "[my-client-id]";
options.ClientSecret = "[my-client-secret]";
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.UsePkce = true;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.GetClaimsFromUserInfoEndpoint = true;
options.SaveTokens = true;
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = JwtClaimTypes.Name,RoleClaimType = JwtClaimTypes.Role,};
});
}
IdentityServer上的设置-
登录重定向URI:https:// localhost:44313 / signin-oidc
注销后重定向重定向URI:https:// localhost:44313 /
范围:openid,个人资料
授予类型:混合,client_credentials
CORS起源:https:// localhost:44313 /
https:// localhost:44313 /是Web应用程序的URL。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。