具有ASP.NET Core 2.1 Identity的IdentityServer4-加载外部登录信息时出错

时间:2018-06-22 16:56:29

标签: c# asp.net-identity asp.net-core-2.0 identityserver4

我正在尝试使用我自己的UserStore for 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;
});

对于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>>();

主要问题是,在成功进行身份验证之后,我什至不知道从哪里开始寻找原因。

1 个答案:

答案 0 :(得分:1)

因为它确实对我有帮助-但是我几乎错过了anserw,对此发表评论,我将其放在此处。 @Thomas Levesque发表评论,您可能会感谢他的回答;-)

  

实际上问题是我正在更改默认的SignInScheme   在Google选项中。它必须是IdentityConstants.ExternalScheme,   因为那是SignInManager.GetExternalLoginInfoAsync所使用的。