Dan*_*yak 4 c# asp.net-identity identityserver4 asp.net-core-2.0
我正在尝试使用我自己的 SSO 用户存储来让 IdentityServer4 与 ASP.NET Core Identity 一起使用。虽然指南看起来相当简单,并且身份验证过程本身似乎有效,但在应用程序(另一个 ASP.NET Core MVC 应用程序)中,我收到以下错误:
Error loading external login information
我的设置如下:
对于 ASP.NET MVC 应用程序(客户端):
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options =>
{
options.ExpireTimeSpan =TimeSpan.FromMinutes(30);
})
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = "https://localhost:5001/";
options.ClientId = "clientId";
options.ClientSecret = "secret";
options.SaveTokens = true;
options.ResponseType = "code id_token";
options.Scope.Add(IdentityServerConstants.StandardScopes.Profile);
options.Scope.Add(IdentityServerConstants.StandardScopes.Email);
options.Scope.Add(IdentityServerConstants.StandardScopes.OfflineAccess);
options.GetClaimsFromUserInfoEndpoint = true;
});
Run Code Online (Sandbox Code Playgroud)
对于 IdentityServer4 应用程序:
services.AddScoped<UserManager<User>, MyUserManager>();
services.AddIdentity<User, UserGroup>()
.AddRoleStore<MyRoleStore>()
.AddUserStore<MyUserStore>()
.AddDefaultTokenProviders();
services.Configure<IdentityOptions>(options =>
{
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Subject;
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name;
options.ClaimsIdentity.RoleClaimType = JwtClaimTypes.Role;
});
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(OpenIDConfig.GetApiResources())
.AddInMemoryIdentityResources(OpenIDConfig.GetIdentityResources())
.AddInMemoryClients(OpenIDConfig.GetClients())
.AddResourceOwnerValidator<ResourceOwnerPasswordValidator<User>>()
.AddProfileService<ProfileService<User>>();
Run Code Online (Sandbox Code Playgroud)
主要问题是我不知道从哪里开始寻找成功的身份验证流程后出现问题的原因。
因为它确实对我有帮助 - 但我几乎错过了评论中的答案,我将其放在这里。评论是由 @Thomas Levesque 发表的,你可能会感谢他的回答;-)
事实上,问题是我正在更改 Google 选项中的默认 SignInScheme。它必须是 IdentityConstants.ExternalScheme,因为这就是 SignInManager.GetExternalLoginInfoAsync 使用的内容。
| 归档时间: |
|
| 查看次数: |
4496 次 |
| 最近记录: |